shabbaranks Posted October 11, 2011 Share Posted October 11, 2011 Hi, I've been google'ing until Im blue in the face and think I have found a solution as to what I want to do, but I cant get how I achieve it. Would I be correct in thinking to get the selected value from below <select name="Activity"> <?php $sql = "SELECT Status FROM Activity"; $rs = mysql_query($sql) or trigger_error(mysql_error() . " unable to run query."); echo "<option></option>"; while($row = mysql_fetch_assoc($rs)) { echo "<option value=\"".$row['Activity']."\">".$row['Status']."</option>\n "; } ?> </select> The array I need is "Activity"? Do I then use javascript getelementbyid? This being the 'Activity' field how do I then push this to the Activity location in the below table? If Im doing this completely wrong would someone be so kind as to point me in the right direction please? <button onclick='addRow();'>Add to Table</button> <script type='text/javascript'> function addRow(){ //get a reference to the table tbody var myTable = document.getElementById('myTable').getElementsByTagName('TBODY')[0]; //create the table row var tr = document.createElement('TR'); //create the 4 column cells var td1 = document.createElement('TD'); td1.innerHTML = '<input class="name" />'; var td2 = document.createElement('TD'); td2.innerHTML = '<input class="date" />'; var td3 = document.createElement('TD'); td3.innerHTML = '<input class="name" />'; var td4 = document.createElement('TD'); td4.innerHTML = '<input class="hours" />'; var td5 = document.createElement('TD'); td5.innerHTML = '<input class="name" />'; var td6 = document.createElement('TD'); td6.innerHTML = '<input class="name" />'; var td7 = document.createElement('TD'); td7.innerHTML = '<input class="description" />'; //add the column cells to the row tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3); tr.appendChild(td4); tr.appendChild(td5); tr.appendChild(td6); tr.appendChild(td7); //append the row to the table myTable.appendChild(tr); } </script> <table id='myTable'> <thead> <tr> <td>Name</td> <td>Date</td> <td>Project</td> <td>Hours</td> <td>Department</td> <td>Activity</td> <td>Description</td> </tr> </thead> <tbody> </tbody> </table> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/248883-how-do-i-get-a-value-from-one-drop-down-list-into-a-field-in-a-javascript-table/ Share on other sites More sharing options...
WebStyles Posted October 11, 2011 Share Posted October 11, 2011 getElemebtById means you're accessing an element by it's id tag, if you don't have one, it won't work... if you simple add an id tag to your select, so instead if this: <select name="Activity"> you'll have something like this: <select name="Activity" id="myActivityCombo"> then you can easily grab the selected value with something like: var selectedValue = document.getElementById("myActivityCombo").value; hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/248883-how-do-i-get-a-value-from-one-drop-down-list-into-a-field-in-a-javascript-table/#findComment-1278201 Share on other sites More sharing options...
shabbaranks Posted October 11, 2011 Author Share Posted October 11, 2011 Thank you so much Webstyles... I was hoping that I was onto the right track. Once Ive grabbed the selection (an also is it possible to grab more than one selection at a time?) how then do I parse it onto a perticular field? This just isnt sinking in Quote Link to comment https://forums.phpfreaks.com/topic/248883-how-do-i-get-a-value-from-one-drop-down-list-into-a-field-in-a-javascript-table/#findComment-1278232 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.