Get Form Value Through JS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ziycon
    Contributor
    • Sep 2008
    • 384

    Get Form Value Through JS

    I have this code below, how can i get the value from the date input box when i click on the button?
    Code:
    <input type="text" name="date" size="10" onfocus="showCalendarControl(this);" readonly="readonly" />
    <input type="submit" value="Refresh" onclick="getcontent(\'../../map.php?id=1&value=\'+this.value,\'map\');" />
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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.getEle mentById("date" )

    Comment

    • xaxis
      New Member
      • Feb 2009
      • 15

      #3
      If you reference the text field via:
      var someVar = document.getEle mentById("date" );

      To retrieve the value within just append .value:
      var someValue = someVar.value;
      or
      var someValue = document.getEle mentById("date" ).value;

      Comment

      • ziycon
        Contributor
        • Sep 2008
        • 384

        #4
        Nice one, got it sorted, thanks.

        Comment

        Working...