Skip to content

Instantly share code, notes, and snippets.

@zulhfreelancer
Created January 21, 2015 19:01
Show Gist options
  • Save zulhfreelancer/7f6226786914174d417e to your computer and use it in GitHub Desktop.
Save zulhfreelancer/7f6226786914174d417e to your computer and use it in GitHub Desktop.
Show an Input Field Based On Selected Dropdown And Change a Hidden Input Value Based on That Showed Input Content (if empty and if not empty) // Demo: http://jsfiddle.net/tfntj5ds/
#ref {
display:none;
}
<select id="drop">
<option>-- Please select --</option>
<option>Agent / Employer</option>
<option id="drop_option">Job Seeker</option>
</select>
<br/>
<input name="referral" type="text" placeholder="Referral" id="ref" />
<br/>
<input name="check" value="false" type="text" />
$('#drop').change(function () {
var selectedId = $('option:selected', this).attr('id');
if (selectedId == "drop_option") {
$('#ref').show("slow", "swing");
$("#ref").blur(function () {
if ($(this).val() === "") {
$('input[name=check]').val('false');
} else {
$('input[name=check]').val('true');
}
});
} else {
$('#ref').hide("slow", "swing");
$('input[name=check]').val('false');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment