PDA

View Full Version : Dropdown box issue


timolein
04-14-2007, 09:27 PM
Hi,

I have a 2 dropdown box with multible selections. First box selection is:

1F15203 FB F15M
1F15213 FB F15ML
1F15302 FB F15E
1F15312 FB F15EL
1A25203 FL F25M EFI
1A25213 FL F25ML EFI
1A25302 FL F25E EFI
1A25312 FL F25EL EFI
1A25413 FL F25 ELPT EFI
1A3G203 FL F30 M GA EFI
1A3G213 FL F30 ML GA EFI
1A3G312 FL F30 EL GA EFI
1A30413 FL F30 ELPT EFI

Second box is where you can choose cables with these models..

But what i want is that when you choose models:

1F15203 FB F15M
1F15213 FB F15ML
1A25203 FL F25M EFI
1A25213 FL F25ML EFI
1A3G203 FL F30 M GA EFI
1A3G213 FL F30 ML GA EFI

second dropdows box should be disabled from those models.. if i choose models:


1F15302 FB F15E
1F15312 FB F15EL
1A25302 FL F25E EFI
1A25312 FL F25EL EFI
1A25413 FL F25 ELPT EFI
1A3G312 FL F30 EL GA EFI
1A30413 FL F30 ELPT EFI

then you can choose anything from cable menu..

I know that some javascript is the answear but i just dont know how to do it.. so, please help me with this issue.

Br,
Tl

code:

<td class="ThRows style2">Model</td>


<?php
$cellvalue = "";
if ((!isset($_GET["add_fd3"])) && (!isset($_POST["add_fd3"]))) {
$itemvalue = "";
} else {
$itemvalue = qsrequest("add_fd3");
}

$cellvalue = "<select name=\"add_fd3\" ><option value=\"\"" . qscheckselected("",$itemvalue,"selected") . ">-- Choose Model --</option><option value=\"1F15203 FB F15M\"" . qscheckselected("1F15203 FB F15M",$itemvalue,"selected") . ">1F15203 FB F15M</option><option value=\"1F15213 FB F15ML\"" . qscheckselected("1F15213 FB F15ML",$itemvalue,"selected") . ">1F15213 FB F15ML</option><option value=\"1F15302 FB F15E\"" . qscheckselected("1F15302 FB F15E",$itemvalue,"selected") . ">1F15302 FB F15E</option><option value=\"1F15312 FB F15EL\"" . qscheckselected("1F15312 FB F15EL",$itemvalue,"selected") . ">1F15312 FB F15EL</option><option value=\"1A25203 FL F25M EFI\"" . qscheckselected("1A25203 FL F25M EFI",$itemvalue,"selected") . ">1A25203 FL F25M EFI</option><option value=\"1A25213 FL F25ML EFI\"" . qscheckselected("1A25213 FL F25ML EFI",$itemvalue,"selected") . ">1A25213 FL F25ML EFI</option><option value=\"1A25302 FL F25E EFI\"" . qscheckselected("1A25302 FL F25E EFI",$itemvalue,"selected") . ">1A25302 FL F25E EFI</option><option value=\"1A25312 FL F25EL EFI\"" . qscheckselected("1A25312 FL F25EL EFI",$itemvalue,"selected") . ">1A25312 FL F25EL EFI</option><option value=\"1A25413 FL F25 ELPT EFI\"" . qscheckselected("1A25413 FL F25 ELPT EFI",$itemvalue,"selected") . ">1A25413 FL F25 ELPT EFI</option><option value=\"1A3G203 FL F30 M GA EFI\"" . qscheckselected("1A3G203 FL F30 M GA EFI",$itemvalue,"selected") . ">1A3G203 FL F30 M GA EFI</option><option value=\"1A3G213 FL F30 ML GA EFI\"" . qscheckselected("1A3G213 FL F30 ML GA EFI",$itemvalue,"selected") . ">1A3G213 FL F30 ML GA EFI</option><option value=\"1A3G312 FL F30 EL GA EFI\"" . qscheckselected("1A3G312 FL F30 EL GA EFI",$itemvalue,"selected") . ">1A3G312 FL F30 EL GA EFI</option><option value=\"1A30413 FL F30 ELPT EFI\"" . qscheckselected("1A30413 FL F30 ELPT EFI",$itemvalue,"selected") . ">1A30413 FL F30 ELPT EFI</option></select>";
if ($cellvalue == "") {
$cellvalue = "&nbsp;";
}
print "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
?>


<td class="ThRows style2">Cable</td>
<?php
$cellvalue = "";
if ((!isset($_GET["add_fd5"])) && (!isset($_POST["add_fd5"]))) {
$itemvalue = "";
} else {
$itemvalue = qsrequest("add_fd5");
}

$cellvalue = "<select name=\"add_fd5\" ><option value=\"\"" . qscheckselected("",$itemvalue,"selected") . ">-- Choose Cable--</option><option value=\"877773A3 3 ft 0,92m\"" . qscheckselected("877773A3 3 ft 0,92m",$itemvalue,"selected") . ">877773A3 3 ft 0,92m</option><option value=\"877773A4 4 ft 1,2m\"" . qscheckselected("877773A4 4 ft 1,2m",$itemvalue,"selected") . ">877773A4 4 ft 1,2m</option></option></select>";
if ($cellvalue == "") {
$cellvalue = "&nbsp;";
}
print "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
?>
</tr>

rafiki
04-14-2007, 09:29 PM
i think javascript or AJAX is the only answer

timolein
04-15-2007, 08:29 AM
really ?

thanks !!

argothian
04-15-2007, 08:01 PM
I'm guessing that was sarcasm so here's a solution:

<script type="text/javascript">
function checkDis(obj) {
if (obj.options[obj.selectedIndex].value.charAt(0) == "s")
document.getElementById("second").disabled = false;
else
document.getElementById("second").disabled = true;
}
</script>

<select id="first" onkeydown="javascript:checkDis(this)">
<option value ="ha">a</option>
<option value ="sb">b</option>
<option value ="sc">c</option>
<option value ="hd">d</option>
</select>
<br /><br />
<select id="second">
<option value ="a">o1</option>
<option value ="b">o2</option>
<option value ="c">o3</option>
<option value ="d">o4</option>
</select>

The first select box calls the check function when it changes. The check functions looks to see if the selected option value starts with a s (for show) and then disables or enables the second select box.

rafiki
04-15-2007, 08:19 PM
sarcasm from who? this isnt a PHP problem, so whats it doing in here? should be in the javascript forum,really ?

thanks !!
if that was sarcastic then you no that it was a javascropt problem and posted it in the php forum?

I know that some javascript is the answear but i just dont know how to do it.. so, please help me with this issue.
hence why i said its the only answer, PHP cant do anything about that

CFMaBiSmAd
04-15-2007, 08:47 PM
A more generic way of doing this, that would not require you to create or edit javascript code that "decodes" which values in one drop down "enables" values in a second drop down, would be to either -

1) Use an onchange event on the first drop down to submit the selection to the .php form processing code, where it would query the database for the allowable options for that selection and populate the second drop down with those options. This method only uses the form (with an event) and PHP on the server.

2) Use AJAX techniques to do the same as #1, but avoid the page refresh that results from the form submission.

Edit: Here is why I suggest a generic method. By separating the data from the code, you can have any data you want and you won't need to modify the code. If you add a product in the future that does not fit the pattern that has been hard coded in, you will need to create some special case code to handle it. By having the data itself contain all the information about the data, all you need to do is add new data and for your application, associate it with the allowable options for the second drop down list.