0

I already saw this answer in the forum passing variables using html "anchor" to JavaScript

<a href="#" onclick="size( 'x' ); return false;">HTML Link</a>

but what I want to do is pass the php variable using html tag to the JavaScript, and right now I cannot run it or make the windows pop out using JS.

Below are my codes for PHP and JS:

reference: html to javascript

php file

while($row = mysqli_fetch_array($varRuleId))
{
echo"<tr>";
echo"<td class=tbl_size id=tbl_size_text   colspan='13'>"."<a href='#' onclick='dRaLoader( '$row[resultId]','$srId'); return false;'>". $row['resultId'] ."</a>"."</td>";
echo"<tr>"; 
}

js file

function dRaLoader()
{
    var myWindow = window.open("","myWindow","width=800,height=600");
    myWindow.document.write("<p>This is 'myWindow'</p>");
    myWindow.opener.document.write("<p>This is the source window!</p>");
}

thanks in advance.

10
  • your dRaLoader-function doesnt take any arguments lol Commented Feb 13, 2014 at 13:01
  • you should have parameters in your js function Commented Feb 13, 2014 at 13:02
  • Check your console. Guaranteed you have errors in there ;) Commented Feb 13, 2014 at 13:05
  • yeah right, but i cannot even pop out the window, when you click the link it does nothing, when it should pop out something right? can you check that one? thanks Commented Feb 13, 2014 at 13:05
  • replace this onclick='dRaLoader( '$row[resultId]','$srId'); return false;' with this onclick='dRaLoader(); return false;' Commented Feb 13, 2014 at 13:06

2 Answers 2

0

Try this.

echo '<td class="tbl_size id=tbl_size_text"  colspan="13"><a href="#" onclick="dRaLoader(\''.$row['resultId'].'\',\''.$srId.'\');">'. $row['resultId'] .'</a></td>';


function dRaLoader($resultId, $srcId)
{
    //do something with $resultId and $srcId here
    var myWindow = window.open("","myWindow","width=800,height=600");
    myWindow.document.write("<p>This is 'myWindow'</p>");
    myWindow.opener.document.write("<p>This is the source window!</p>");
}
0

you have to concat the php variables with your string.

while($row = mysqli_fetch_array($varRuleId))
{
echo"<tr>";
echo"<td class=tbl_size id=tbl_size_text   colspan='13'><a href='#' onclick='dRaLoader( \"".$row[resultId]."\",\"".$srId."\"); return false;'>". $row['resultId'] ."</a></td>";
echo"<tr>"; 
}
1
  • And you should use double quotes onclick='dRaLoader( \"".$row[resultId]."\",\"".$srId."\"); return false;' Commented Feb 13, 2014 at 13:12

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.