elabuwa Posted September 27, 2009 Share Posted September 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/175665-solved-php-variable-pass-to-javascript/ Share on other sites More sharing options...
elabuwa Posted September 27, 2009 Author Share Posted September 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/175665-solved-php-variable-pass-to-javascript/#findComment-925648 Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 Well the reason for that is because strings must be surrounded by quotes, while ints don't need to be. Quote Link to comment https://forums.phpfreaks.com/topic/175665-solved-php-variable-pass-to-javascript/#findComment-925650 Share on other sites More sharing options...
elabuwa Posted September 27, 2009 Author Share Posted September 27, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/175665-solved-php-variable-pass-to-javascript/#findComment-925656 Share on other sites More sharing options...
mikesta707 Posted September 27, 2009 Share Posted September 27, 2009 echo "<td> <a href=\"javascript:post_value('$idz');\">SELECT</a></td>"; try that. you have nested single quotes which is probably causing the problem Quote Link to comment https://forums.phpfreaks.com/topic/175665-solved-php-variable-pass-to-javascript/#findComment-925694 Share on other sites More sharing options...
elabuwa Posted September 27, 2009 Author Share Posted September 27, 2009 hey mikeeee it worked. thanks bro :D Quote Link to comment https://forums.phpfreaks.com/topic/175665-solved-php-variable-pass-to-javascript/#findComment-925779 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.