Results 1 to 3 of 3
  1. #1
    615techguy is offline Member
    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0

    Default PHP dynamic Select in a Java script

    Help please, I am very new to PHP and Java, I have been asked to make a time card page for our employees to enter there times daily. I made a form that uses Java to dynamically generate the required time card questions.. “Job Number, Drawing Number, Work Step, Quantity and Time spent.” At the push of a button. So the employee can add one job or many if needed. I got that part to work. Now the problem I run in to is I need to have a Selection box for “Job Number” and “Work Step” dynamically populated from a PHP query of the data base. So as we add / remove Job Numbers or Work Steps thay show up on the fly so I don’t have to up date the code ever time a change is made.

    Here is my java code. Warning it’s sloppy; it adds two sets of tables with the questions needed. I put <!!!!DYNAMIC SELECT BOX HERE!!!!> where I would like the PHP results to be.

    Java Code:
      function addInput(divName, inputType){
         
              var newdiv = document.createElement('div');
              newdiv.innerHTML = "<table width='632' border='1'><td width='30%'><table width='307' height='129' border='1'><tr><td width='49%'><strong>Job Number:</strong></td><td width='51%'><input type='text' name='JobNumber[]'></td></tr><tr><td><strong>Drowing Number:</strong></td><td><input type='text' name='DrowingNumber[]'></td></tr><tr><td><strong>Work Step:</strong></td><td> <!!!!DYNAMIC SELECT BOX HERE!!!!> </td></tr><tr><td><strong>Quantity:</strong></td><td><input type='text' name='Quantity[]'></td></tr><tr><td height='23'><strong>Time:</strong></td><td><input type='text' name='Time[]'></td></tr></table></td><td width='70%'><table width='308' height='129' border='1'><tr><td width='49%'><strong>Job Number:</strong></td><td width='51%'><input type='text' name='JobNumber[]'></td></tr><tr><td><strong>Drowing Number:</strong></td><td><input type='text' name='DrowingNumber[]'></td></tr><tr><td><strong>Work Step:</strong></td><td><!!!!DYNAMIC SELECT BOX HERE!!!!> </td></tr><tr><td><strong>Quantity:</strong></td><td><input type='text' name='Quantity[]'></td></tr><tr><td height='23'><strong>Time:</strong></td><td><input type='text' name='Time[]'>";
              document.getElementById(divName).appendChild(newdiv);
              counter++;
    Here is my PHP code:

    Java Code:
    mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
    mysql_select_db($dbname) or die(mysql_error());
    
    $query = "SELECT DISTINCT name FROM work_steps where active='1' ORDER BY name";
    $result = mysql_query($query);
    
    <? print "<SELECT class='element select medium' name=Work Step  size=10>";
    while ($line = mysql_fetch_array($result))
    {
    foreach ($line as $value)
    {
    print "<OPTION value='$value'";
    } 
    print ">$value</OPTION>";
    }
    mysql_close($link);
    print "</SELECT>";?>
    Now both by them self work but I need help getting them to work to gather. Or if you know a better way.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    This is not Java, but rather is JavaScript which is a completely different language. You may have some folks who know about this here, but you could be better off looking for a JavaScript site. Best of luck.

  3. #3
    615techguy is offline Member
    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0

Similar Threads

  1. java script
    By satti in forum Web Frameworks
    Replies: 0
    Last Post: 06-09-2009, 09:53 AM
  2. How to retain value in struts 2 using <s:select></s:select> tag
    By SaiPrasad@Sella in forum Web Frameworks
    Replies: 0
    Last Post: 02-09-2009, 08:23 AM
  3. run perl script from java
    By maheshmhs in forum New To Java
    Replies: 0
    Last Post: 12-19-2008, 01:40 PM
  4. Replies: 3
    Last Post: 08-26-2008, 05:43 AM
  5. Displaying a Java List in Html:select tag
    By ramitmehra123 in forum New To Java
    Replies: 0
    Last Post: 02-07-2008, 06:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •