0

I'm trying to use jquery's datepicker for multiple form fields which I have working when hard coded. I don't know how to do this for a variable number of fields. For example, below I have hard coded it to work for two inputs. I want to do this for any amount of inputs the user provides on a previous page. Thanks for the help!

 <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
      <script src="https://www.cvrc.virginia.edu/otherscripts/jquery-1.9.1.js"></script>
      <script src="https://www.cvrc.virginia.edu/otherscripts/jquery-ui.js"></script>
      <script>
      $(function() {
        $( "#datepicker" ).datepicker();
      });
      $(function() {
        $( "#datepicker2" ).datepicker();
      });
      </script>

      <input type=text name=date size=10 id=datepicker>
      <input type=text name=date size=10 id=datepicker2>

1 Answer 1

1

Use a common class or use the name with an attribute selector

JavaScript

$('[name="date"]').datepicker();

or

$(".datepicker").datepicker();

HTML if you go with the class selector

 <input type="text" name="date" size="10" id="datepicker" class="datepicker">
 <input type="text" name="date" size="10" id="datepicker2" class="datepicker">
Sign up to request clarification or add additional context in comments.

1 Comment

Do they have the same name?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.