How do you make a user’s input become the value of a javascript variable?

A user will come in a worth in to a form as well as we wish which worth to turn a worth of a non-static in a javascript snippet. The javascript requires me to hard-code a date similar to (2009-06-01). Instead of me carrying to manually do it, we wish whatever date a user enters in a form (or regulating a GET method) to reinstate (2009-06-01) in a script. Thanks.

One thought on “How do you make a user’s input become the value of a javascript variable?

  1. if you give the input an ‘id’, like so,

    <input type="text" id="inpt" value="1" />

    then in your script, you simply do:

    var someVar = document.getElementById("inpt").value;

    (and the script will be triggered by some event that occurs after the user inputs the data, for you to decide how to do this)

    https://developer.mozilla.org/en/DOM/element#Event_Handlers

    The tricky part for you will be to validate the input to make sure it is in the form you like. It may be easier to use drop down boxes to choose the month, day, and year.

    And of course you don’t have to use getElementById, but any method of retrieving the appropriate node will do.

    https://developer.mozilla.org/en/DOM/document#Methods

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>