admin管理员组文章数量:1336645
I need help calling my function, it is not recognizing it and i cannot see why? Any answers to why this is not working...thanks Broken
<script type='text/javascript'>
$('select').change(function() {
alert("hi");
var op =$(this).val();
if(op !='') {
$('input[name="processor_details"]').prop('disabled',false);
} else {
$('input[name="processor_details"]').prop('disabled', true);
}
});
</script>
</head>
<body>
<div>
<strong>Processor:</strong>
<select class="custom-pc" name="processor" id="processor">
<option value=""></option>
<option value="1">1</option>
<option value="1">2</option>
<option value="3">3</option>
</select>
<input name="processor_details" type="button" value="Details" disabled="true" />
</div>
</body>
</html>
I need help calling my function, it is not recognizing it and i cannot see why? Any answers to why this is not working...thanks Broken
<script type='text/javascript'>
$('select').change(function() {
alert("hi");
var op =$(this).val();
if(op !='') {
$('input[name="processor_details"]').prop('disabled',false);
} else {
$('input[name="processor_details"]').prop('disabled', true);
}
});
</script>
</head>
<body>
<div>
<strong>Processor:</strong>
<select class="custom-pc" name="processor" id="processor">
<option value=""></option>
<option value="1">1</option>
<option value="1">2</option>
<option value="3">3</option>
</select>
<input name="processor_details" type="button" value="Details" disabled="true" />
</div>
</body>
</html>
Share
Improve this question
asked Feb 10, 2012 at 14:17
KenKen
291 gold badge1 silver badge4 bronze badges
3 Answers
Reset to default 2You script not see the select
because it's below script itself. You can put your script below select or wrap it with $(document).ready()
http://jsfiddle/cchdW/
It is working on Chrome and Firefox on Mac. Are you sure you are calling JQuery? You did not paste the full HTML code. I think you are missing JQuery. This code will not work without JQuery.
Also, you have to wrap it $(window).load(function(){}
in like this:
<script type='text/javascript'>
$(window).load(function(){
$('select').change(function() {
alert("hi");
var op =$(this).val();
if(op !='') {
$('input[name="processor_details"]').prop('disabled',false);
} else {
$('input[name="processor_details"]').prop('disabled', true);
}
});
});
</script>
You can try this...
<script type='text/javascript'>
function fun()
{
if(document.getElementById("processor").value!="")
document.getElementById("button").disabled=false;
else
document.getElementById("button").disabled=true;
}
</script>
</head>
<body>
<div>
<strong>Processor:</strong>
<select class="custom-pc" name="processor" id="processor" onChange="fun()">
<option value=""></option>
<option value="1">1</option>
<option value="1">2</option>
<option value="3">3</option>
</select>
<input name="processor_details" type="button" value="Details" id="button" disabled="true" />
</div>
</body>
</html>
本文标签: javascriptEnable Button with on change of SelectStack Overflow
版权声明:本文标题:javascript - Enable Button with on change of Select - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742408617a2469333.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论