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
Add a ment  | 

3 Answers 3

Reset to default 2

You 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