I try to change the dates in javascript.
So to start, in fact I have a mysql query that selects records from the database.
These records have two dates a date called action and another for validation.
In fact the script is supposed to change the dates on criteria but only if the validation date is equal to 0000-00-00 that is that the registration of the database is not considered valid.
So I actually added all the fields are not validated attribute required.
and I tried the code below I struggled to do:
<script type="text/javascript">
function lz(x){
return x.toString().replace(/^(\d)$/,'0$1')
}
function addday() {
var items = new Array();
var itemCount = document.getElementsByClassName("datepicker hasDatepicker");
items[0] = document.getElementById("date" + (1)).value;
items[1] = document.getElementById("date" + (2)).value;
items[2] = document.getElementById("date" + (3)).value;
items[3] = document.getElementById("date" + (4)).value;
items[4] = document.getElementById("date" + (5)).value;
items[5] = document.getElementById("date" + (6)).value;
items[6] = document.getElementById("date" + (7)).value;
items[7] = document.getElementById("date" + (8)).value;
items[8] = document.getElementById("date" + (9)).value;
items[9] = document.getElementById("date" + (10)).value;
for (var i = 0; i < itemCount.length; i++) {
items[i] = document.getElementByAttribute('required').value;
Uncaught TypeError: Object #<HTMLDocument> has no method 'getElementByAttribute'
var itemDtParts = items[i].split("-");
var itemDt = new Date(parseInt(itemDtParts[2],10), parseInt(itemDtParts[1],10)-1, parseInt(itemDtParts[0],10)+ +nb);
nb=document.getElementById('nb').value;
itemCount[i].value = lz(itemDt.getDate())+"-"+lz(itemDt.getMonth()+1)+"-"+itemDt.getFullYear()
}
return items;
}
</script>
but I return the following error:
Uncaught TypeError: Object # Has No method 'getElementByAttribute'
I do not understand why.
the code that generates the javascript is as follows:
<script type="text/javascript">
function lz(x){
return x.toString().replace(/^(\d)$/,'0$1')
}
function addday() {
var items = new Array();
var itemCount = document.getElementsByClassName("datepicker hasDatepicker");
<?php $sql2 = "SELECT * FROM agenda WHERE n_doss='".mysql_real_escape_string($_GET['n_doss'])."' AND qualite='".mysql_real_escape_string($_GET['qualite'])."' AND liasse='".$_GET['liasse']."' AND `date_validation`='0000-00-00' ORDER BY `date_action` ASC" ;
$rules2=mysql_query($sql2) ; $i2=0;
while($data2=mysql_fetch_assoc($rules2)) {?>
items[<?php echo $i2 ; ?>] = document.getElementById("date" + (<?php echo ++$i2 ; ?>)).value;
<?php }?>
for (var i = 0; i < itemCount.length; i++) {
items[i] = document.getElementByAttribute('required').value;
var itemDtParts = items[i].split("-");
var itemDt = new Date(parseInt(itemDtParts[2],10), parseInt(itemDtParts[1],10)-1, parseInt(itemDtParts[0],10)+ +nb);
nb=document.getElementById('nb').value;
itemCount[i].value = lz(itemDt.getDate())+"-"+lz(itemDt.getMonth()+1)+"-"+itemDt.getFullYear()
}
return items;
}
</script>
I use this micro form to execute the function
<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="addday()" />
Receive all my utmost Respect.
Kind regards.
SP.