56
rated 0 times
[
63]
[
7]
/ answers: 1 / hits: 20694
/ 11 Years ago, thu, april 11, 2013, 12:00:00
HTML
<table id=table>
<tr>
<td>1999.09-2007.06</td>
<td> Secondary School </td>
</tr>
<tr>
<td>2007.09-2011.06</td>
<td> College </td>
</tr>
<tr>
<td>2011.09-2015.06</td>
<td> University</td>
</tr>
</table>
<form autocomplete=on>
<p/>
<label>Year</label>
<input type=text id=year name=year autofocus/>
<p/>
<label>Month</label>
<input type=text name=month id=month />
<p/>
</form>
<input type=button onClick=method() />
JavaScript
function method(){
var year = document.getElementById(year).value;
var month = document.getElementById(month).value;
var data = new Date(year,month-1,1);
var dataTable = document.getElementById(table);
var cells = dataTable.querySelectorAll(td);
var cells2 = dataTable.querySelectorAll(td+td);
for (var i = 0; i < cells.length; i++){
var mikro = cells[i].firstChild.data.split(-);
var place = cells2[i].firstChild.data;
var firstData = mikro[0].split(.);
var secondData = mikro[1].split(.);
var data1 = new Date(firstData[0],firstData[1]-1,1);
var data2 = new Date(secondData[0],secondData[1]-1,1);
if(data1<=data && data2>=data){
alert(place);
}
}
}
Here i have 2 columns in the table, i want to create script which will help me to find information from it: I have <input type=text id=year name=year autofocus/>
and <input type=text name=month id=month />
where i can enter year & month.After entering year&month i have to get information from the 2nd column according to the dates on the 1st column for example: Input year: 2002, Input month:05 - result must be 'Secondary School' because it between 1999.09-2007.06 . I can't see what is wrong with my script, it always give me false information.
More From » html