SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    May 2003
    Posts
    590
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    PHP 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

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

    PHP Code:
    <?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 ??

    Thanks,

    Peter

  2. #2
    SitePoint Addict BenANFA's Avatar
    Join Date
    Apr 2003
    Location
    Bath, UK
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 Code:
      <frameset cols="0,*" frameborder="no" border="0">
          <
      frame src="blank.html" name="invisibleFrame" NORESIZE>
          <
      frame src="formPage.php" name="MAIN">
      </
      frameset

  3. #3
    SitePoint Evangelist
    Join Date
    May 2003
    Posts
    590
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing parameters with ONBLUR event

    Hi,

    Quote Originally Posted by BenANFA
    In the HTML - It should be a php file for your hidden field to work
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •