Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,208 members, 7,818,705 topics. Date: Sunday, 05 May 2024 at 10:17 PM

Sub Menu With A Twist - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Sub Menu With A Twist (956 Views)

How To Create Dropdown Menu With Html And Css / How Do I Create Space Between The Menu(nav) And <h1> - Snapshot / Simple Drop Down Menu With Jquery And CSS (2) (3) (4)

(1) (Reply) (Go Down)

Sub Menu With A Twist by skyhighweb(m): 2:30pm On May 16, 2017
i have this code below its working fine but i need it to display result the other way round for example the code display result like this

On click(Nigeria) it shows drop menu of (3,6,4)
On click (Ghana) it shows drop menu of (5,2)

i want the code altered so it displays this way

On click(Nigeria) it shows drop menu of (5,2)
On click (Ghana) it shows drop menu of (3,6,4)


code below thanks



<?php
error_reporting(E_ALL);
ini_set('display_errors',0);
require_once('conn.php');
$country_result = $conn->query('select * from countries');
?>

<select name="country" id="countries-list">
<option value="">Select Country</option>
<?php
if ($country_result->num_rows > 0) {
// output data of each row
while($row = $country_result->fetch_assoc()) {
?>
<option value="<?php echo $row["id"]; ?>"><?php echo $row["country_name"]; ?></option>
<?php
}
}
?>
</select>
</br></br></br>
<select name="state" id="states-list">
<option value=''>Select State</option>

</select>
<?php

$country_id = mysql_real_escape_string($_POST['country_id']);
if($country_id!='')
{
$states_result = $conn->query('select * from states where country_id='.$country_id.'');
$options = "<option value=''>Select Name</option>";
while($row = $states_result->fetch_assoc()) {
$options .= "<option value='".$row['country_id']."'>".$row['state']."</option>";
}
echo $options;
}

?>


<script src="js/jquery-1.3.0.min.js"></script>
<script>
$('#countries-list').on('change', function(){
var country_id = this.value;
$.ajax({
type: "POST",
data:'country_id='+country_id,
success: function(result){
$("#states-list"wink.html(result);
}
});
});
</script>
Re: Sub Menu With A Twist by skyhighweb(m): 6:59am On May 17, 2017
no response
Re: Sub Menu With A Twist by chygoz3(m): 5:04pm On May 17, 2017
Which URL are you making your Ajax call to?
Re: Sub Menu With A Twist by skyhighweb(m): 6:05pm On May 17, 2017
chygoz3:
Which URL are you making your Ajax call to?
i only have aa menu code without d submenu so not calling yet
Re: Sub Menu With A Twist by chygoz3(m): 6:59pm On May 17, 2017
From my understanding of your code, when the page loads, the countries select input is populated with a list of countries. Assuming all the php code is in one file, the part where you are trying to get the States for a country will result in an error because $_POST['country-id'] will not have a value (loading the page the first time is done using the http GET method).
Now since you want to load the states in a selected country asynchronously via AJAX when a country is selected, you need to pass the fill the url parameter of ajax which tells Ajax which php file to call.
From the code you provided, it is unclear what the error you are trying to fix is.
Re: Sub Menu With A Twist by skyhighweb(m): 7:26pm On May 17, 2017
chygoz3:
From my understanding of your code, when the page loads, the countries select input is populated with a list of countries. Assuming all the php code is in one file, the part where you are trying to get the States for a country will result in an error because $_POST['country-id'] will not have a value (loading the page the first time is done using the http GET method).
Now since you want to load the states in a selected country asynchronously via AJAX when a country is selected, you need to pass the fill the url parameter of ajax which tells Ajax which php file to call.
From the code you provided, it is unclear what the error you are trying to fix is.
ok i get what u saying, am think of trying something else, will update soon

(1) (Reply)

CPA Account / Freelancing Might Just Be The Future Of Work In Nigeria / Naija Non Hosted Adsense Account For Sale

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 15
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.