1

i'm trying to echo the following function add() in HTML

'<a onclick="add('.$row["x"].','.$row["y"].')" href="javascript:void(0)">'

The function is not getting invoked. How should i implement it correctly?

3 Answers 3

1

This

echo '<a onclick="add('.$row["x"].','.$row["y"].')" href="javascript:void(0)">';

will gives you

<a onclick="add(a,b)" href="javascript:void(0)">

You need to add single quotes if you are passing strings to your function, like this

echo '<a onclick="add(\''.$row["x"].'\',\''.$row["y"].'\')" href="javascript:void(0)">';

Then in your document you will get

<a onclick="add('a','b')" href="javascript:void(0)">
Sign up to request clarification or add additional context in comments.

Comments

1

Try this

'<a href="javascript:add('.$row["x"].','.$row["y"].')">'

OR

'<a onclick="add('.$row["x"].','.$row["y"].')" href="#">'

Or

'<a onclick="add('.$row["x"].','.$row["y"].') return false" href="#">'

Comments

1

Try to something like this.

Php File

<?php
     echo '<a onclick="add('.$row["x"].','.$row["y"].')" >Onclick Function</a>';
 ?>

.html file

<a onclick="add(<?= $row["x"] ?>,<?= $row["y"] ?>)" href="javascript:void(0)">Onclick Function</a>

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.