www.webdeveloper.com
Results 1 to 5 of 5

Thread: Inserting Javascript Variables into DB using PHP

  1. #1
    Join Date
    May 2003
    Posts
    86

    Inserting Javascript Variables into DB using PHP

    Hi, i have a javascript function that opens a new window and at the same time uses php to write a couple variables to a database. The window opens and the php writes to the database but it's not writing the value of the javascript variable i am trying to asign to it.

    here's my code.



    PHP Code:
    function MM_openBrWindow(theURL,winName,features) { //v2.0
    var title = document.form.txtEventTitle.value; 
    var info = document.form.txtEventInfo.value; 
    <?php
    $conn 
    db_connect("dbname");
    $Sql "UPDATE tblTmpEvents SET EventTitle='title', EventInfo='info'";
    $Result mysql_query($Sql);
    ?>
    win = window.open(theURL,'emailWin',features); 
    win.focus();
    }

    As you can see i am setting the variables title and info to the values of 2 text boxes on my form. I then want to write these variables to the database but i cant figure out how to get the value of those variables into the php code.

    How would i go about this?

    Thanks!

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    There are two ways to move a javascript variable to a PHP page. One is by submitting a form, and two is by refreshing the page with a query string (page.htm?variable). You can't just call your javascript variable as a PHP variable.

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  3. #3
    Join Date
    Nov 2003
    Location
    Sacramento CA
    Posts
    5
    pyro - no wonder your the "Super Moderator" You solved a problem I have been trying to figure out for three days. The fact that I would have to submit a form to use a variable seams so out of wack but works like a charm. With this I have finaly put an end to a major part of my message board.

    thanks again!
    Mark Aplet
    http://pixeljunkie.org

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    You can do the same with a regular link:

    <a href="page.php?foo=value">test</a>

    AND:

    $foo = $_GET['foo']; //equals values


    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  5. #5
    Join Date
    Nov 2003
    Location
    Sacramento CA
    Posts
    5
    This is pretty nifty...


    PHP Code:
    <form name="prevform" method="post">
    <
    input type="hidden" name="message">
    <
    input name="action" type="hidden" id="action" value="show">
    </
    form>

    <
    script language="javascript">
    document.prevform.message.value=window.opener.document.PostTopic.message.value;     
    document.prevform.submit();   
    </script> 
    This will take my form info from a preview button and allow me to post it as form data and apply my string manipulations to the form data wich is great because my JS skills are pretty low.
    Mark Aplet
    http://pixeljunkie.org

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles