SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast MAC#1's Avatar
    Join Date
    Mar 2003
    Location
    ontario
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php from javascript

    PHP Code:
    document.write('
    <a href=prod_show.php code_no='
    +thenumber+'>'+theitem+'</A>'); 
    Hi,
    I have this javascript code in a php page. I need to access the value of '+thenumber+' into a variable that PHP would understand so that I can carry the "thenumber" value onto the next page and have it be a usable php value.

    I've tried:
    PHP Code:
    document.write('<INPUT TYPE=hidden NAME="number" VALUE="'+thenumber+'">'
    but this didn't work probably because I have no clue as to how to do this. Any ideas? thanks.

  2. #2
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably your best bet would be to pass this value through the URL if you are using a link:
    Code:
    document.write('<a href="[link]?[varName]='+thenumber+'">[linkText]</a>');
    unless you are using a form, then the hidden field should work.
    John

  3. #3
    SitePoint Enthusiast MAC#1's Avatar
    Join Date
    Mar 2003
    Location
    ontario
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using a submit button...
    PHP Code:
    FORM METHOD="GET" ACTION="order.php"><INPUT TYPE="submit" VALUE=" <?php echo $txt_checkout ?> "
    I've also tried but it didn't work either:
    PHP Code:
    <INPUT TYPE=hidden NAME="number" VALUE="document.writeln(+thenumber+)"
    I'm retrieving the value on the next page with
    PHP Code:
    $code_no=$_REQUEST["number".$i]; 
    If there is more than one item ordered than this "number" will be more than one value.

  4. #4
    SitePoint Enthusiast MAC#1's Avatar
    Join Date
    Mar 2003
    Location
    ontario
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MAC#1
    OK... I get this to display the values that I need as long as it's within the <script></script> tags.
    PHP Code:
    document.write(""+thenumber+""
    DISPLAYS:
    48749
    52627
    67382

    So my question is.... How do incorporate the script tags to work with
    PHP Code:
    <INPUT TYPE=hidden NAME="number" VALUE="document.writeln(+thenumber+)"
    ANy ideas??

  5. #5
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe that you are not getting the value because you are not using the right key.

    Use this: $_REQUEST['number']

    The key to $_REQUEST[] MUST be the same as the "name" value in the form.
    John

  6. #6
    SitePoint Enthusiast MAC#1's Avatar
    Join Date
    Mar 2003
    Location
    ontario
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks PHP JOHN tried that but still nothing.

  7. #7
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post the code.
    John

  8. #8
    SitePoint Addict
    Join Date
    May 2003
    Location
    The Netherlands
    Posts
    391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  9. #9
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would this work for you?
    Code:
    <html>
      <head>
    	<title></title>
      </head>
      <body>
    	<script language="javascript" type="text/javascript">
    	  var number = 12;
    	</script>
    	<form action="scriptName.php" method="post" name="formName">
    	  <input type="hidden" name="number" value="" />
    	  <script language="javascript" type="text/javascript">
    		document.write(number);
    	  </script>
    	  <input type="submit" name="submit" />
    	</form>
    	<script language="javascript" type="text/javascript">
    	  document.formName.number.value = number;
    	</script>
      </body>
    </html>
    It works for me just as a test, but I don't know if you could integrate it for what you need.
    John


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
  •