Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function code executes prematurely 2

Status
Not open for further replies.

RPGguy

Programmer
Jul 27, 2001
73
0
0
US
I'm trying to get the hang of functions using PHP and JavaScript but I have a problem I can't fix. My HTML for a form starts with:
<html>
<head>

<? include(&quot;banner.html&quot;);
include(&quot;navigate.html&quot;);
include(&quot;custtitle.html&quot;);
require (&quot;function.php&quot;);
?>

</head>

The function looks like this:

function funDelCust()

<script LANGUAGE=&quot;JavaScript&quot;>
if (confirm(&quot;Are you Sure&quot;)) {
alert(&quot;OK&quot;);
WRITE(&quot;THIS IS A TEST&quot;);
} else {
alert(&quot;NOT OK&quot;)
}
</SCRIPT>

(I'm just trying to get the functionality down for now. I'll add the real code later.)

The problem is that the confirm window pops up as soon as the form is displayed (the fields are not populated either). It also prints &quot;function funDelCust()&quot; under my headings on the form I had intended to execute the function when the 'Delete' key was pressed but the program doesn't wait. Once I press 'OK' in the window the fields are populated and the form works ok except the delete key does not execute the function.

All help is greatly appreciated.

Scott
 
Could you show us the code? I'm suspecting that funDelCust() is not in the header of the page.

Take Care,
Mike
 
Mike, thanks for the reply. The code at the top is the real code and the 'required' is in the header. I can't see any logical reason for this not working but it's not.

Scott
 
I guess I'm not clear if you're implying that functionDelCust() is in function.php?
Where is functionDelCust() being called from? Is it a PHP function or a JavaScript function. If you intend to use it as a javascript function, do this in function.php:

<script>
function funDelCust()
{
if (confirm(&quot;Are you Sure&quot;))
{
alert(&quot;OK&quot;);
WRITE(&quot;THIS IS A TEST&quot;);
}
else {alert(&quot;NOT OK&quot;;)}
}
</script>
</script>

Take Care,
Mike
 
Mike,
I have changed my approach in that now when the user presses the 'Delete Customer' button I go to a window that conatins the code below. The Questions pops up but clicking on either 'Yes' or 'No' does nothing. I have put print statements in each function but they never get displayed. 'cookcust' is a value I det as a cookie. Here is the entire code of the called HTML:

<HTML>

<HEAD>
<?
function doDel() {

$cust = $_REQUEST[&quot;cookcust&quot;];
$query4 = &quot;DELETE from tblCust where Cust = '$cust'&quot;;

$link = mysql_connect(&quot;localhost&quot;, &quot;*****&quot;, &quot;*****&quot;);
mysql_select_db(&quot;Liebert&quot;);

$result = mysql_query($query4);
print &quot;Deleted&quot;;
}

function doExit() {
print &quot;Back&quot;;
}
?>

</HEAD>

<div align=&quot;center&quot;>
<center>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse&quot; bordercolor=&quot;#111111&quot; width=&quot;50%&quot; id=&quot;AutoNumber1&quot;>
<tr>
<td width=&quot;100%&quot; colspan=&quot;3&quot; align=&quot;center&quot;>Are you sure you want to
delete this customer and all associated records?</td>
</tr>
<tr>
<td width=&quot;100%&quot; align=&quot;center&quot; colspan=&quot;3&quot;>&nbsp;</td>
</tr>
<tr>
<td width=&quot;33%&quot; align=&quot;center&quot;>
<form method=&quot;POST&quot; action=&quot;--WEBBOT-SELF--&quot;>
<p><input type=&quot;button&quot; value=&quot;Yes&quot; name=&quot;btnYes&quot; tabindex=&quot;1&quot; style=&quot;float: right&quot; onClick=&quot;doDel()&quot;></p>
</form>
<p>&nbsp;</td>
<td width=&quot;33%&quot; align=&quot;center&quot;></td>
<td width=&quot;34%&quot; align=&quot;center&quot;>
<form method=&quot;POST&quot; action=&quot;--WEBBOT-SELF--&quot;>
<p><input type=&quot;button&quot; value=&quot;No&quot; name=&quot;btnNo&quot; tabindex=&quot;2&quot; style=&quot;float: left&quot; onClick=&quot;doExit()&quot;</p>
</form>
<p>&nbsp;</td>
</tr>
</table>
</center>
</div>

</HTML>


Thanks again.
 
PHP is not a client side scripting language such as JavaScript. PHP is processed by the server, hence the client never gets to see any PHP code.
Have you read anything of the manual? It's a great resource:
//Daniel
 
Right, you will have to code anything that the user does, or that responds to the users actions in JavaScript.
Could you send your original code to webmaster at emmgee dot com and I'll take a look at it for you.

Take Care,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top