Unable to pass PHP variable to a Javascript function -
i trying php variable pass values sample javascript nothing shows if tried echo result.
i tried passing regular strings arguments , worked fine. doesn't seem working if tried pass php variables arguments.
aes (rijndael) encryption test in javascript
<script type="text/javascript" src="decrypt.js"></script> </head> <body> <?php mysql_connect("localhost","root",""); mysql_select_db("encryption") or die(mysql_error()); $userid = $_post['userid']; if (($_server['request_method'] == 'post') && ($_post['key'] == "")) { $query = mysql_query("select * employee_details id = '$userid'"); if($row=mysql_fetch_assoc($query)) { echo '<tr>'; foreach($row $value) echo '<td>'.$value.'</td>'; echo '</tr>'; } else { echo "no rows returned"; }} else if (($_server['request_method'] == 'post') && ($_post['key'])) { $columname = "ciphertext"; $tablename = "employee_details"; function getfield($field, $tbl_name, $condition) { $result = mysql_query("select $field $tbl_name id = ".$condition); return @mysql_result($result, 0); } $myvalue = getfield($columname,$tablename,$userid); echo "ciphertext = $myvalue"; echo "<br>"; //dodecryption(); } echo '<script type="text/javascript"> dodecryption("<?php $myvalue; ?>"); </script>'; echo "whats happening"; ?> </body> </html> the js file
function dodecryption(param) { document.write(param); document.write("programming change"); } thanks in advance. appreciated!!!!
you not need echo statement build javascript-part, try this:
<script type="text/javascript"> dodecryption("<?php echo $myvalue; ?>"); </script> but if not want change , want write out -block via echo, should not use "
echo '<script type="text/javascript"> dodecryption(' . $myvalue . '); </script>';
Comments
Post a Comment