How to pass the content of input="text" to a Javascript function?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mickey0
    New Member
    • Jan 2008
    • 142

    How to pass the content of input="text" to a Javascript function?

    Hello,
    I must do something like this (it doesn't work and I wonder if 'form' tag is necessary as well):
    Code:
    <head>
     <script language="JavaScript" type="text/javascript">  
        function createCalendar(form) {       
           alert("calendar" + form.date); 
           //here I must use 'date'
           //document.bgColor='yellow'"; //this doens't work
        }
     </script>
    </head>
    
    <form onsubmit="createCalendar(this);">
    Choose a date: <input type="text" size="15" name="date" />  
    <input type="button" value="Submit" id="mybutton2" />
    </form>
    I would like that the js function is called after typing a date and press the button.

    thanks
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    a) the <form> tag is necessary
    b) you access the content of a text field via its value attribute/property.

    Comment

    Working...