|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Dynamic listing in php with javascript onChange or onClick
OK firstly Newbie alert!
Next if this is in the wrong forum could you please move to the correct forum. Thank you all for any input on this. Here is the outline, I need to get an outputed string from the chosen radio button to use for a set of if else statement. the code so far is this: Code:
<?php
// Wolfen initial product choice radio button - start
$radio_html = '<table border="0" cellspacing="0" cellpadding="2"><tr>';
$products_choice_query = tep_db_query("select products_choice_id, products_choice_name from " . TABLE_PRODUCTS_CHOICE . " order by products_choice_id");
$checked = true;
while ($products_choice_array = tep_db_fetch_array($products_choice_query)) {
$radio_html .= '<td class="main">';
$radio_html .= tep_draw_radio_field('id[' . $products_choice['products_choice_id'] . ']', $products_choice_array['products_choice_id'], $checked, 'onChange=""');
$checked = false;
$radio_html .= $products_choice_array['products_choice_name'];
$radio_html .= '</td>';
}
$radio_html .= '</tr><a href="attribute_info/products_choice.php" target="blank"><img src="images/i.gif" border="0"></a></table>';
?>
<tr>
<td class="main"><?php echo $products_choice['products_choice_name']; ?></td>
</tr>
<tr></tr>
<td class="main"><?php echo $radio_html; ?></td>
</tr></table>
<?php
// Wolfen initial product choice radio button - end
if ($products_choice['products_choice_id'] = '1') {
which gives three radio buttons pulled from an array created from the table in the database which has three entries. The table consists of products_choice_id and products_choice_name what I want to do is have someone select using the radio buttons and depending on the selection as shown at the end of the code with the Code:
if ($products_choice['products_choice_id'] = '1') {
The if part is there as a representation that the next section of code will be the if else statements. any help you can give on this would be appreciated. Further blurb:: I am looking now at possible use of a javascript function for the onchange, onSelect or onClick To give you a little more details, this code is to be used on the product_info.php I have a situtation where there is a lot of different attributes available. The idea of the radio buttons is to cut down on the attributes that are initially shown by giving an initial set of radio buttons, when a selection is made using the radio buttons, this then shows the specific attributes for that selection as not all attributes will be used for all choices. Example: three radio buttons called 1, 2, 3 radio 1 only requires attributes showing 1 drop menu with a choice of 3 radio 2 requires 3 drop menus with choices from each dop menu and also requires 2 checkboxes and a text input. radio 3 requires 4 drop menus 3 radio buttons 2 check boxes and a text area input. to show the combination of all of these o a user and then get them to make a choice would be to confusing, that is where the initial 3 radio button choice comes into play, therefore the user is only presented with the appropriate attributes for the initial choice rather that all attributes for all choices. |
|
#2
|
||||
|
||||
|
You can't do it with PHP, PHP is a server side language and once run won't respond to user input until the user either changes pages or submits a form.
Your best bet is javascript, but still not sure what exactly is your question besides if it'll work in PHP or not. |
|
#3
|
|||
|
|||
|
Quote:
1. what is required in the onChange part at present I have choose() 2. What javascript is required to make this function. The simplified html derived from the php previously posted. Code:
<table border="0" cellspacing="0" cellpadding="2"> <tr> <td class="main"><form name="cart_quantity" method="post" action=""> <table border="0" cellspacing="0" cellpadding="2"> <tr> <td class="main"> <label><input type="radio" name="choice" value="1" CHECKED onChange="choose()">Car Mascot</label> <label><input type="radio" name="choice" value="2" onChange="choose()">Ornament</label> <label><input type="radio" name="choice" value="3" onChange="choose()">Trophy</label> </td> </tr><a href="attribute_info/products_choice.php" target="blank"><img src="images/i.gif" border="0"></a> </table></form> </td> </tr> </table> if choice 1 Car mascot is selected I need it to show this code on the same page Code:
<table border="0" cellspacing="0" cellpadding="2"> <tr> <td class="main">Car Mascot:</td> <td class="main"><select name="id[2]"><option value="3">Select a finish</option><option value="4">Bronze (+£39.00)</option><option value="5">Chrome plated (+£39.00)</option><option value="6">Enamelled (+£87.00)</option></select><a href="attribute_info/option_2.php" target="blank"><img src="images/i.gif" border="0"></a></td> </tr> </table> if choice 2 Ornament is selected I need it to show this code on the same page Code:
<table border="0" cellspacing="0" cellpadding="2"> <tr> <td class="main">Ornament:</td> <td class="main"><select name="id[1]"><option value="1">Select a finish</option><option value="2">Silver plated (+£45.00)</option></select><a href="attribute_info/option_1.php" target="blank"><img src="images/i.gif" border="0"></a></td> </tr> </table> if choice 3 Trophy is selected I need it to show this code on the same page Code:
<table border="0" cellspacing="0" cellpadding="2"> <tr> <td class="main"><select name="id[3]"><option value="7">Select a finish</option><option value="8">Bronze (+£39.00)</option><option value="9">Chrome plated (+£39.00)</option><option value="10">Enamelled (+£87.00)</option></select><a href="attribute_info/option_3.php" target="blank"><img src="images/i.gif" border="0"></a><select name="id[4]"><option value="11">Select a mount</option><option value="12">Large thick Oak (+£12.00)</option><option value="13">Large Mahogany plinth (+£17.00)</option><option value="14">Rough cut Welsh Slate (+£28.00)</option><option value="15">Welsh Slate 5in x 3in x 1.5in (+£19.00)</option></select><a href="attribute_info/option_4.php" target="blank"><img src="images/i.gif" border="0"></a></td> </tr> <tr> <td class="main"><input type="checkbox" name="id[5]" value="16">(+£14.10) <a href="attribute_info/option_5.php" target="blank"><img src="images/i.gif" border="0"></a><input type="text" name ="id[txt_6]" size="32" maxlength="32" value=""> <a href="attribute_info/option_6.php" target="blank"><img src="images/i.gif" border="0"></a></td> </tr> </table> |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Dynamic listing in php with javascript onChange or onClick |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|