Page 1 of 1
how to retain dropdown list value
Posted: Thu Nov 09, 2006 7:35 am
by mypopy
Hi everyone
Anyone can help?
What I am trying to do is:
I have a s dropdown list on the first page. When I select from the first drop down is not retaining the value,
I want dropdown list retain the chosen values . How can I do that?
Thanks for your help.
Posted: Thu Nov 09, 2006 7:37 am
by feyd
Inject "selected" or "selected="selected"" into the option that was .. selected.
how to retain dropdown list value
Posted: Thu Nov 09, 2006 9:25 am
by mypopy
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
HI I tried but still not working here is my coding
beginning of Store_locator
Code: Select all
<?php
require_once('z3.php');
$Province =getProvince($Data);
$City =getCities($Data);
$Store =getStores($Data);
// die(print_r($_POST));
if (isset($HTTP_POST_VARS['store_locator']))
{
$ID=$_POST['cityid'];
$Sql="SELECT * FROM store where City_ID='".$ID."' order by Store_Name";
$Res=mysql_query($Sql);
//echo $Sql;
$Str="<table><tr><td class='text' >Store Name</td><td class='text' >Location</td><td class='text' >Contact No</td></tr>";
while ($Rw=mysql_fetch_array($Res))
{
$Str.="<tr>
<td class='text' >".$Rw['Store_Name']."</td>
<td class='text'>".$Rw['Store_Location']."</td>
<td class='text'>".$Rw['Contact_No']."</td>
</tr>";
}
$Str.="<tr><td><input type='submit' value='back' name='back' onClick='javascript:history.back(1)' ></td> </tr>";
/*die($Province);
die($City );*/
echo $Str;
}
function getProvince($Data=array(),$ProvinceID="")
{
//die(print_r($_POST));
$Sql="SELECT * FROM province order by Province_Name";
$Res=mysql_query($Sql);
//print mysql_num_rows($Res);
$Str="<select name='province_id' class='inputbox' onchange=\"reload(this.form)\" >";
$Str.=" <option value=''> Select Province</option>";
while ($Rw=mysql_fetch_array($Res))
{
$Selected="";
if (($Data['province_id']==$Rw['Province_ID']) || ($Rw['Province_ID']==$ProvinceID))
{
$Selected="selected";
//die($Data['province_id']);
}
$Str.="<option value=".$Rw['Province_ID']." ".$Selected.">".$Rw['Province_Name']."</option>";
}
$Str.="</select>";
return $Str;
}
function getCities($Data=array(),$ProvinceID="",$CityID="")
{
$ID=$_GET['province_id'];
$Sql="SELECT * FROM city where Province_ID='".$ID."'
order by City_Name";
$Res=mysql_query($Sql);
// print mysql_error();
$Str="<select name='cityid' class='inputbox'>";
$Str.="<option value='0'> Select a City</option>";
while ($Rw=mysql_fetch_array($Res))
{
// print '<br>xx '.$Rw['City_ID'];
$Str.="<option value=".$Rw['City_ID']." ".$Selected.">".$Rw['City_Name']."</option>";
}
$Str.="</select>";
return $Str;
}
function getStores($Data=array(),$CityID="",$StoreID="")
{
$ID=$_POST['cityid'];
$Sql="SELECT * FROM store where City_ID='".$ID."' order by Store_Name";
$Res=mysql_query($Sql);
//echo $Sql;
$Str="<table width='100%' cellpadding='0' cellspacing='0'><tr id class ='text'><td>Store Name</td><td>Location</td><td>Contact No</td></tr>";
while ($Rw=mysql_fetch_array($Res))
{
$Str.="<tr>
<td>".$Rw['Store_Name']."</td>
<td>".$Rw['Store_Location']."</td>
<td>".$Rw['Contact_No']."</td>
</tr>";
}
$Str.="</table>";
return $Str;
}
?>
<html>
<head>
<title>Store Locator</title>
<link rel='stylesheet' type='text/css' href='../../templates/organic_fusion_1.0/css/template_css.css'>
</head>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.province_id.options[form.province_id.options.selectedIndex].value;
self.location='store_locator.php?province_id=' + val ;
}
function validateForm(objForm)
{
var returnStatus = 1;
if (objForm.Make.selectedIndex == 0) {
alert("Please select a City");
returnStatus = 0;
};
if (returnStatus) {
objForm.submit();
}
}
function validateForm(objForm)
{
var returnStatus = 1;
if (objForm.Make.selectedIndex == 0) {
alert("Please select a car make");
returnStatus = 0;
};
if (returnStatus) {
objForm.submit();
}
}
function Validate(form)
{
if (document.store_locator.cityid.value == '0') {
alert("Please provide us with a selection.\n");
return false;
}
}
</script>
</head>
<body>
<form method=post name=store_locator action='locator.php' method='post' enctype='multipart/form-data' METHOD="POST" onSubmit="return Validate(this);">
<tr><td>Please select a province followed by a city then press submit to view the stores in that area.<br><br>
</td></tr>
<tr>
<td><?php echo $Province?></td>
<td><?php echo $City?></td>
<td><input type="submit" value="submit" name="store_locator" class='button' onClick="validateForm(document.store_locator)" ></td>
</tr>
</form>
</body>
</html>
end of Store_locator
________________________________________________________________________________________________________________________
beginning of locator
<?
require_once('z3.php');
/*die($Province);
die($City );*/
$stores=getStores($Data);
function getStores($Data=array(),$CityID="",$StoreID="")
{
//sql to select city
$CID=$_POST['cityid'];
$Cty="SELECT * FROM city where City_ID='".$CID."' order by City_Name";
$RCty=mysql_query($Cty);
while ($RwCty=mysql_fetch_array($RCty))
{
echo "<table align='center' class='componentheading'><tr><td>Stores in ".$RwCty['City_Name']."</td></tr></table>";
}
$ID=$_POST['cityid'];
$Sql="SELECT * FROM store where City_ID='".$ID."' order by Store_Name";
$Res=mysql_query($Sql);
//echo $Sql;
$Str="<table width='80%'cellpadding='0' cellspacing='0' class='componentheading'><tr><td>Store Name</td><td>Location</td><td>Contact No</td></tr>";
while ($Rw=mysql_fetch_array($Res))
{
$Str.="<tr>
<td class='text' >".$Rw['Store_Name']."</td>
<td class='text'>".$Rw['Store_Location']."</td>
<td class='text'>".$Rw['Contact_No']."</td>
</tr>";
}
$Str.="<tr><td><input type='submit' value='back' name='back' onClick='javascript:history.back(1)' class='back_button'></td> </tr>";
/*die($Province);
die($City );*/
return $Str;
}
?>
<html>
<head>
<title>Store Locator</title>
<link rel='stylesheet' type='text/css' href='../../templates/organic_fusion_1.0/css/template_css.css'>
</head>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.province_id.options[form.province_id.options.selectedIndex].value;
self.location='store_locator.php?province_id=' + val ;
}
</script>
</head>
<body>
<form method=post name=store_locator action='store_locator.php' method='post' enctype='multipart/form-data'>
<tr>
<td class='text'><?php echo $stores?></td>
</tr>
</form>
</body>
</html>
End of locator
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Thu Nov 09, 2006 9:44 am
by Obadiah
cant....read....code.....must...use....php tags
Code: Select all
<?php
require_once('z3.php');
$Province =getProvince($Data);
$City =getCities($Data);
$Store =getStores($Data);
// die(print_r($_POST));
if (isset($HTTP_POST_VARS['store_locator']))
{
$ID=$_POST['cityid'];
$Sql="SELECT * FROM store where City_ID='".$ID."' order by Store_Name";
$Res=mysql_query($Sql);
//echo $Sql;
$Str="<table><tr><td class='text' >Store Name</td><td class='text' >Location</td><td class='text' >Contact No</td></tr>";
while ($Rw=mysql_fetch_array($Res))
{
$Str.="<tr>
<td class='text' >".$Rw['Store_Name']."</td>
<td class='text'>".$Rw['Store_Location']."</td>
<td class='text'>".$Rw['Contact_No']."</td>
</tr>";
}
$Str.="<tr><td><input type='submit' value='back' name='back' onClick='javascript:history.back(1)' ></td> </tr>";
/*die($Province);
die($City );*/
echo $Str;
}
function getProvince($Data=array(),$ProvinceID="")
{
//die(print_r($_POST));
$Sql="SELECT * FROM province order by Province_Name";
$Res=mysql_query($Sql);
//print mysql_num_rows($Res);
$Str="<select name='province_id' class='inputbox' onchange=\"reload(this.form)\" >";
$Str.=" <option value=''> Select Province</option>";
while ($Rw=mysql_fetch_array($Res))
{
$Selected="";
if (($Data['province_id']==$Rw['Province_ID']) || ($Rw['Province_ID']==$ProvinceID))
{
$Selected="selected";
//die($Data['province_id']);
}
$Str.="<option value=".$Rw['Province_ID']." ".$Selected.">".$Rw['Province_Name']."</option>";
}
$Str.="</select>";
return $Str;
}
function getCities($Data=array(),$ProvinceID="",$CityID="")
{
$ID=$_GET['province_id'];
$Sql="SELECT * FROM city where Province_ID='".$ID."'
order by City_Name";
$Res=mysql_query($Sql);
// print mysql_error();
$Str="<select name='cityid' class='inputbox'>";
$Str.="<option value='0'> Select a City</option>";
while ($Rw=mysql_fetch_array($Res))
{
// print '<br>xx '.$Rw['City_ID'];
$Str.="<option value=".$Rw['City_ID']." ".$Selected.">".$Rw['City_Name']."</option>";
}
$Str.="</select>";
return $Str;
}
function getStores($Data=array(),$CityID="",$StoreID="")
{
$ID=$_POST['cityid'];
$Sql="SELECT * FROM store where City_ID='".$ID."' order by Store_Name";
$Res=mysql_query($Sql);
//echo $Sql;
$Str="<table width='100%' cellpadding='0' cellspacing='0'><tr id class ='text'><td>Store Name</td><td>Location</td><td>Contact No</td></tr>";
while ($Rw=mysql_fetch_array($Res))
{
$Str.="<tr>
<td>".$Rw['Store_Name']."</td>
<td>".$Rw['Store_Location']."</td>
<td>".$Rw['Contact_No']."</td>
</tr>";
}
$Str.="</table>";
return $Str;
}
?>
<html>
<head>
<title>Store Locator</title>
<link rel='stylesheet' type='text/css' href='../../templates/organic_fusion_1.0/css/template_css.css'>
</head>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.province_id.options[form.province_id.options.selectedIndex].value;
self.location='store_locator.php?province_id=' + val ;
}
function validateForm(objForm)
{
var returnStatus = 1;
if (objForm.Make.selectedIndex == 0) {
alert("Please select a City");
returnStatus = 0;
};
if (returnStatus) {
objForm.submit();
}
}
function validateForm(objForm)
{
var returnStatus = 1;
if (objForm.Make.selectedIndex == 0) {
alert("Please select a car make");
returnStatus = 0;
};
if (returnStatus) {
objForm.submit();
}
}
function Validate(form)
{
if (document.store_locator.cityid.value == '0') {
alert("Please provide us with a selection.\n");
return false;
}
}
</script>
</head>
<body>
<form method=post name=store_locator action='locator.php' method='post' enctype='multipart/form-data' METHOD="POST" onSubmit="return Validate(this);">
<tr><td>Please select a province followed by a city then press submit to view the stores in that area.<br><br>
</td></tr>
<tr>
<td><?php echo $Province?></td>
<td><?php echo $City?></td>
<td><input type="submit" value="submit" name="store_locator" class='button' onClick="validateForm(document.store_locator)" ></td>
</tr>
</form>
</body>
</html>
end of Store_locator
________________________________________________________________________________________________________________________
beginning of locator
<?
require_once('z3.php');
/*die($Province);
die($City );*/
$stores=getStores($Data);
function getStores($Data=array(),$CityID="",$StoreID="")
{
//sql to select city
$CID=$_POST['cityid'];
$Cty="SELECT * FROM city where City_ID='".$CID."' order by City_Name";
$RCty=mysql_query($Cty);
while ($RwCty=mysql_fetch_array($RCty))
{
echo "<table align='center' class='componentheading'><tr><td>Stores in ".$RwCty['City_Name']."</td></tr></table>";
}
$ID=$_POST['cityid'];
$Sql="SELECT * FROM store where City_ID='".$ID."' order by Store_Name";
$Res=mysql_query($Sql);
//echo $Sql;
$Str="<table width='80%'cellpadding='0' cellspacing='0' class='componentheading'><tr><td>Store Name</td><td>Location</td><td>Contact No</td></tr>";
while ($Rw=mysql_fetch_array($Res))
{
$Str.="<tr>
<td class='text' >".$Rw['Store_Name']."</td>
<td class='text'>".$Rw['Store_Location']."</td>
<td class='text'>".$Rw['Contact_No']."</td>
</tr>";
}
$Str.="<tr><td><input type='submit' value='back' name='back' onClick='javascript:history.back(1)' class='back_button'></td> </tr>";
/*die($Province);
die($City );*/
return $Str;
}
?>
<html>
<head>
<title>Store Locator</title>
<link rel='stylesheet' type='text/css' href='../../templates/organic_fusion_1.0/css/template_css.css'>
</head>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.province_id.options[form.province_id.options.selectedIndex].value;
self.location='store_locator.php?province_id=' + val ;
}
</script>
</head>
<body>
<form method=post name=store_locator action='store_locator.php' method='post' enctype='multipart/form-data'>
<tr>
<td class='text'><?php echo $stores?></td>
</tr>
</form>
</body>
</html>
Posted: Thu Nov 09, 2006 9:57 am
by pickle
What & how is it not working? Could you post a smaller, more relevant section of code so we don't have to wade through 3 pages of possible irrelevant stuff?