Wrox Programmer Forums
|
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 July 20th, 2006, 10:18 AM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default OnChange issue

Hi there. I am pretty new to PHP and finding it pretty cool..

Having problem with the following code..

Have the Select working fine on opening the page, but the ONSUBMIT is not printing the desired results.

Copied the code from: http://p2p.wrox.com/topic.asp?TOPIC_ID=17383
Code:
<html>
<head>
<title>Test</title>
</head>
<body>
<?php
//http://p2p.wrox.com/topic.asp?TOPIC_ID=17383
$city = null; //declare vars
$conn = mysql_connect ("localhost","login","password");
$db = mysql_select_db('database',$conn);
if(isset($_GET["city"]) && is_numeric($_GET["city"]))
{
    $city = $_GET["city"];
}
?>
<script language="JavaScript">
function autoSubmit()
{
    var formObject = document.forms['theForm'];
    formObject.submit();
}
</script>
<form name="theForm" method="get">
    <select name="city" onChange="autoSubmit();">
        <option value="null"></option>
        <?php
        //POPULATE DROP DOWN MENU WITH STATES FROM A GIVEN REGION, COUNTRY

        $sql = "SELECT DISTINCT city FROM lodges";
        $cityname = mysql_query($sql,$conn);

        while($row = mysql_fetch_array($cityname))
        {
            echo ("<option value=\"$row[city]\" ".($city == $row["city"] ? " selected" : "").">$row[city]</option>");        
        }
        ?>
    </select>
        <?php
        if($city != null)
    {
        //POPULATE DROP DOWN MENU WITH CITIES FROM A GIVEN REGION, COUNTRY, STATE

        $sql = "SELECT id, secretary FROM lodges WHERE city = $city ";
        $secretaries = mysql_query($sql,$conn);

        while($row = mysql_fetch_array($secretaries))
        {
            echo $row[secretary];
    }
    ?>
</form>
</body>
</html>
The dropdown works great, but I see no restults onchange..

Thanks,

Kent


 
Old July 21st, 2006, 04:32 PM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Never mind.. Got it to work.. had to make some change with $_POST and $_GET.. It works great now.

Thanks,

Kent

 
Old October 4th, 2006, 06:45 AM
Registered User
 
Join Date: Oct 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to kumarj
Default

hi ,pls check this you r not menson the ACTION attribute in
the form tag. To list selected item values ,select query with
selected item.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Option's onclick,onchange events issue manishk73 Javascript 7 August 29th, 2008 01:20 PM
onChange Event mcinar Javascript 11 May 11th, 2007 09:38 AM
Event:OnChange catchrohith Classic ASP Basics 0 November 3rd, 2006 12:52 AM
'onChange' crmpicco Javascript How-To 2 January 28th, 2005 05:37 AM
Onchange listbox Varg_88 JSP Basics 1 June 16th, 2004 07:45 AM





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