Jquery Show A Textbox When An Option Is Selected
I have the following code:
Solution 1:
No need for any css here.
$('#sel').change(function() {
var selected = $(this).val();
if(selected == 'Other'){
$('#other').show();
}
else{
$('#other').hide();
}
});
Solution 2:
<select id="sel">
<optionvalue="Type 1">Type 1</option><optionvalue="Type 2">Type 2</option><optionvalue="Type 3">Type 3</option><optionvalue="Other">Other</option>
</select>
<inputtype="text"id="other"style="display: none;" />
$('#sel').change(function() {
$('#other').css('display', ($(this).val() == 'Other') ? 'block' : 'none');
});
Solution 3:
Try this:
<selectid="selectbox_id"><optionvalue="Type 1">Type 1</option><optionvalue="Type 2">Type 2</option><optionvalue="Type 3">Type 3</option><optionvalue="Other">Other</option></select><inputtype="text"id="other" />
JQuery:
$(function(){
// hide by default
$('other').css('display', 'none');
$('selectbox_id').change(function(){
if ($(this).val() === 'Other') {
$('other').css('display', 'block');
}
});
});
Solution 4:
<select id = "ddlPassport" onchange = "ShowHideDiv()" style="width:150px;">
<option value="Y">Type 1</option>
<option value="Y">Type 2</option>
<option value="N">Type 3</option>
<option value="D">Other</option>
</select>
<script type="text/javascript">
functionShowHideDiv()
{
var ddlPassport = document.getElementById("ddlPassport");
var dvPassport = document.getElementById("dvPassport");
dvPassport.style.display = ddlPassport.value == "Y" ? "block" : "none";
dvPassport1.style.display = ddlPassport.value == "N" ? "block" : "none";
dvPassport2.style.display = ddlPassport.value == "D" ? "block" : "none";
}
<div id="dvPassport" style="display: none">
<form action="viewdata.php" method="POST">
Enter Data:
<input type="text"id="txtPassportNumber" name="data" />
<br>
<input type="submit" value="Search" name="submit"
style="float:right;width:150px;margin-top:10px;">
</form>
</div>
<div id="dvPassport1" style="display: none">
<form action="viewdata.php" method="POST">
Enter Data:
<input type="number"id="txtPassportNumber" name="data" />
<br>
<input type="submit" value="Search" name="submit"
style="float:right;width:150px;margin-top:10px;">
</form>
</div>
<div id="dvPassport2" style="display: none">
<form action="viewdata.php" method="POST">
Enter Data:
<input type="date"id="txtPassportNumber" name="data" />
<br>
<input type="submit" value="Search" name="submit"
style="float:right;width:150px;margin-top:10px;">
</form>
</div>
Post a Comment for "Jquery Show A Textbox When An Option Is Selected"