Jono
Jono

Reputation: 18118

JavaScript function can't be identified from an onchange

Hi i get a error below:

05-31 11:17:20.427: D/CordovaLog(20889): Uncaught ReferenceError: hello is not defined

on my html i have embeded the following to pass the toggleswitch element to my javascript function

 <select name="toggleswitch1" id="toggleswitch1" data-theme="" data-role="slider"
            data-mini="true" onchange="hello(document.getElementById('toggleswitch1'))">

here is my javascript

<script>
        function hello(toggle)
        {
        var e = toggle;
        var value = e.options[e.selectedIndex].value;
            if value == "yes"
            {
                //do something
            }

        }
  </script>

what am i missing?

Upvotes: 0

Views: 139

Answers (2)

fnkr
fnkr

Reputation: 10075

Please try this:

<script>
    function hello(toggle)
    {
    var e = toggle;
    var value = e.options[e.selectedIndex].value;
        if(value == "yes")
        {
            //do something
        }

    }
</script>

You forgot the ( and ) on the if:

Diff

Upvotes: 1

Thierry
Thierry

Reputation: 5243

You have an error in your script :

  <script>
    function hello(toggle)
    {
    var e = toggle;
    var value = e.options[e.selectedIndex].value;
        if (value == "yes")
        {
            //do something
        }

    }
 </script>

Upvotes: 3

Related Questions