Jump to content

How to save value??


Piba

Recommended Posts

Hi guys,

I have a drop down menu, the user must choose form this dropdown

and when he choose, another dropdown menu will show up according to what he choose

 

So, the second drop down is called in other page...

 

My problem is the value in the second dropdown menu won't be saved if the page is refreshed!!

 

I know how to save the value of the first one:

<select name=dropdown1>
<option name=option1 value=1 <? if ($_POST['dropdown1']=="1") echo selected=selected; ?> >option1</option>
</select>

 

But how could i save the value of the second dropdown menu ???

 

Hope i'm explaining my problem well ;D

 

thanks alot,

 

Piba

Link to comment
Share on other sites

maybe add an onchange submit to an AJAX/PHP script which would add sessions to state which second dropdown should be, and what should be selected?

 

then when it reloads it would figure out what option to select from the session

Link to comment
Share on other sites

hi you shall use like this <select name='dropdown2' onchange='save(this.value);'></select> you should use ajax program you should pass 'selected value' to the insert query page.

 

for eg:-

    function save(str)

    {

      var url = 'query.php?dropdown2='+str;

      .....

      .....

    }

 

you should pass like this to avoid page refresh..

Link to comment
Share on other sites

Hi Myth

Thnaks for your replay..

 

i'm afraid that i dont understand exactly how to make this ???

Becasue i have already onchange in the select

 

Here is the code of select1:

<html>
<head>
<script src="selectuser.js"></script>
</head>
<body><form> 
Select a User:
<select name="dropdown1" onchange="showUser(this.value)">
<option value="1" <? if(isset($_POST['dropdown1'])) if($_POST['dropdown1']==1) echo $_POST['dropdown1']; ?>>Peter Griffin</option>
<option value="2" <? if(isset($_POST['dropdown1'])) if($_POST['dropdown1']==2) echo $_POST['dropdown1']; ?>>Lois Griffin</option>
<option value="3" <? if(isset($_POST['dropdown1'])) if($_POST['dropdown1']==3) echo $_POST['dropdown1']; ?>>Glenn Quagmire</option>
<option value="4" <? if(isset($_POST['dropdown1'])) if($_POST['dropdown1']==4) echo $_POST['dropdown1']; ?>>Joseph Swanson</option>
</select>
</form><p>
<div id="txtHint"><b>User info will be listed here.</b></div>
</p></body>
</html>

 

Then the js page:

var xmlHttpfunction showUser(str)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getuser.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
} 
}function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
}
return xmlHttp;
}

 

and finally the select2:

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'peter', 'abc123');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("ajax_demo", $con);

$sql="SELECT * FROM user WHERE id = '".$q."'";

$result = mysql_query($sql);

<select name=dropdown2>

while($row = mysql_fetch_array($result))
{
echo "<option name=info value='$row['FirstName']'>";
}
echo "</table>";

mysql_close($con);
?>

 

 

So, how could i save the second value in dropdown2 when the page relode??

I don't think onchange in dropdown2 will work!???!??!

 

Could help plz :)

 

Link to comment
Share on other sites

<select name="dropdown1" onchange="showUser(this.value)">

 

simply add another behind it. Theres no limitations on the amoutn of functions that can be executed.

 

<select name="dropdown1" onchange="showUser(this.value); function2(); function3(); etc..">

 

Would execute all those commands onchange.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.