1

I am using fusion maps in one of my application.

In one of the example i have to pass the value from one map to another charts,

I am facing one problem if the data passed is numeric its displaying alert message correctly but if it is a string it generates an error:

NM is not defined

javascript:alert(NM)()

My code is as below:

$strXML .= "<entity id='" . $rs1['Internal_Id'] . "' value='" . round((($rs1['datap'] /  $sumdata) * 100),2) . "' link='javascript:alert(".($rs1['Internal_Id']) . ")'  />";

If i change the link part (passing single quotes in alert)that is:

$strXML .= "<entity id='" . $rs1['Internal_Id'] . "' value='" . round((($rs1['datap'] /  $sumdata) * 100),2) . "' link='javascript:alert('".($rs1['Internal_Id']) . "')'  />";

It displays invalid xml data.

Please help me on this

Thanks

Pankaj

0

3 Answers 3

1

Use \" rather than ' to surround the JavaScript string.

$strXML .= "<entity id='" . $rs1['Internal_Id'] . "' value='" . round((($rs1['datap'] /  $sumdata) * 100),2) . "' link='javascript:alert(\"".($rs1['Internal_Id']) . "\")'  />";

What is happening is that the xml produced is like so:

<entity id='NM' value='1' link='javascript:alert('NM')'/>

Which as you should be able to see from SOs syntax highlighting ends the value for the link attribute after javascript:alert(' as you are using the same quotes for the javascript as you are using for surrounding the attribute values.

Using a different quote (" rather than ') doesn't end the attribute value (again see the syntax highlighting)

<entity id='NM' value='1' link='javascript:alert("NM")'/>


In PHP we have to escape the quote (Using \) so it isn't interpreted as a special character by the php interpreter and used to end the string, which is why in php you have to write \"

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

Comments

0

You should change your

ink='javascript:alert('".($rs1['Internal_Id']) . "')'

by

ink='javascript:alert(\"".($rs1['Internal_Id']) . "\")'

5 Comments

Hi, Thanks for reply but now it shows this error missing ) after argument list
Seems you $rs1['Internal_Id'] has some non word character like " or , or )
If u don't mind, can you let us know what is your $rs1['Internal_Id'] value
Hi, It has a string value like 'AK', 'UK' Even if i am giving static text value its generating an error.
Pankaj have you seen by reversing the ' with " like 'javascript:alert(\"".($rs1['Internal_Id']) . "\")' by link="javascript:alert('".($rs1['Internal_Id']) . "');\"
0

Try:

$strXML .= "<entity id='" . $rs1['Internal_Id'] . "' value='" . round((($rs1['datap'] /  $sumdata) * 100),2) . "' link='javascript:alert(\"".($rs1['Internal_Id']) . "\")'  />";

Basically escaping your alert quotation marks :)

1 Comment

Hi, Thanks for reply but now it shows this error missing ) after argument list

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.