views:

56

answers:

3

I have a code that is a mmix of html and js. I cannot get it correct.

location.description + '<br><a href="javascript:void(0);" onclick="showStreet;">ShowStreet </a><br>'+ location.lat + '<br> + location.lng

Can anyone help me with it?

A: 
location.description + '<br><a href="javascript:void(0);" onclick="showStreet();">ShowStreet </a><br>'+ location.lat + '<br>' + location.lng

You have to call a function inside onclick and there you were missing parenthesis. And also a single quote after the last <br>

rahul
@rahul: That won't work...you are missing the single quote.
Sarfraz
@Sarfraz: The thing he actually corrected, he corrected just fine (the call *was* missing the parens). If the OP *also* wants the onclick to be cancellable, then yes, he'd also need to add a `return`. @rahul: Does Google know you're using their intellectual property? (http://www.google.co.uk/permissions/guidelines.html) ;-)
T.J. Crowder
Any reason for that??
rahul
@T.J. Crowder: You are right but I did not down vote. Rahul knows I do not down vote, for this reason i suggested him to correct his answer :)
Sarfraz
@Sarfraz: I didn't say you downvoted. And your original unedited comment *didn't* tell him about the other problem, it just said "That won't work." full stop.
T.J. Crowder
+4  A: 

You have two problems in that:

  • You were missing ' after location.lat + '<br>
  • You were not suffixing the function showStreet with ()

Try this:

location.description + '<br><a href="javascript:void(0);" onclick="showStreet();">ShowStreet </a><br>'+ location.lat + '<br>' + location.lng

Note: You might want to add the return keyword for your function depending on whether you want to cancel it at some point.

Sarfraz
+1 Probably also worth mentioning the `return` thing if he wants to cancel.
T.J. Crowder
@T.J. Crowder: Thanks in the first place, the OP knows the best whether he needs the return keyword or not, however i have mentioned that.
Sarfraz
would not the `href="jaascript:void(0)"` result in the link not being followed any way?
thecoshman
@thecoshman: There is no link to be followed in that, as can be seen the OP has to run a function on clicking that link.
Sarfraz
+1  A: 

Did you mean onclick="showStreet()" (instead of onclick="showStreet;")? From your question, it's unclear what the problem is.

atzz