0

I keep on getting a syntax error in this HTML/JavaScript code and I can't seem to figure out why.

Any ideas?

<li onClick="document.getElementById(\'attribute83\').selectedIndex ="2", spConfig.configureElement($("attribute83")); class="some-css-class"><a href="http://www.example.com">Something</a></li>'
1
  • Because the original poster is using PHP to output the Javascript. Commented Jan 20, 2012 at 4:21

2 Answers 2

3

Because your onClick handler has a syntax error.

The web browser will take everything between the two quote on your onClick handler

onClick="document.getElementById('attribute83').selectedIndex ="2"

which means

document.getElementById(\'attribute83\').selectedIndex ="2

This isn't valid javascript. If you're using onclick handlers you can have the quotes used to enclose your html attribute (") in your javascript.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

<li onClick="Click()", spConfig.configureElement($("attribute83")); class="some-css-class"><a href="http://www.example.com">Something</a></li>'

<script type="text/javascript">
   function Click()
   {
      document.getElementById('attribute83').selectedIndex = "2";
   }

</script>

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.