Connecting Tech Pros Worldwide Help | Site Map

get form value

Jon Paal
Guest
 
Posts: n/a
#1: Aug 16 '06
onClick can't get the search input value , what am I missing ?

....
<input type="text" value="Search" size="10" >
<input type="submit" name="Submit" value="Go" class="form"
onClick= return "alert( document.forms[this.formname].elements['Search'].value );">

....


Randy Webb
Guest
 
Posts: n/a
#2: Aug 16 '06

re: get form value


Jon Paal said the following on 8/16/2006 4:33 PM:
Quote:
onClick can't get the search input value , what am I missing ?
>
....
<input type="text" value="Search" size="10" >
<input type="submit" name="Submit" value="Go" class="form"
onClick= return "alert( document.forms[this.formname].elements['Search'].value );">
onclick="alert(this.form.elements['Search'].value)"

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Evertjan.
Guest
 
Posts: n/a
#3: Aug 16 '06

re: get form value


Randy Webb wrote on 16 aug 2006 in comp.lang.javascript:
Quote:
Jon Paal said the following on 8/16/2006 4:33 PM:
Quote:
>onClick can't get the search input value , what am I missing ?
>>
>....
> <input type="text" value="Search" size="10" >
<inputmust have a name to be used
Quote:
Quote:
> <input type="submit" name="Submit" value="Go" class="form"
>onClick= return "alert(
>document.forms[this.formname].elements['Search'].value );">
1 alert does not return a usable value
2 do not use onclick here, but onsubmit in the <form>
Quote:
>
onclick="alert(this.form.elements['Search'].value)"
>
Try:

<form onsubmit='alert(this.elements["Search"].value);return false'>
<input type='text' name='Search' value='abc' >
<input type='submit' name='Submit' value='Go'>
</form>

the "return false" is only necessary if you do not want to submit ageter
the alert.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Matt Kruse
Guest
 
Posts: n/a
#4: Aug 16 '06

re: get form value


Jon Paal wrote:
Quote:
onClick can't get the search input value , what am I missing ?
<input type="text" value="Search" size="10" >
<input type="submit" name="Submit" value="Go" class="form"
onClick= return "alert(
document.forms[this.formname].elements['Search'].value );">
<input type="submit" name="Submit" value="Go" class="form"
onClick="alert(this.form.Search.value);">

And then be sure to put a name="Search" in your input box, as it currently
lacks a name attribute.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


Closed Thread