Discussion:
show input field base on selected option
123gotoandplay
2010-02-17 13:08:44 UTC
Permalink
How do i show a input field only when a certain option is selected?
and hide if it isn't selected



regards
123gotoandplay
2010-02-17 14:05:15 UTC
Permalink
this is what i have now

$('#numOfHours').hide();

$('#type').change(function() {
if($('#type :selected').text() == "parttime") {
$('#numOfHours').show();
} else {
$('#numOfHours').hide();
}
Post by 123gotoandplay
How do i show a input field only when a certain option is selected?
and hide if it isn't selected
regards
123gotoandplay
2010-02-17 14:14:06 UTC
Permalink
solution:

$('#type').change(function() {

if($('#type :selected').val() === "parttime") {
$('#numOfHours').show();
} else {
$('#numOfHours').hide();
}
})
Jonathan Vanherpe (T & T nv)
2010-02-17 14:19:07 UTC
Permalink
maybe something like this?
$(function(){
$('#type').change(function(){
var selected = $(this).children().filter(':selected');
if(selected.val()=='parttime'){
$('#numOfHours').show();
}else{
$('#numOfHours').hide();
}
});
});

This is untested, and can probably be written a lot shorter.

Throw a couple of console.log(); lines in there and I'm sure you'll
figure out what's wrong. If it still doesn't work, post your page online
somewhere.

Jonathan
Post by 123gotoandplay
this is what i have now
$('#numOfHours').hide();
$('#type').change(function() {
if($('#type :selected').text() == "parttime") {
$('#numOfHours').show();
} else {
$('#numOfHours').hide();
}
Post by 123gotoandplay
How do i show a input field only when a certain option is selected?
and hide if it isn't selected
regards
--
Jonathan Vanherpe - Tallieu & Tallieu nv - ***@tnt.be
Continue reading on narkive:
Loading...