Results 1 to 5 of 5

Thread: Passing on the current value of a field

  1. #1
    Join Date
    Apr 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Passing on the current value of a field

    Sorry if this question has already been asked before, but I really am a n00b when it comes to coding with JavaScript.

    What I am looking to do is pass on the current value of a field into a pop-up window. The value needs to be written into a PHP variable. How I do this does not really matter. The method I have used thus far is as follows:

    Code:
    <input class="mainField" name="to" type="text" id="to" size="50" />
    		
    <script type="text/javascript" language="JavaScript">
         var value = document.compose.to.value
    </script>
    
    <input name="button" type="button" class="btn" onclick="window.open('userSearch.php?field=to&value=+value','_search','width=400,height=200,left=100,top=100,resizable')" value="Find Users" />
    What I am basically looking for is a really short script that takes the current value from the field named "to" and passes it to the opened window. I wondered whether it was possible to write a JavaScript variable to a PHP variable, for example:

    Code:
    $value = ?><script language="JavaScript">var value = "document.compose.to.value";
    document.write(value);
    </script>
    <?php ;?>
    Any help with this problem really would be gratefully received.

    Many thanks in advance,
    Ben

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Beings that you are going to be assigning the PHP variable anyways, why not just assign it with the value from the form directly. In other words:

    Code:
    <?php
    $value = $_REQUEST['to']; //get the form field with the name "to".
    
    //rest of code here
    ?>
    Unless I am mising something, or misunderstood you post, it appears that this is pretty much all that you wanted. Although, if you wanted it to open in a new window, you could just do something like this:

    Code:
    <form action="userSearch.php" method="POST" target="_blank">
    That will open userSearch.php and it's results in a new browser window.
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Apr 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    thetestingsite,

    Many thanks for your response. The reason that I did not use the $_REQUEST variable in PHP is due to the fact that I don't actually want to submit the form.

    Basically, I want to have a field that contains a list of usernames, for example user1,user2. Each time the "Find User" button is pressed, it should open the userSearch.php window, and pass on the current value of the field, so that another username can be appended to the end of the string (hope that makes sense).

    So basically, I would use opener.document to write the username to the field, but because I need to append each username, I need to maintain the current value, for example:

    Code:
    <select name="course" class="mainField"  onchange="javascript:window.opener.document.compose.<?php echo $field;?>.value = <?php echo $currentValue;?>,(this.value)">
    I hope that all makes sense, it is pretty difficult to put all of this into words

    Many thanks once again,
    Ben
    Last edited by benmajor; 04-20-2007 at 07:03 AM. Reason: Formatting Error

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, you can't.

    PHP is executed server-side; this means it finishes executing before the Javascript is even sent to the browser. The only way it can do anything is by executing again, which involves requesting the page again.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Quote Originally Posted by Twey
    The only way it can do anything is by executing again, which involves requesting the page again.
    Which would remove the point of client-side technologies.
    - Mike

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
  •