Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 10th, 2008, 03:50 PM
Authorized User
Join Date: Nov 2007
Location: , , Ireland.
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default PHP dropdown list

I am a newcomer to PHP from a asp.net
I have 2 dropdown lists on my page, the first ia hard coded with 3 values, once selected I want the 2nd dropdown list to be populated based on whats selected in the first, the second list is to be populated from a mysql DB, I want to change the SQL command for it based on the option value selected in the first list. help please, i know code is messy, have been looking forums piecing together... any ideas please or even a simple example to steer me in the right direction!!
here is my code which sits in the form:

                <td>Function Type:</td>
                <td><select name="cat" onchange="return reload(this)">
                            <option value="">--------Select--------</option>
                            <option value="1" text="Hardware">Hardware</option>
                            <option value="2">Stationery</option>
                            <option value="3">System Module</option>

                <select name="select_subcat">
                <?php $cat=$HTTP_GET_VARS['select_fxn'];?>
                <option value="" onchange=\"return reload(this.form)\">--------Select--------</option>


My Javascript:
function reload(thisform)
    var val=document.forms['frm_regbarcode'].cat.options[document.forms['frm_regbarcode'].cat.options.selectedIndex].value;
self.location='ch_test.php?cat=' + val ;
// return true;

// return true;

function reload3(form)
    var val=document.forms['frm_regbarcode'].cat.options[document.forms['frm_regbarcode'].cat.options.selectedIndex].value;
var val2=document.forms['frm_regbarcode'].select_subcat.options[document.forms['frm_regbarcode'].select_subcat.options.selectedIndex].value;

self.location='ch_test.php?cat=' + val + '&select_subcat=' + val2 ;
Thank You
Old September 25th, 2008, 01:15 AM
Friend of Wrox
Join Date: Oct 2003
Location: colombo, WP, Sri Lanka.
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran

hi mate,
try to use basic ajax script for this

(Anything is Possible)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dropdown list maha .NET Framework 2.0 7 April 28th, 2007 12:32 AM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
HELP WITH DROPDOWN LIST enavas Excel VBA 1 April 6th, 2004 02:08 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.