PDA

View Full Version : Dynamic Dropdown Results


BWilliams
01-09-2010, 01:04 AM
I have created a Dynamic Dropdown that works perfect, well kinda. The issue I am having is when the "insert" form is submitted (WA Data Assist) it puts the ID #'s into the database instead of the selected values that were populated from the Dynamic Dropdowns. How can I fix this?

Thanks,

Bobby

BWilliams
01-09-2010, 03:17 PM
Here are the (2) values I am having problems with:

<?php echo ((isset($_POST["VehicleModel"]))?$_POST["VehicleModel"]:""); ?>
<?php echo ((isset($_POST["VehicleStyle"]))?$_POST["VehicleStyle"]:""); ?>

I am posting the "selected values" into another table if that makes any difference, which I am assuming does.

Jason Byrnes
01-11-2010, 10:02 AM
create two hidden form fields to capture the labels, then use javascvript to populate the hidden form fields with the labels on change. here is an example:

<form name="form1" method="post" action="">
<label for="select"></label>
<select name="select" id="select" onChange="document.form1.hiddenField.value = document.form1.select[document.form1.select.selectedIndex].text">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
</select>
<input type="hidden" name="hiddenField" id="hiddenField">
<label for="button"></label>
<br>
<input type="submit" name="button" id="button" value="Submit">
<br>
List value = <?php echo((isset($_POST["select"]))?$_POST["select"]:"") ?>
<br>
Hidden Field Value=<?php echo((isset($_POST["hiddenField"]))?$_POST["hiddenField"]:"") ?>
</form>

BWilliams
01-11-2010, 12:49 PM
create two hidden form fields to capture the labels, then use javascvript to populate the hidden form fields with the labels on change. here is an example:

<form name="form1" method="post" action="">
<label for="select"></label>
<select name="select" id="select" onChange="document.form1.hiddenField.value = document.form1.select[document.form1.select.selectedIndex].text">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
</select>
<input type="hidden" name="hiddenField" id="hiddenField">
<label for="button"></label>
<br>
<input type="submit" name="button" id="button" value="Submit">
<br>
List value = <?php echo((isset($_POST["select"]))?$_POST["select"]:"") ?>
<br>
Hidden Field Value=<?php echo((isset($_POST["hiddenField"]))?$_POST["hiddenField"]:"") ?>
</form>
I apologize Jason, but I am a little lost here. I am assuming I should NOT create a new form and just take the code above, minus the form tags, and insert it into my current form on the INSERT page? Am I going in the right direction here? Please, if possible, provide a little more detal. Thanks.

BWilliams
01-11-2010, 01:08 PM
Attached is the code from my insert.php page.

Jason Byrnes
01-11-2010, 01:35 PM
No, my code was merely to demonstrate the javascript code needed.


lets take the VehicleModel select list as an example:

<select name="VehicleModel" size="1" id="VehicleModel" onchange="WA_FilterAndPopulateSubList(rsVehicleStyle_WAJA,MM _findObj('VehicleModel'),MM_findObj('VehicleStyle' ),1,0,false,': ')">


inside the form create another hidden form element named "VehicleModelname"

<input type="hidden" name="VehicleModelname" id="VehicleModelname">


and change the select list tag to:

<select name="VehicleModel" size="1" id="VehicleModel" onchange="WA_FilterAndPopulateSubList(rsVehicleStyle_WAJA,MM _findObj('VehicleModel'),MM_findObj('VehicleStyle' ),1,0,false,': ');document.WADAInsertForm.VehicleModelname.value = document.WADAInsertForm.VehicleModel[document.WADAInsertForm.VehicleModel.selectedIndex].text">

BWilliams
01-11-2010, 01:54 PM
Thanks for the quick reply. I just attempted to do this and did not work. Any other ideas?

Jason Byrnes
01-11-2010, 02:06 PM
please post a link.

BWilliams
01-11-2010, 02:10 PM
www.profleetsales.com/admin/factory_orders/insert.php

Jason Byrnes
01-11-2010, 02:15 PM
The script is updating the hidden form element. have you updated the insert record behavior to use the hidden form element value instead of the select list?

BWilliams
01-11-2010, 02:35 PM
The script is updating the hidden form element. have you updated the insert record behavior to use the hidden form element value instead of the select list?
okay, the Model is now working properly, but the style is not. I copied the same code over and change the VehicleModel to Vehicle Style and that didn't do the trick.

Jason Byrnes
01-11-2010, 02:43 PM
When I view source of your page, the style select list does not have an onchange event:
<select name="VehicleStyle" size="1" id="VehicleStyle">



should be changed to:
<select name="VehicleStyle" size="1" id="VehicleStyle" onChange="document.WADAInsertForm.VehicleStylename.value = document.WADAInsertForm.VehicleStyle[document.WADAInsertForm.VehicleStyle.selectedIndex].text">

BWilliams
01-11-2010, 02:50 PM
When I view source of your page, the style select list does not have an onchange event:
<select name="VehicleStyle" size="1" id="VehicleStyle">



should be changed to:
<select name="VehicleStyle" size="1" id="VehicleStyle" onChange="document.WADAInsertForm.VehicleStylename.value = document.WADAInsertForm.VehicleStyle[document.WADAInsertForm.VehicleStyle.selectedIndex].text">
That did the trick. Thank you VERY much!

Now on to the update page ;-)

Any pointers? :) :)

Jason Byrnes
01-11-2010, 02:55 PM
same thing, make sure you have a hidden form element, and add the onchange code to the select list:

onChange="document.<form name>.<hidden element name>.value = document.<form name>.<select list name>[document.<form name>.<select list name>.selectedIndex].text"


The example above has threee vairabels,
<form name> = the name of the form
<hidden element name> = the name of the hidden form element
<select list name> = the name of the select list