Jump to content

[SOLVED] Php Variable pass to javascript


elabuwa

Recommended Posts

Ok guys may be a really easy question but i think i mite give u guys a bit of background too.

 

1. I needed a textbox to be filled auto when a user clicks a link in a popup window that opens up when clicked "Add Account" next to the text box.

 

  code used for linkin is :

<span class="style3"><a href="accountselect.php" target="_self" onClick="MM_openBrWindow('accountselect.php','','width=500,height=400'); return false">Add Account</a>  </span>

 

the code in MM_openbrwindow function is

 

function MM_openBrWindow(theURL,winName,features) {

  window.open(theURL,winName,features);

 

}

 

this part works fine.

 

now comes the popup part. Im totally new to javascript and php as well.

so i thought creating links dynamically and when the link is clicked a php variable is passed to a javascript function which will fill the textbox in the parent window.

 

the code for link generation which I believe where the problem is below :

 

  echo "<td> <a href='javascript:post_value($idz);'>SELECT</a></td>";

 

the code for the post_value function is

 

function post_value(a){

opener.document.form1.acnum.value = a;

self.close();

 

}

 

the problem is what ever the value that $idz is having doesnt seem to be passed on the javascript. I think the way im passing the variable value is wrong.

 

what ever the value $idz has, the text box in the parent window gets filled with "-xxx minus 1"

 

for example if

$idz = "1-1000"    : text value in parent is "-999"

$idz = "1-1001"    : text value in parent is "-1000"

 

can you guys please help me out.

thanks a million in advance.

Link to comment
https://forums.phpfreaks.com/topic/175665-solved-php-variable-pass-to-javascript/
Share on other sites

i did some testing and here are the results

 

echo "<td> <a href='javascript:post_value(asd);'>SELECT</a></td>";

 

the text box didnt get filled at all and the popup didnt get closed either.

 

echo "<td> <a href='javascript:post_value(1234);'>SELECT</a></td>";

 

the text box got filled with 1234 which exactly i wants to be filled instead 1234 should be a variable value and popup closed as well.

hey alex,

 

i tried the below ones it still didnt work.

 

echo "<td> <a href='javascript:post_value('$idz');'>SELECT</a></td>";

 

echo "<td> <a href='javascript:post_value(".$idz.");'>SELECT</a></td>";

 

I even tried settype($idz, "string");

 

if you dont mind can u please show me how the above code should be.

 

Thanks again

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.