SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Retreive url variables and put into form elements

    I am trying to pull two variables from a url and insert them into the appropriate text fields in a html form.

    URL:
    orderform.php?shape=Longboard&model=Cutter

    I have this javascript, which searches the url string, HOWEVER it pulls the string into one variable. ie - Shape: LongboardCutter - INSTEAD OF: Shape: Longboard - Model: Cutter.

    Code:
    <script language="JavaScript">
    document.form1.shape.value = location.search.substring(1);
    </script>
    [b]How do I get the javascript to pull the two variables seperately?[\b]

    Regards,
    Kevin

  2. #2
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, in php, you could do
    PHP Code:
    $shape $_GET['shape'];
    $model $_GET['model']; 
    And then you could set the variables through there.

  3. #3
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tried that and it dosent work...it shows up blank where the variable should show

    My code:
    Code:
    <?
    $P_shape = $_GET['shape'];
    $P_model = $_GET['model'];
    ?>
    
    <input name="model" type="text" id="model">
     <script language="JavaScript"><!--
    document.form1.model.value = $P_model;
    //--></script>
    It just shows up blank where the variable should come in.

  4. #4
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't access php values when you're not in PHP

    Try this:
    PHP Code:
    <?php
    $P_shape 
    $_GET['shape'];
    $P_model $_GET['model'];
    ?>

    <input name="model" type="text" id="model">
     <script language="JavaScript"><!--
    document.form1.model.value = <?php echo $P_model?>
    //--></script>
    I also noticed that you were using short tags.


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
  •