Need help with Jquery and javascript
I have bunch of employees, each employee have 7 days for their work schedule. I created the following form using php and w开发者_如何学编程ould like get data from here to JavaScript for verification and then submit it to SQL database using ajax. My problem is how can I dynamically create these forms and then get values from their inputs? Dynamically creating them is the easy part.
<?php
function getNewEmployeeForm($name) {
$def_form = "
<tr name=\"" . $name ."\">
<td>".$name ."</td>
<td>
<input style=\"width:55px\" id='". $name ."' type=\"text\">
</td>
<td>
<input style=\"width:55px\" id='". $name ."' type=\"text\">
</td>
<td>
<input style=\"width:55px\" id='". $name ."' type=\"text\">
</td>
<td>
<input style=\"width:55px\" id='". $name ."' type=\"text\">
</td>
<td>
<input style=\"width:55px\" id='". $name ."' type=\"text\">
</td>
<td>
<input style=\"width:55px\" id='". $name ."' type=\"text\">
</td>
<td>
<input style=\"width:55px\" id='". $name ."' type=\"text\">
</td>
</tr>";
echo $def_form;
}?>
add a 'name' attribute and give it a value for example 'day'
Then try the following javascript (untested)
var employees = new Array();
$('table td input[name="day"]').each(function(i){
employees[i] = $(this).val();
});
精彩评论