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?

2 Answers 2

6

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Also, there is no such thing as ‘type="selectbox"’; this should be omitted.
3

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.