I have a trouble with a custom function that I’ve done.
In fact it does not work and I really do not know why.
Here is the function:
<script type="text/javascript">
function lz(x){
return x.toString().replace(/^(\d)$/,'0$1')
}
function dayplus(){
var items = document.getElementsByClassName("datepicker hasDatepicker");
for (var i = 0; i < items.length; i++){
if (items[i].getAttribute('required')){
var itemDtParts = items[i].value.split("-");
var itemDt = new Date(parseInt(itemDtParts[2],10), parseInt(itemDtParts[1],10)-1, parseInt(itemDtParts[0],10)+ +nb);
items[i].value = lz(itemDt.getDate())+"-"+lz(itemDt.getMonth()+1)+"-"+itemDt.getFullYear();
}
}
}
</script>
It says to me:
Uncaught SyntaxError: Unexpected token ILLEGAL addday.html:20
Moreover it says to me that the function is undefined or it is not the case.
Here below is the form I use with the function:
<input type="text" class="datepicker hasDatepicker" required value="26-10-2012">
<input type="button" value="( - )" width="22" height="22" onClick="subday()" />
<input name="jours" type="text" value="" size="5" id="nb" />
<input type="button" value="( + )" width="22" height="22" onClick="dayplus()" />
Modified code: jsfiddle. changes:
nbwas missing, you were using+ +to addnb