I want to have jQuery show div id='business' only if 'business use' is selected in the dropdown box.
This is my code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$('#purpose').on('change', function() {
if ( this.value == '1');
{
$("#business").show();
}
else
{
$("#business").hide();
}
});
});
</script>
<body>
<select id='purpose'>
<option value="0">Personal use</option>
<option value="1">Business use</option>
<option value="2">Passing on to a client</option>
</select>
<div style='display:none;' id='business'>Business Name<br/>
<br/>
<input type='text' class='text' name='business' value size='20' />
<br/>
</div>
</body>
and the JSFiddle: http://jsfiddle.net/2kGzZ/1/
you have error in your code
unexpected token
.use:Demo
Update: You can narrow down the code using
.toggle()
The core problem is the js errors:
http://jsfiddle.net/Bushwazi/2kGzZ/3/
I had to clean up the html & js...I couldn't help myself.
HTML:
CSS:
JS:
You need to either put your code at the end of the page or wrap it in a document ready call, otherwise you're trying to execute code on elements that don't yet exist. Also, you can reduce your code to:
jsFiddle example
try this which is working for me in my test demo
Wrap the code within
$(document).ready(function(){...........});
handler , also remove the;
afterif
Fiddle Demo