Reputation: 39
I have this drop down list and my idea is when i click on videos that i disable other drop down list.This is not working.Do i need something else?
<select name="Type" id="type">
<option value="0">Please Select</option>
<option name="image" value="I" >Images</option>
<option name="video "value="V">Videos</option>
<?php
$value=$_POST['image'];
?>
</select>
<select id="text-one" <?php if($value=="V"){ ?> disabled="disabled"<?php }?> >
<option selected value="base">Please Select</option>
<option value="Dig">Digital</option>
</select
Upvotes: 2
Views: 7749
Reputation: 1531
try this code :
<script>
function disable(val)
{
if(val=="V")
document.getElementById("text-one").disabled=true;
else
document.getElementById("text-one").disabled=false;
}
</script>
<select name="Type" id="type" onchange="disable(this.value)">
<option value="0">Please Select</option>
<option name="image" value="I" >Images</option>
<option name="video "value="V">Videos</option>
</select>
<select id="text-one" >
<option selected value="base">Please Select</option>
<option value="Dig">Digital</option>
</select>
Upvotes: 2
Reputation: 6356
You can do this with PHP, but that's going to require submitting form the data so you can then access $_POST
, and then loading a new page, that's basically the same as the original, just with text-one disabled.
Remember, PHP runs server side, and once it's rendered in the browser, nothing else can be done via PHP. For example, you've got a line in your sample code that show's you tring to assign $_POST['image']
to $value
- until you submit a form, $_POST
will be empty.
Most likely, you want to do this client side and without a reload, and this can be done using javascript.
As a basic overview:
onChange
event handler for your type
select element type
select element, and set the disabled
attribute on the text-one
as neededAnother option (maybe simpler?):
attach an onclick
attribute to the video input, that will run a javascript function that disables text-one
jQuery will make some of this easier, but you could write all of the above in plain javascript, without any libraries.
Upvotes: 2