SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Mar 2003
    Location
    Australia
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript loads PHP in background

    Hello programmers, I have a small question.
    I have a javascript which processes a form input using
    onSubmit return processFAQ()

    What I need to do is to capture the form input into a database so that I know what questions are being asked about my product. Also it can help me identify which questions are asked the most and which questions I have not covered in the javascript answers.

    In short, is it possible for something like
    <form action="storequestion.php" method="get" onSubmit=return processFAQ()> ?

    I tried the above but once it runs the php file it totally breaks out of the script, ignoring the onSubmit.

    Do anyone know how I could get around this? I will appreciate any help with gratefulness.

  2. #2
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    You could try putting the processFAQ() on your submit button
    Code:
    <form action='storequestion.php' method='get'>
    <input type='submit' name='submit' onClick='processFAQ()' />

  3. #3
    Bangarang! Karloff's Avatar
    Join Date
    Mar 2003
    Location
    Manchester, United Kingdom
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just leave the form tag the way it is and have this in your script:

    Code:
    function processFAQ() {
      if ( whatever_you_need_to_check ) {
    	// whatever you wish to do if the submit
    	// requirements were met
     
    	// now you explicitly submit the form via script
    	document.forms[0].submit();
    	return false;
      } else {
    	// whatever if submit requirements were
    	// not met
    	return false;
      }
    }

    Hope it helps,
    Karl
    Last edited by Karloff; Mar 16, 2003 at 03:19.

  4. #4
    SitePoint Member
    Join Date
    Mar 2003
    Location
    Australia
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DJ P@CkMaN
    You could try putting the processFAQ() on your submit button
    Code:
    <form action='storequestion.php' method='get'>
    <input type='submit' name='submit' onClick='processFAQ()' />
    Thanks DJ, I tried that but it didn't work too. It continued to process the javascript but quickly went to storequestion.php and breaks out of the script.

    I'm now having to opening another window for the php file so that it does not interupt the javascript.

    Do you (or anyone reading this) know how to send a variable to an external open.document ? Please help..

  5. #5
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Yes
    Code:
    window.open('file.php?foo=bar', etc...);
    and in the PHP file
    PHP Code:
    <?php
    echo $_GET['foo'];
    ?>

  6. #6
    SitePoint Member
    Join Date
    Mar 2003
    Location
    Australia
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DJ P@CkMaN
    Yes
    Code:
    window.open('file.php?foo=bar', etc...);
    and in the PHP file
    PHP Code:
    <?php
    echo $_GET['foo'];
    ?>
    Thanks. Does that mean if I want to port the variable $input (from javascript) into $foo in PHP I use:

    window.open('file.php?foo=$input', etc...);

    or

    window.open('file.php?foo=print("var input") ', etc...);

    Thanks heaps.. guess that will be my last question...


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
  •