Jump to content

create checkbox when choice is made from dropdown


kabucek

Recommended Posts

hello @LL,

 

I have some dropdown

 

<select name='selectedProd'>

 

 

 

<option  value='code1'>event 1,IL</option>

 

<option  value='code2'>event 2, IL</option>

 

 

I want to create checkbox visible only if user picks event 1 from dropdown, but checkbox would not show up if event 2 will be selected.

is that possible?

 

thanks

lonewolf, and then use ajax to built the checkbox or use simple js to change the style.display of the element? Either would work, but this isn't the board for JS.

Kabucek, this seems to be a good time to use js, but if you want to go pure html and php, here is what you can do.

They will need to select from the drop down then submit the form. interchange $_GET for $_POST if you are using form method = post

<option  value='code1'>event 1,IL</option>

<option  value='code2' <?php if($_GET['selectedProd'] == "code2"){ echo "selected"; } ?>>event 2, IL</option>
</select>
<?php
if($_GET['selectedProd'] == 'code1'){
echo "Box here <input type='checkbox' name='check' value='1'>";
}
?>

you'll probably need to make several adjustments, but essentially that is what you could do.



<select name"selectedProd" onChange="if (this.selectedIndex == 1){ document.getElementById('chkBoxDisp').innerHTML = '<input type=checkbox>'; }else{ document.getElementById('chkBoxDisp').innerHTML = ''; }" >

 <option value="">...</option>

 <option value="code1">event 1,IL</option>

 <option value="code2">event 2, IL</option>

</select>

<div id="chkBoxDisp" style="width: 100%; height: 15px; background-color: #ffffff;"><!-- CHECKBOX --></div>

 

 

That should do it:P

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.