0

I just want to pass the base url to a javaScript function. Function call is like as follows

<img src="assets/images/c_arow_rite.jpg" onClick="nextMonth('.$bs_url.')"/>

It showing an error in the Error Console like

Error: SyntaxError: identifier starts immediately after numeric literal
Source File: `http://mywebsite/rand/`
Line: 1, Column: 15
Source Code:
nextMonth(http%3A%2F%2F192.168.1.254%2Frand%2F)
2
  • try to pass the URL within double quotes as a string. Commented Oct 9, 2012 at 15:48
  • Don't pass it at all? location.href, location.host, location.pathname, location.protocol, location.port... there's a lot of info already available to you. If it's not the current url, then 'quote the url' Commented Oct 9, 2012 at 15:49

2 Answers 2

1

This line:

<img src="assets/images/c_arow_rite.jpg" onClick="nextMonth('.$bs_url.')"/>

Should be written as:

<img src="assets/images/c_arow_rite.jpg" onClick="nextMonth(\''.$bs_url.'\')"/>

to add string delimiters that don't muck up the double quotes of the HTML, and are escaped in your php script. I think I'm right in assuming this is actually part of a statement like:

echo '<img src="assets/images/c_arow_rite.jpg" onClick="nextMonth(\''.$bs_url.'\')"/>';

In which case, adding escaped single quotes is the answer.

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

Comments

0

I think you can do just like this:

<img src="assets/images/c_arow_rite.jpg" onClick="nextMonth($bs_url)"/>

2 Comments

only if the php quotes are " or heredoc afaik, not '
@JanusTroelsen, Right now what is the quote?

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.