Connecting Tech Pros Worldwide Forums | Help | Site Map

Get Form Value Through JS

Familiar Sight
 
Join Date: Sep 2008
Posts: 255
#1: Feb 11 '09
I have this code below, how can i get the value from the date input box when i click on the button?
Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="date" size="10" onfocus="showCalendarControl(this);" readonly="readonly" />
  2. <input type="submit" value="Refresh" onclick="getcontent(\'../../map.php?id=1&value=\'+this.value,\'map\');" />
  3.  

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Feb 11 '09

re: Get Form Value Through JS


There's a number of ways:
1. using this.form.date
2. using document.forms[formName].elements["date"]
3. setting an id "date" and using document.getElementById("date")
xaxis's Avatar
Newbie
 
Join Date: Feb 2009
Location: California, United States
Posts: 15
#3: Feb 11 '09

re: Get Form Value Through JS


If you reference the text field via:
var someVar = document.getElementById("date");

To retrieve the value within just append .value:
var someValue = someVar.value;
or
var someValue = document.getElementById("date").value;
Familiar Sight
 
Join Date: Sep 2008
Posts: 255
#4: Feb 12 '09

re: Get Form Value Through JS


Nice one, got it sorted, thanks.
Reply