doforumda Posted April 12, 2009 Share Posted April 12, 2009 hi i created a button "Edit" and i make a function for that in javascript. when the user click on the button it should call that javascript function and go to the specified page. i did all this but it is not doing anything. how can this problem be solved? Link to comment https://forums.phpfreaks.com/topic/153703-how-to-call-javascript-function-in-php/ Share on other sites More sharing options...
ram4nd Posted April 12, 2009 Share Posted April 12, 2009 It can't, until you wont give us the code. If i would tel you that my code doesn't work but it should to do work then how the hell can you tel me whats wrong. Link to comment https://forums.phpfreaks.com/topic/153703-how-to-call-javascript-function-in-php/#findComment-807747 Share on other sites More sharing options...
doforumda Posted April 12, 2009 Author Share Posted April 12, 2009 Here is the code <?php $db_connect = mysql_connect("localhost","username","password"); mysql_select_db("database",$db_connect); if(isset($function) && $function == "edit") { echo "Function is not set"; $sql_query = "select * from statusvalues where statVal_id = &mode"; print($sql_query); } if(isset($function) && $function == "add") { echo "This is the value - $regionNumber<br>"; $sql_query = "insert into statusvalues (firstname,lastname,region,ssn) values ('".$fname."','".$lname."','".$regionNumber."','".$ssn."')"; $exe_query = mysql_query($sql_query); } $sql_reg = "select * from region"; $sqlQuery = mysql_query($sql_reg); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script language="JavaScript"> function go_to_page(hlink) { window.location = "indexxx2.php?function=edit&mode="+hLink+""; } </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <form name="form1" method="post" action="indexxx.php?function=add"> <p>First Name: <input type="text" name="fname" id="fname"> </p> <p>Last Name: <input type="text" name="lname" id="lname"> </p> <p>Select Region Number: <?php echo "<select name='regionNumber' id='regionNumber'>"; while($record = mysql_fetch_array($sqlQuery)) { echo "<option value = '".$record['regionNumber']."'>".$record['regionNumber']."-".$record['regionName']."</option>"; } echo "</select>"; ?> </p> <p>Enter SSN No Dashes: <input type="text" name="ssn" id="ssn"> </p> <p> <input type="submit" name="button" id="button" value="OK"> </p> </form> <?php $selectQuery = "select * from statusvalues";// order by lastname ASC"; $resultName = mysql_query($selectQuery);// or die(mysql_error()); ?> <table width='400' border='1' cellspacing='0' cellpadding='0'> <tr> <td>ID</td> <td>First Name</td> <td>Last Name</td> <td>Region</td> <td> </td> </tr> <?php while($record = mysql_fetch_array($resultName)) { ?> <tr> <td><?php echo $record['statVal_id'] ?></td> <td><?php echo $record['firstname'] ?></td> <td><?php echo $record['lastname'] ?></td> <td><?php echo $record['region'] ?></td> <td><input type = "button" name = "edit1" value = "Edit" onclick="javascript(go_to_page(<?php echo $record['statVal_id'] ?>));"/></td> </tr> <?php } ?> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/153703-how-to-call-javascript-function-in-php/#findComment-807748 Share on other sites More sharing options...
MasterACE14 Posted April 12, 2009 Share Posted April 12, 2009 please use [ code ] [ /code ] tags. <?php $db_connect = mysql_connect("localhost","username","password"); mysql_select_db("database",$db_connect); if(isset($function) && $function == "edit") { echo "Function is not set"; $sql_query = "select * from statusvalues where statVal_id = &mode"; print($sql_query); } if(isset($function) && $function == "add") { echo "This is the value - $regionNumber<br>"; $sql_query = "insert into statusvalues (firstname,lastname,region,ssn) values ('".$fname."','".$lname."','".$regionNumber."','".$ssn."')"; $exe_query = mysql_query($sql_query); } $sql_reg = "select * from region"; $sqlQuery = mysql_query($sql_reg); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script language="JavaScript"> function go_to_page(hlink) { window.location = "indexxx2.php?function=edit&mode="+hLink+""; } </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <form name="form1" method="post" action="indexxx.php?function=add"> <p>First Name: <input type="text" name="fname" id="fname"> </p> <p>Last Name: <input type="text" name="lname" id="lname"> </p> <p>Select Region Number: <?php echo "<select name='regionNumber' id='regionNumber'>"; while($record = mysql_fetch_array($sqlQuery)) { echo "<option value = '".$record['regionNumber']."'>".$record['regionNumber']."-".$record['regionName']."</option>"; } echo "</select>"; ?> </p> <p>Enter SSN No Dashes: <input type="text" name="ssn" id="ssn"> </p> <p> <input type="submit" name="button" id="button" value="OK"> </p> </form> <?php $selectQuery = "select * from statusvalues";// order by lastname ASC"; $resultName = mysql_query($selectQuery);// or die(mysql_error()); ?> <table width='400' border='1' cellspacing='0' cellpadding='0'> <tr> <td>ID</td> <td>First Name</td> <td>Last Name</td> <td>Region</td> <td> </td> </tr> <?php while($record = mysql_fetch_array($resultName)) { ?> <tr> <td><?php echo $record['statVal_id'] ?></td> <td><?php echo $record['firstname'] ?></td> <td><?php echo $record['lastname'] ?></td> <td><?php echo $record['region'] ?></td> <td><input type = "button" name = "edit1" value = "Edit" onclick="javascript(go_to_page(<?php echo $record['statVal_id'] ?>));"/></td> </tr> <?php } ?> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/153703-how-to-call-javascript-function-in-php/#findComment-807749 Share on other sites More sharing options...
doforumda Posted April 12, 2009 Author Share Posted April 12, 2009 still unresolve i am still waiting anybody Link to comment https://forums.phpfreaks.com/topic/153703-how-to-call-javascript-function-in-php/#findComment-807755 Share on other sites More sharing options...
neon Source Posted April 12, 2009 Share Posted April 12, 2009 hi i created a button "Edit" and i make a function for that in javascript. when the user click on the button it should call that javascript function and go to the specified page. i did all this but it is not doing anything. how can this problem be solved? You can't call a javscript function from php. Php is a server side script and javascript client side. Php is parsed on the server and outputs an html file from which you can call the javascript function by using php to print a button with an onclick attribute that called the function. Link to comment https://forums.phpfreaks.com/topic/153703-how-to-call-javascript-function-in-php/#findComment-807763 Share on other sites More sharing options...
doforumda Posted April 12, 2009 Author Share Posted April 12, 2009 can you tell where am i making a mistake in my code? Link to comment https://forums.phpfreaks.com/topic/153703-how-to-call-javascript-function-in-php/#findComment-807769 Share on other sites More sharing options...
RichardRotterdam Posted April 12, 2009 Share Posted April 12, 2009 Couldn't you just simply use a hyperlink ??? Instead of this: <input type = "button" name = "edit1" value = "Edit" onclick="javascript(go_to_page(<?php echo $record['statVal_id'] ?>));"/> Use this: <a href="your_target_page.php?page_id=<?php echo $record['statVal_id'] ?>">edit</a> Link to comment https://forums.phpfreaks.com/topic/153703-how-to-call-javascript-function-in-php/#findComment-807771 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.