0

hi
i'm new to ajax i've already got a drop down menu populated with values from my database and the code is underneath here, when i click on any province in the drop down menu the cities have to appear on the next page which are also from my database.The cities have to appear using a code from ajax i hear, i tried using a code from w3schools but doesn't seem to work at the moment.what i would like is a little bit of light on how i'm going to go about tackling this kinda problem.Just for clarity the drop down menu does work

[<html>]

[<head>][title]<?php echo $title;?>[/title]

[<h1>]<?php echo $heading;?>[</h1>]
[<script type="text/javascript">]
[</script>]

[</head>]
[<body>]
<?
    function writeCities($id)
    {       
        $con = mysql_connect("localhost","root","");
        if (!$con) die('Could not connect: ' . mysql_error());
        mysql_select_db("msansi", $con);
        $query  = "SELECT cities FROM provinces WHERE id =";
        $query .= $id;
        $result = mysql_query($query);          

        $row = mysql_fetch_array($result);
        echo $row[0];       
    }



    function populateDropBox()
    {
        $con = mysql_connect("localhost","root","");
        if (!$con) die('Could not connect: ' . mysql_error());
        mysql_select_db("msansi", $con);
        $result = mysql_query("SELECT id,title,cities FROM provinces");

        while($row = mysql_fetch_array($result))
        {   
            echo "<option value=$row[0]>" . $row['title']."</option>";
        }
    }
?>

    [<form name="myform">]

        <select name = "province" onChange="onChangeDropBox();/"> 
        <? populateDropBox(); ?>     
        <input type ="submit" value="submit";/>     
        </form>      
[<script type="text/javascript">]

[</script>] 
[</body>]

Edited by mike_2000_17: Fixed formatting

Attachments
<html>

<head><title><?php echo $title;?></title>

<h1><?php echo $heading;?></h1>

<script type="text/javascript">

</script>

</head>

<body>


<?
	function writeCities($id)
	{		
		$con = mysql_connect("localhost","root","");
		if (!$con) die('Could not connect: ' . mysql_error());
	  	mysql_select_db("msansi", $con);
		$query  = "SELECT cities FROM provinces WHERE id =";
		$query .= $id;
		$result = mysql_query($query);			
				
		$row = mysql_fetch_array($result);
		echo $row[0];		
	}
	


	function populateDropBox()
	{
		$con = mysql_connect("localhost","root","");
		if (!$con) die('Could not connect: ' . mysql_error());
	  	mysql_select_db("msansi", $con);
		$result = mysql_query("SELECT id,title,cities FROM provinces");
		
		while($row = mysql_fetch_array($result))
		{	
		    echo "<option value=$row[0]>" . $row['title']."</option>";
		}
	}
?>
 
	<form name="myform">
	
		<select name = "province" onChange="onChangeDropBox();"> 
		<? populateDropBox(); ?> 	
		<textarea name ="textArea" readonly="true"></textarea>     
		</form>	  	
<script type="text/javascript">
function onChangeDropBox()

	{
		var selected =0;
		selected = document.myform.province.value;					
		
		var t = "<? writeCities(9);?>";
		document.myform.textArea.value = t;
				
		}
</script> 
	  

	  
	  
	  
</body>
</html>
2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by kgizo
0

Kgizo,

"next page" and "ajax" are mutually exclusive. It's either one or the other.

Which do you want?

Airshow

0

ok thanxx i know that now airshow i've created a new window using the window.open method in javascript now all i need to do is fetch information from my database and display the cities as soon as you click on the submit button when a province is chosen from my drop menu.
thanxx in advance.

0

Kgizo,

Creating a new window doesn't address the point I was making.

Do you want :

  1. to use AJAX to obtain the data from the database and display it on the same page without refreshing the page (that's what AJAX does).
  2. to serve a new page (in to the same window or an opened window) to display the data.

Your original post is ambiguous in this regard.

Airshow

Edited by Airshow: n/a

0

thanxx airshow i managed to solve my problem using php i used a form to move from 1 page to another with the action method then i posted my provinces. i also managed to get my data from my database and display it on different pages. thannx for your interest!!!!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.