3

The code dynamically creates a listview which works but i want to make it so when a listview item is clicked it sends the a url paramater to another method. When i set a paramater it doesnt alert the paramater, but when i give no parameter it works.

var output = 
"<li onclick='openURL()'><h3> Module Code: " + 
results.rows.item(i).module 
+ "</h3>Room: " 
+ results.rows.item(i).room +
"</li>";

The above works - No parameter in openURL();

var output = 
    "<li onclick='openURL('" + results.rows.item(i).url + "')'><h3> Module Code: " + 
    results.rows.item(i).module 
    + "</h3>Room: " 
    + results.rows.item(i).room +
    "</li>";

The above doesnt work - I have done alert(results.rows.item(i).url) and it has a value.

function openURL(url) {
    alert("opening url " + url);
} 

Could someone explain what i'm doing wrong, i've been trying to solve the problem for hours.

Cheers!

2
  • nested apostrophes: "<li onclick='openURL('" .. Commented Oct 26, 2012 at 14:17
  • in second case ur getting null value for url argument? Commented Oct 26, 2012 at 14:17

1 Answer 1

4

You are using single quotes to open the HTML attribute, you can't use it as JavaScript String because you'll be closing the HTML attribute, use double quotes:

var output = 
    "<li onclick='openURL(\"" + results.rows.item(i).url + "\")'><h3> Module Code: " + 
    results.rows.item(i).module 
    + "</h3>Room: " 
    + results.rows.item(i).room +
    "</li>";
Sign up to request clarification or add additional context in comments.

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.