views:

846

answers:

2
<script>
    function options(){
       alert("asdfasdf");
    }
</script>
<select type="selectbox" name="crPaymentOption" id ="crPaymentOption"onchange="options()"/>
    <option selected="" value="--">--</option>
    <option value="Check">Check</option>
    <option value="Credit Card">Credit Card</option>
    <option value="Cash">Cash</option>
</select>

The alert is not firing when i change the options of the select drop down. Can anyone help me on this??

+6  A: 

Change your method name, and leave a space before the onchange attribute :

<script>
    function optionsAlert(){
       alert("asdfasdf");
    }
</script>
<select name="crPaymentOption" id="crPaymentOption" onchange="optionsAlert()"/>
    <option selected="" value="--">--</option>
    <option value="Check">Check</option>
    <option value="Credit Card">Credit Card</option>
    <option value="Cash">Cash</option>
</select>
Canavar
Also, there is no such thing as ‘type="selectbox"’; this should be omitted.
bobince
Yes, I didn't notice that, updated the answer.
Canavar
+3  A: 

It doesn't like the function name - change it to a different name, e.g. changeOptions, and use that. Here's a version of your code that works for me:

<html>
<body>

    <script>    function changeOptions(){       alert("asdfasdf");    }</script>

    <select type="selectbox" name="crPaymentOption" id="crPaymentOption" onchange="changeOptions()" />
    <option selected="" value="--">--</option>
    <option value="Check">Check</option>
    <option value="Credit Card">Credit Card</option>
    <option value="Cash">Cash</option>
    </select>
</body>
</html>
Pete OHanlon