[SOLVED] Updating multiple selected records based on a combobox v |
4/1/2010 3:31:24 PM |
PHPRunner General questions | |
F
FunkDaddy author
I've looked through the posts (and online manual) and found lots of good help on updating multiple records, however, I still have not been able to figure out how to do the following: |
|
J
|
Jane 4/2/2010 |
Marcelo, <INPUT class=button onclick="var form = $('#frmAdmin1')[0]; form.a.value=document.getElementById("dropdown1").value; form.submit(); return false;" value="Update selected" type=button> |
F
|
FunkDaddy author 4/2/2010 |
Jane,
global $dal;
<INPUT class=button onclick="var form = $('#frmAdmin1')[0]; form.a.value=document.getElementById("dropdown1").value; form.submit(); return false;" value="Update selected" type=button> it will turn the $_Post["a"] value into whatever I selected in my combobox. The problem is I can't predict what that value will be since the user can choose from a variety of values. $sql = "Update employees set ReportsTo='Bob Smith' where " . $where; offers a hard coded value for the SQL SET action (which in this case is ReportsTo = 'Bob Smith'. //create dropdown box
|
F
|
FunkDaddy author 4/5/2010 |
Just an update on this topic and issue.. the code Jane provided was great, but it took me a while to figure out the part where it says form.a.value=document.getElementById('dropdown1').value should be written with single quotes and not double quotations. Additionally, if you want to use the actual selected value of the index box (dropdown1) it should read form.a.value=document.getElementById('dropdown1').selectedIndex Otherwise, the form will $_POST a value of the entire dropdownbox1 HTML stirng... causing major errors. Just an update to help others out there! :-) <INPUT class=button onclick="var form = $('#frmAdmin1')[0]; form.a.value=document.getElementById('dropdown1').selectedIndex; form.submit(); return false;" value="Update selected" type=button>
|
F
|
FunkDaddy author 4/6/2010 |
OK. Going a little nuts NOW! |
D
|
Dale 4/6/2010 |
Add the .value to your selected index. |
F
|
FunkDaddy author 4/6/2010 |
Thanks DAleM... |
D
|
Dale 4/6/2010 |
Try this one, sorry but I havent tested it. Ive done something like this in a different project. |
F
|
FunkDaddy author 4/6/2010 |
The code you just gave me got me closer than ever before... the problem is that I need the actual key value being stored and not the text displayed. For example, I have a dropdown as a follows (which is dynamically generated using the code found here: http://xlinesoft.com/phprunner/docs/add_dropdown_list_box_with_values_for_search.htm |
D
|
Dale 4/6/2010 |
how about this one. Sorry for all the wacking but as I said I havent got a test bed to proof it. |
F
|
FunkDaddy author 4/6/2010 |
My bad... I should have mentioned in my last post that was exactly what I tried after I first tested what you suggested. When I do that it does return the value, the problem is that value is unusable since it returns this: |
F
|
FunkDaddy author 4/6/2010 |
OK. I finally figured out how to do this: if(@$_POST["a"]=="update")
if(@$_POST["a"]!="delete")
$sql = "Update employees set ReportsTo='Bob Smith' where " . $where; with this $sql = "Update employees set ReportsTo=" . @$_POST["a"] . " where " . $where;
//create dropdown box
<INPUT class=button onclick="var form = $('#frmAdmin1')[0]; form.a.value=document.getElementById("dropdown1").value; form.submit(); return false;" value="Update selected" type=button>
|