I was wondering if there is a way similar to the code below in order to use ‘conditional’ select boxes. I tried a few jquery methods, but I really got stuck since I use wordpress, and this should be a search box so it complicates things for me.
<form name="main" method="post">
<select name="currency-select">
<option value="default">Currency</option>
<option value="a">U.S Dollars (USD)</option>
<option value="b">Euros (EUR)</option>
<option value="c">British Pounds (GBP)</option>
</select>
</form>
<form name="child">
<select name="currency-child">
<?php if($_POST['currency-select'] == "a"): >
<option value="1">price</option>
<option value="2">100</option>
<option value="3">200</option>
<option value="4">300</option>
<?php endif; ?>
<?php if($_POST['currency-select'] == "b"): >
<option value="5">price</option>
<option value="6">50</option>
<option value="7">60</option>
<option value="8">70</option>
<?php endif; ?>
<?php if($_POST['currency-select'] == "c"): >
<option value="9">price</option>
<option value="10">130</option>
<option value="11">260</option>
<option value="12">390</option>
<?php endif; ?>
</select>
</form>
Update : syntax errors fixed
As long as the form is not submited, PHP don’t do any thing about your form, and you don’t have a submit button in your html so the values won’t be set in your PHP script.
I suggest you
jQuery
.I wrote the code below for you, but you have to set the new attributes for your html elements and append a
<div>
withid="wrapper"
–><div id="wrapper">
If you didn’t append
wrapper
, change$('#wrapper').on('change', 'form#main', function() {
with$(document).on('change', 'form#main', function() {
.but in larg codes, I suggest
#wrapper
instead ofdocument
.CODE:
Add this lines in the
<head>
of page:Body-html elements-