www.webdeveloper.com
Results 1 to 9 of 9

Thread: Drop Down list problem, onchange

  1. #1
    Join Date
    Jan 2004
    Posts
    312

    Drop Down list problem, onchange

    I have a drop down list called "Number_Of_Carts". It has a # selection from 1-9. What I want is, when they click on any number, I want them to go to the same .php script file to pull further data based on the # they chose. It refreshes the page, but it doesn't hold the value! It just come back with first option selected which is an empty option. How can I make it refresh to:
    PHP Code:
    mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>
    Which is my link. Then hold the value of what they selected. So if they choose 4 for instance, then the php code will pull the data from the variable $Number_Of_Carts, so then my script states, if 4 is selected then write "selected" so then the page with refresh with the "4". I hope I made this clear.

    PHP Code:
    <tr>
    <td width="175" height="25"><font size="2"># of Carts:</font></td>
    <td width="427" height="25">
    <select name="Number_Of_Carts" onchange="if(this.options[this.selectedIndex].id){top.location.href=this.options[this.selectedIndex].id;}return true;">
    <option selected></option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>" value="1">1</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>" value="2">2</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>" value="3">3</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>" value="4">4</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>" value="5">5</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>" value="6">6</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>" value="7">7</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>" value="8">8</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>" value="9">9</option>
    </select>
    </td>
    </tr>

  2. #2
    Join Date
    Jul 2004
    Location
    Canada, eh
    Posts
    784
    If I were trying to submit info, I'd use a form. something like this:
    Code:
    <html>
    <body>
    <table>
    <tr> 
    <td width="175" height="25"><font size="2"># of Carts:</font></td> 
    <td width="427" height="25">
    <form action="mobile_vendors_pre_submit.php"> 
    <input type="text" name="state" style="display:none" value="<?php echo ($_GET['state']?$_GET['state']:"0"); ?>"></input>
    <select name="Number_Of_Carts" method="GET" onchange="if(this.selectedIndex>0) this.form.submit();"> 
    <option >- Choose -</option>
    <option value="1" <?php echo ($_GET['Number_Of_Carts']==1?"selected='true'":""); ?>>1</option> 
    <option value="2" <?php echo ($_GET['Number_Of_Carts']==2?"selected='true'":""); ?>>2</option> 
    <option value="3" <?php echo ($_GET['Number_Of_Carts']==3?"selected='true'":""); ?>>3</option> 
    <option value="4" <?php echo ($_GET['Number_Of_Carts']==4?"selected='true'":""); ?>>4</option> 
    <option value="5" <?php echo ($_GET['Number_Of_Carts']==5?"selected='true'":""); ?>>5</option> 
    <option value="6" <?php echo ($_GET['Number_Of_Carts']==6?"selected='true'":""); ?>>6</option> 
    <option value="7" <?php echo ($_GET['Number_Of_Carts']==7?"selected='true'":""); ?>>7</option> 
    <option value="8" <?php echo ($_GET['Number_Of_Carts']==8?"selected='true'":""); ?>>8</option> 
    <option value="9" <?php echo ($_GET['Number_Of_Carts']==9?"selected='true'":""); ?>>9</option> 
    </select>
    <input type="submit" value="Submit"></input>
    </form>
    </td> 
    </tr> 
    </table>
    </body>
    </html>
    Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.

  3. #3
    Join Date
    Jan 2004
    Posts
    312
    Here is what I have now:

    PHP Code:
    <select name="Number_Of_Carts" onchange="this.form.submit();">
    <option selected></option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>&carts=1" value="1">1</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>&carts=2" value="2">2</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>&carts=3" value="3">3</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>&carts=4" value="4">4</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>&carts=5" value="5">5</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>&carts=6" value="6">6</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>&carts=7" value="7">7</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>&carts=8" value="8">8</option>
    <option id="mobile_vendors_pre_submit.php?state=<? $state $_GET['state']; echo $state?>&carts=9" value="9">9</option>
    </select>
    I need it to go to those specified url because the $carts are being read by an include to see if it needs to add more input field, and how many. How can I use the onchange submit form but with the url in the "id" specified by each number!?

  4. #4
    Join Date
    Jan 2004
    Posts
    312
    I need something like:
    PHP Code:
    onChange="location=document.formcheck.Number_Of_Carts.options[document.formcheck.Number_Of_Carts.selectedIndex].id;" 
    but with onchange submit form to the specified "id" url, as if say it was just a regular submit button with form action to the url, but with more than one url option, I need it like this otherwise my data won't pass thru. If I do onchange submit, it parses the data, but doesn't go the the url, just stays in the same place!

  5. #5
    Join Date
    Jan 2004
    Posts
    312
    Can anyone help, i'm real desperate!

  6. #6
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    I'm completely unclear on this question. You want to refresh the current page with a query string which has a value based on what selection is made in a select box?

    Code:
     <select size="1" onchange="location.href=location.href+'?Number_of_Carts='+this.options[this.options.selectedIndex].value">
     <option value="1">One</option>
     <option value="2">Two</option>
     <option value="3">Three</option>
     </select>
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  7. #7
    Join Date
    Jan 2004
    Posts
    312
    Thanx anyways.
    Last edited by d.brandusa; 09-11-2004 at 02:49 PM.

  8. #8
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    I'm sorry but this is too complicated for my little brain. It makes absolutely no sense to me...Sorry.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  9. #9
    Join Date
    Sep 2004
    Posts
    19
    Here is your code:
    PHP Code:
    <select name="Number_Of_Carts" onchange="this.form.submit();"> 
    <option></option> 
    <option id="mobile_vendors_pre_submit.php?state=<?= $_GET['state']?>&carts=1" value="1" <?php ($_GET['Number_Of_Carts']==1? echo 'selected':''); ?>>1</option> 
    <option id="mobile_vendors_pre_submit.php?state=<?= $_GET['state']?>&carts=2" value="2" <?php ($_GET['Number_Of_Carts']==2? echo 'selected':''); ?>>2</option> 
    <option id="mobile_vendors_pre_submit.php?state=<?= $_GET['state']?>&carts=3" value="3" <?php ($_GET['Number_Of_Carts']==3? echo 'selected':''); ?>>3</option> 
    <option id="mobile_vendors_pre_submit.php?state=<?= $_GET['state']?>&carts=4" value="4" <?php ($_GET['Number_Of_Carts']==4? echo 'selected':''); ?>>4</option> 
    <option id="mobile_vendors_pre_submit.php?state=<?= $_GET['state']?>&carts=5" value="5" <?php ($_GET['Number_Of_Carts']==5? echo 'selected':''); ?>>5</option> 
    <option id="mobile_vendors_pre_submit.php?state=<?= $_GET['state']?>&carts=6" value="6" <?php ($_GET['Number_Of_Carts']==6? echo 'selected':''); ?>>6</option> 
    <option id="mobile_vendors_pre_submit.php?state=<?= $_GET['state']?>&carts=7" value="7" <?php ($_GET['Number_Of_Carts']==7? echo 'selected':''); ?>>7</option> 
    <option id="mobile_vendors_pre_submit.php?state=<?= $_GET['state']?>&carts=8" value="8" <?php ($_GET['Number_Of_Carts']==8? echo 'selected':''); ?>>8</option> 
    <option id="mobile_vendors_pre_submit.php?state=<?= $_GET['state']?>&carts=9" value="9" <?php ($_GET['Number_Of_Carts']==9? echo 'selected':''); ?>>9</option> 
    </select>
    This should work

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