473,288 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

how can I fetch dynamic rows (drop down's database values) using ajax?

My javaScript.
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2. var i=0;
  3. function addRow(table1)
  4. {
  5. i++;
  6. frm.reza.value=i;
  7.  
  8. var tbl = document.getElementById('table1');
  9. var lastRow = tbl.rows.length;
  10. var iteration = lastRow -1;
  11. var row = tbl.insertRow(lastRow);
  12.  
  13. var firstCell = row.insertCell(0);
  14. var el = document.createElement('input');
  15. el.type = 'text';
  16. el.name = 'title' + i;
  17. el.id = 'title' + i;
  18. el.size = 20;
  19. el.maxlength = 20;
  20. firstCell.appendChild(el);
  21.  
  22. var secondCell = row.insertCell(1);
  23. var el2 = document.createElement('input');
  24. el2.type = 'time';
  25. el2.name = 'start_time' + i;
  26. el2.id = 'start_time' + i;
  27. el2.size = 20;
  28. el2.maxlength = 20;
  29. secondCell.appendChild(el2);
  30.  
  31. var thirdCell = row.insertCell(2);
  32. var el3 = document.createElement('input');
  33. el3.type = 'time';
  34. el3.name = 'end_time' + i;
  35. el3.id = 'end_time' + i;
  36. el3.size = 20;
  37. el3.maxlength = 20;
  38. thirdCell.appendChild(el3);
  39.  
  40. var forthCell = row.insertCell(3);
  41. var el4 = document.createElement("select");
  42. el4.name ='program_name'+i;
  43. el4.id = 'program_name' + i;
  44. var option = document.createElement("option");
  45. option.value='';
  46. option.innerHTML='';
  47. el4.appendChild(option);
  48. forthCell.appendChild(el4);
  49.  
  50. var fifthCell = row.insertCell(4);
  51. var el5 = document.createElement("select");
  52. el5.name ='peak_offpeak'+i;
  53. var option1 = document.createElement("option");
  54. option1.value='';
  55. option1.innerHTML='';
  56. el5.appendChild(option1);
  57.  
  58. var option2 = document.createElement("option");
  59. option1.value='peak';
  60. option1.innerHTML='peak';
  61. el5.appendChild(option1);
  62.  
  63. var option3 = document.createElement("option");
  64. option2.value='off_peak';
  65. option2.innerHTML='off_peak';              
  66. el5.appendChild(option2);
  67. fifthCell.appendChild(el5);
  68.  
  69. var sixthCell = row.insertCell(5);
  70. var el6 = document.createElement("select");
  71. el6.name ='sub_brand_name'+i;
  72. el6.id = 'sub_brand_name' + i;
  73. var option = document.createElement("option");
  74. option.value='';
  75. option.innerHTML='txt';
  76. el6.appendChild(option);
  77. sixthCell.appendChild(el6);
  78.  
  79.  
  80.  
  81. var seventhCell = row.insertCell(6);
  82. var el7 = document.createElement('input');
  83. el7.type = 'text';
  84. el7.name = 'sponsor' + i;
  85. el7.id = 'sponsor' + i;
  86. el7.size = 20;
  87. el7.maxlength = 20;
  88. seventhCell.appendChild(el7);    
  89.  
  90. var eighthCell = row.insertCell(7);
  91. var el8 = document.createElement("select");
  92. el8.name ='product_name'+i;
  93. el8.id = 'product_name' + i;
  94. var option = document.createElement("option");
  95. option.value='';
  96. option.innerHTML='+i+';
  97. el8.appendChild(option);
  98. eighthCell.appendChild(el8);
  99.  
  100. }
  101. </script>
  102.  
  103.  
My HTML and PHP code.
Expand|Select|Wrap|Line Numbers
  1.  
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <title>Untitled Document</title></head>
  5.  
  6. <body>
  7. <header><ul><tr><li><a href="https://bytes.com/submit/mediasourcebd_reza/home.php">Home</a></li></tr></ul></header>
  8. <form action="action_entry_history.php" method="post" name="frm" id="frm">
  9. <table width="100%" border="0"  id="table1" class="table">
  10. <tr align="justify">
  11. <td><strong>Title</strong></td>
  12. <td><strong>Start Time</strong> </td>
  13. <td><strong>End Time</strong> </td>
  14. <td><strong>Program</strong> </td>
  15. <td><strong>Peak Off-Peak</strong> </td>
  16. <td><strong>Sub-Brand</strong> </td>
  17. <td><strong>Sponsor</strong> </td>
  18. <td><strong>Product</strong> </td>
  19. </tr>
  20. <tr>
  21. <td><input name="title" type="text" id="title" size="20" maxlength="20" /></td>
  22. <td><input name="start_time" type="time" id="start_time" size="20" maxlength="20" /></td>
  23. <td><input name="end_time" type="time" id="end_time" size="20" maxlength="20" /></td>
  24. <td><?php 
  25.                         $sql ="SELECT program_name FROM program";
  26.                         $result = mysql_query($sql);
  27.                         echo "<select name='program_name' id='ss' class='s' >";
  28.                         while ($row = mysql_fetch_array($result)) {
  29.                         echo "<option value='" .$row['program_name'] ."'>" .$row['program_name'] ."</option>";
  30.                         }
  31.                         echo "</select>";        
  32.                         ?></td>
  33. <td><select name="peak_offpeak"><option value="peak">peak</option><option value="off_peak">off_peak</option></select></td>
  34. <td><?php 
  35.                         $sql = "SELECT sub_brand_name FROM sub_brand";
  36.                         $result = mysql_query($sql);
  37.                         echo "<select name='sub_brand_name' >";
  38.                         while ($row = mysql_fetch_array($result)) {
  39.                         echo "<option value='" . $row['sub_brand_name'] ."'>".$row['sub_brand_name']."</option>";
  40.                         }
  41.                         echo "</select>";        
  42.                         ?></td>
  43.  
  44. <td><input name="sponsor" type="text" id="sponsor" size="20" maxlength="20" /></td>
  45. <td><?php 
  46.                         $sql = "SELECT product_name FROM product";
  47.                         $result = mysql_query($sql);
  48.                         echo "<select name='product_name' >";
  49.                         while ($row = mysql_fetch_array($result)) {
  50.                         echo "<option value='".$row['product_name'] ."'>".$row['product_name']."</option>";
  51.                         }
  52.                         echo "</select>";        
  53.                         ?></td>
  54.  
  55. </tr>
  56.  
  57. </table>
  58. <input type="button" value="Add Rows" onclick="addRow();" />
  59. <input name="Save" type="submit" value="Save Rows" />
  60. <input type="hidden" name="reza" id="reza" value="0" />
  61. </form>
  62.  
May 17 '16 #1
0 1913

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: George G. | last post by:
Hi there, I hope I am posting to the correct news group. What would be a good way to deal with null database values using ADO.NET. My SQL queries sometimes return null values when I have left...
5
by: Nivetha | last post by:
I have requirement list of records are there in that each and every record i need to keep refresh button by clicking that each button ....it should take tha latest value from the database that too...
2
by: pralhadkulkarni12 | last post by:
Hi, I am a new user of AJAX. I need to generate suggest list for every input given by user as we get in Google. To generate I need AJAX code which will read data following XML file. e.g....
2
by: elangobala | last post by:
HI I have a problem in the page. In my page i m having two text boxes and two drop down list box.when i select a value in first drop down it gets a appropriate value for it in the second...
8
by: Bhuwan Bhaskar | last post by:
Hi, Can we access database (SQL) using AJAX ? Thanks, Bhuwan
4
by: ghjk | last post by:
I want to edit database values using my web application. So first i load data to test boxex and drop down list. But drop down list only contain one value. I want to put all posible value to that and...
1
by: galdunne | last post by:
Hi, Im new to ajax and im using prototype for a project i am working on. I am hoping to call a servlet written in java which holds a hashtable to strings. When i click on a link it opens up a tab...
1
by: mfaisalwarraich | last post by:
I am trying to get values posted by a form using ajax but i dont know how to get them. im opening a form which is also based on the ajax. here is the code. function showPage(page) { var...
3
by: sree23 | last post by:
i am fetching records from mysql database am using while loop for displaying in side while loop am using radio button for each record am using ajax for posting each radio button value but it is not...
2
by: helalreza | last post by:
i have some dynamic rows, when i submit a single row submit into my database. how can i insert my dynamic all rows into database by submit? entry_history.php (page)
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.