I am currently working on implementing a feature that involves changing the CSS property visibility:
of an <input>
element using a JavaScript function triggered by user selection in a <select>
dropdown.
Here's what I have so far in my code:
main.js:
function adjustVisibility(){
if( $('#billing_method').val() == "CLICK THIS TO CHANGE VISIBILITY" ){
$('#the_input').css({ 'visibility': 'visible' });
}else{
$('#the_input').css({ 'visibility': 'hidden' });
}
}
page.html:
<select name="billing_method">
<option onClick='adjustVisibility()'>-- SELECT AN OPTION --></option>
<option onClick='adjustVisibility()'>CLICK THIS TO CHANGE VISIBILITY</option>
</select>
<input type="text" id="the_input" value="" placeholder="I AM THE INPUT" />
styles.css:
#the_input{
visibility: hidden;
}
Check out the demo at jsfiddle