View Full Version : validating - Duplicate ID datepicker

12-14-2010, 04:46 PM

I am going through my code validating, see here: http://validator.w3.org/check?uri=http%3A%2F%2Fwww.mypubspace.com%2Fregister.php&charset=%28detect+automatically%29&doctype=Inline&group=0&user-agent=W3C_Validator%2F1.1

I have 1 error left to fix, I have a dupicate ID="datepicker"
I need this in here as it runs from a JavaScript, is there anyway I can get this validated?

here is my code with the relevant JavaScript

<script type="text/javascript">
$( "#datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1920:1994'

<span id="sprytextfield6">
<input name="rsAge" type="text" class="textbox" id="datepicker" />
<span class="textfieldRequiredMsg">A value is required.</span></span>
<!-- Datepicker -->
<span id="datepicker"></span>

12-14-2010, 04:50 PM
You need the id in for the datepicker, yes, but you don't want it on two different elements. It would be normal to have it on the input, assuming this is UI Datepicker. Are you using the id on the span as well - or can that be removed?

12-14-2010, 05:15 PM

the <span id="datepicker"></span> part is the bit that shows the JQuery UI DatePicker when you focus on the input field, so no, it can't be removed.

Any other ideas? thanks anyway SB65

12-14-2010, 05:38 PM
The datepicker will run on the focus event of the the element #datepicker. You have this on your input tag - you shouldn't need it on a span as well. If you really really need the span, for some other reason, make the id a class instead.