-1

I have bunch of employees, each employee have 7 days for their work schedule. I created the following form using php and would 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;
}?>
10
  • 4
    That's not valid html. Two elements cannot have the same id. Commented Jun 4, 2011 at 1:41
  • I tried, var arr = $(":input#name"); didn't work. Commented Jun 4, 2011 at 1:41
  • how can name or id them so i can get all the inputs, given a user name. Commented Jun 4, 2011 at 1:42
  • I believe you wanted to use class attribute rather than id Commented Jun 4, 2011 at 1:43
  • 4
    I think, before trying anything, you should first think about what you wnat. Your question contains about 8 questions, and you seem to miss some basic information. Break up your problem. You don't need any javascript or jquery to post a form. Try to save fixed/hardcoded data first. If that works, create a simple dynamic HTML form and try to process the posted. Only after everything works you start enhancing it using javascript/jquery to improve usability. Commented Jun 4, 2011 at 1:45

1 Answer 1

1

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();
});
Sign up to request clarification or add additional context in comments.

1 Comment

the table thing didn't work but this did, (':input.Name'). Thank you all for your help and comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.