-1

I need to fix this javascript error I am having "missing name after . operator on variable". This is my current code I am trying to get working.

    <!DOCTYPE html>
<html>
<body onload="myFunction()">

<select>
    <option>1</option>
</select>
<br/>
<select>
    <option>1</option>
</select>

<script>
function myFunction()
{
    if(typeof document.body.ontouchstart == "undefined"){actionIn = "onmouseover"; actionOut = "onmouseout"}
    else{actionIn = "ontouchstart"; actionOut = "ontouchend";}

    var elem = document.getElementsByTagName("SELECT");
    for (var i = 0;i < elem.length; i++){
        elem[i].[actionIn] = function(){this.style.background='red';}
        elem[i].[actionOut] = function(){this.style.background='';}
    }
}
</script>

</body>
</html>
3
  • Ermmmmm what is this elem[i].[actionIn] Commented Apr 23, 2013 at 14:53
  • 2
    I already answered this in a comment on your previous question. Commented Apr 23, 2013 at 14:53
  • 1
    Uncaught ReferenceError: myFunction is not defined Commented Apr 23, 2013 at 14:59

2 Answers 2

2

Use either dot or bracket notation, not both:

elem[i][actionIn] = function(){this.style.background='red';}
elem[i][actionOut] = function(){this.style.background='';}
Sign up to request clarification or add additional context in comments.

Comments

1

You do not need a . between the two square bracket pairs.

elem[i][actionIn] and elem[i][actionOut]

should suffice.

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.