Passing parameters with ONBLUR event

Hi,

There are basically 4 fields in a form, being Name,Company,Email and Phone. I’m trying to use the ONBLUR event, on the email field, to then pass parameters to a JS function, which calls a PHP file, to insert a row into a MySQL db. I saw an example of how to do this, using a hidden field, possibly I need 3 hidden fields to pass the 3 parameters (value of fields) ?. Anyway, here is the code:


<!DOCTYPE html PUBLIC "-//W3C//Dtd XHTML 1.0 Transitional//EN"
                   "Dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
   <meta name="Author" content="Peter" />
   <title>Test DB Insert</title>
<script type="text/javascript" src="datetime.js">
	</script>
</head>

<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD width="130">

<FONT SIZE="2" COLOR="#66CCFF" FACE="Verdana, Arial">

Full Name</TD>
<TD>
<input type="text" size="25" name="name">
</td></tr><tr>
<td><FONT SIZE="2" COLOR="#66CCFF" FACE="Verdana, Arial">

Company Name</td><td><input
type="text" size="25" name="company"> </TD></TR>

<tr><td width="130"><FONT SIZE="2" COLOR="#66CCFF" FACE="Verdana, Arial">

Email</td>
<td>
<input type="text" size="25" name="email" onBlur="updateDB(name.value,company.value,email.value);"></td></tr>

<tr><td width="100"><FONT SIZE="2" COLOR="#66CCFF" FACE="Verdana, Arial">

Phone Number</td><td>
<input type="text" size="25" name="phone"></td></tr>
<input type="hidden" name="hiddenname" value="<?= $name ?>">


The JS file datetime.js


function updateDB(theName, theCompany, theEmail){
 top.invisbleFrame.href =
"datetime.php?name="+theName+"&company="+theCompany+"&email="+theEmail;
}

and the PHP file datetime.php


<?php

getparms();

@mysql_pconnect("localhost", "dbusername", "dbpwd") or die ("cannot connect to database");
mysql_select_db("dbname");

//evaluate the date and time in the format yyyy-mm-dd hh:mm:ss
$date = date ("Y-m-d H:i:s");
$name = $parameters[1];
$company = $parameters[2];
$email = $parameters[3];
mysql_query ("insert into test values (NULL, '$date','$name','$company','$email')") or die(mysql_error());

function getparms(){
	// receive all parameters in the $parameters array:
	$parameters = func_get_args();
	// ...
	return $result;
}
?>

I’m probably doing something really stupid. Can someone please tell me what I’m doing wrong ? Do I need hidden fields at all, or can I just pass the value of the fields to the JS function, etc ?? :slight_smile:

Thanks,

Peter

What is going wrong ? I can think of some things to check.

In the HTML

  1. It should be a php file for your hidden field to work
  2. You don’t appear to have any < form>< /form> tags

In the Javascript file

  1. It appears to refer to a frame named invisibleFrame that you have not created, I wonder if this is supposed to work from inside a frameset
    php <frameset cols="0,*" frameborder="no" border="0"> <frame src="blank.html" name="invisibleFrame" NORESIZE> <frame src="formPage.php" name="MAIN"> </frameset>

Hi,

Yes, the HTML code is in a PHP file already, called test.php

You don’t appear to have any < form>< /form> tags

Do I need them ? I’m not wanting to do a post/submit, but cause the execution of a PHP file/code when the ONBLUR event is triggerred.

In the Javascript file - It appears to refer to a frame named invisibleFrame that you have not created, I wonder if this is supposed to work from inside a frameset

Okay, I will try that, adding the code you supplied.

Thanks,

Peter