Reply to Re: Text in textfield

Your name:

Reply:


Posted by Toby Inkster on 11/15/06 10:12

Toby Inkster wrote:
> Willy wrote:
>
>> <input name=userInput type=text value="something">
>> Could value'something' ibe put in a variable via avascript?
>
> <form name=theForm>
> <input name=userInput type=text value="">
> </form>
> <script type="text/javascript">
> var myInput = document.forms["theForm"].elements["userInput"];
> myInput.value = "something";
> </script>

Sorry -- I think I misread your question. My example above uses Javascript
to put something into a form field. It seems you want to read it *out*.

Here you have two options, depending on what you want to read. Say you
have '<input value="something">' but the visitor then types into the form
field 'something else'. Do you want to retrieve the original value
'something', or the new value 'something else'?

If you want to retrieve 'something else' (which most people would probably
want), then:

<form name=theForm>
<input name=userInput type=text value="something">
</form>
<script type="text/javascript">
var myInput = document.forms["theForm"].elements["userInput"];
var WhatIWant = myInput.value;
// now the variable 'WhatIWant' has what you want.
</script>

If you want to retrieve the original value ('something') then you need
'myInput.defaultValue' instead of 'myInput.value'.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация