Forum Moderators: coopster

Message Too Old, No Replies

Combo box to submit?

         

AlexLee

1:20 pm on Feb 19, 2005 (gmt 0)

10+ Year Member



Hi, how do I use the combobox to submit the page to itself?

I want to use the combobox to submit then when it opens itself again, the textfields below would be filled with data form the DB.

hughie

3:08 pm on Feb 19, 2005 (gmt 0)

10+ Year Member



you need to use Javascript to submit the form,

something like:

in the header put

<SCRIPT language="JavaScript">
function submitform()
{
document.form1.submit();
}
</SCRIPT>

then for the body put

<form name="form1" method="post" action="<?pjp echo $_SERVER[PHP_SELF];?>">

<input type="checkbox" name="checkbox1" value="checkbox" onClick="javascript:submitform();">
</form>

should do the job

hughie

AlexLee

12:16 am on Feb 20, 2005 (gmt 0)

10+ Year Member



What I want is to use a dropdown menu. It will have datas inside and when the user selects the data, it will fill the textfield below with data from database. And the value of the dropdown menu would be selected on the one the user clicks...

Like when you register for Hotmail and the part where you have to select your country... It will bring you to another page with details more connected to your country...

hughie

10:39 am on Feb 20, 2005 (gmt 0)

10+ Year Member



You can do this very similar to the above script (i read checkbox, not combobox ;-) )

so similar to before
<?php
// DBASE CONECT HERE

//
if (isset($_POST['finalsubmit']))
{
// PROCEED TO NEXT FORM
}
else
{
if (isset($_POST['select1']) && $_POST['select1']!=0)
{
$result=mysql_query("SELECT * FROM states WHERE country_id=$_POST[select1] ");
$thestates='STATES <select name="states">';
while($row=mysql_fetch_array($result))
{
// RETURN DETAILS OF THE COUNTRY CHOSEN
$thestates.='<option value="'.$row[State_ID].'">'.$row[State].'</option>';
}
$thestates.='</select>';
}
}

?>
<html>
<head>
<SCRIPT language="JavaScript">
function submitform()
{
document.form1.submit();
}
</SCRIPT>
</head>
<body>
<form name="form1" method="post" action="<?php echo $_SERVER[PHP_SELF];?>">

<select name="select1" onChange="javascript:submitform();">
<option value="0" selected>Please Choose a Country</option>
<option value="1">UK</option>
<option value="2">USA</option>
</select>
<?php echo $thestates;?>
<Br><br>
<input type="submit" name="finalsubmit" value="FINAL SUBMIT">
</form>
</body></html>

when the person changes the select box the for will reload and pullout the states of the relevant country.

cheers hughie

hakre

5:24 pm on Feb 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What I want is to use a dropdown menu. It will have datas inside and when the user selects the data, it will fill the textfield below with data from database. And the value of the dropdown menu would be selected on the one the user clicks...
Like when you register for Hotmail and the part where you have to select your country... It will bring you to another page with details more connected to your country...

if you're looking for a way to have your form interact immediatly with the user (ie after he changes something), this is client side. for client side you need to use javascript / ecma script / vbscript or any scriptlanguage browsers support. please refer to the javascript forum for that.

php itself is server side and recieves no events or requests when a user changes the content of a dropdown menu (combobox). php could have eventually provided the page incl. specific scripts and their data, but that's before the page is displayed.

gettopreacherman

2:33 am on Feb 23, 2005 (gmt 0)

10+ Year Member



If you don't have an issue with immediate updating, you can post back to the form itself like:

<form action="self.php"> then when the form loads it uses the information passed back to itself to pull the query from the dbase and display...