Page 1 of 1
<iframe> question
Posted: Thu Aug 05, 2004 5:35 pm
by Think Pink
hy. need some help pls.
i have index.php and page_2.php.
on index.php i have a dropdown (name=country) and a <iframe> with page_2.php loading in it. The page page_2.php has also a dropdown (name=cities).
When i choose a country in index.php, it loads in the dropdown from the <iframe > the corresponding cities.
The question is how I take selected value from dropdown loaded in the <iframe> and insert it in a $db.?
thx in advance
Posted: Thu Aug 05, 2004 5:45 pm
by hawleyjr
It depends. do you want your whole page to refresh when you insert the value or do you want your main page to remain while your iframe refreshes?
<iframe> question
Posted: Thu Aug 05, 2004 6:03 pm
by Think Pink
my main page remains. Only the <iframe> refreshes. I use the <iframe> because is too complicated for me to make a dynamic dropdown with javascript, so the <iframe> size is not bigger than the drop down
Posted: Thu Aug 05, 2004 6:07 pm
by hawleyjr
Put the drop down in a form and submit the form using the onChange javascript function. In the action of the form set it as follows:
Code: Select all
<form action="" method="post" name="form1" target="_self">
Posted: Thu Aug 05, 2004 6:26 pm
by Think Pink
you mean like this?
index.php
Code: Select all
<?php
// connection information
?>
Code: Select all
<table align="center" width="100" cellspacing="0" cellpadding="0" border="1">
<form name="test" method="post" action="<? $PHP_SELF; ?>" >
<tr><td width="100" align="center" valign="middle" height="35">
<select id="selCountry" name="selCountry" onChange="parent.content.location.href=iframe.php?selCountry='+document.getElementById('selCountry').value"><option selected value="0">Select One</option>
Code: Select all
<?php
$sql = "SELECT id_Country, nume_Country FROM Country ORDER BY nume_Country ASC";
$resursa = mysql_query($sql);
while($row = mysql_fetch_array($resursa))
{
print "<option value='".$row['id_Country']."'>".$row['nume_Country']."</option>";
}
?>
Code: Select all
</select></td></tr>
<tr><td width="100" align="center" valign="middle" height="35">frame here
<iframe src="iframe.php" name="content" width="150" height="30" marginwidth="0" marginheight="0" hspace="4" vspace="4" align="middle" scrolling="no" frameborder="0"></iframe>
</td></tr>
<tr><td>
<input type="text" name="message">
</td></tr>
<tr><td>
<input type="submit" name="adaugaOG">
</td></tr>
</form>
</table>
<table align="center" cellspacing="2" cellpadding="2" border="0"><tr><td align="center">
Code: Select all
<?php
if(isset($_POST['adaugaOG'])) {
$sqlOG = "SELECT * FROM oferta_generala";
$resultOG = mysql_query($sqlOG);
$sqlOG = "INSERT INTO ogTbl(id_Country, id_City, transport) VALUES ('".$_POST['selCountry']."', '".$_POST['selJudet']."', '".$_POST['transport']."')";
mysql_query($sqlOG);
print '<span class="mesaj4"><LI> Country a fost adaugata cu succes !</span>';
exit;
}
?>
Code: Select all
</td></tr></table>
iframe.php
Code: Select all
<?php
// connection information
print "<select name="selJudet">";
<option selected value="">Alege City</option>
<?php
$id_Country = $_GET['selCountry'];
$sql = "SELECT id_City, nume_City FROM City WHERE id_Country = '".$id_Country."' ORDER BY nume_City ASC";
$resursa = mysql_query($sql);
while($row = mysql_fetch_array($resursa))
{
print "<option value='".$row['id_City']."'>".$row['nume_City']."</option>";
}
print "</select>";
?>
Posted: Thu Aug 05, 2004 6:50 pm
by hawleyjr
UNTESTED....
OK, I think I know what your trying to do.
Add a hidden field in the form of your main page:
Code: Select all
<form name="test" method="post" action="<? $PHP_SELF; ?>" >
<!-- HIDDEN FIELD -->
<input type="hidden" name="hidden_city">
Replace your current submit button whith this one:
Code: Select all
<input type="submit" name="adaugaOG" onClick="submitForm();return false;">
Add the following Javascript function to the top of the main page:
Code: Select all
function submitForm(){
document.test.hidden_city.value = parent.content.document.iframeform.selJudet.value;
document.test.submit();
}
Replace your current IFRAME code with the following:
Code: Select all
<?php
echo '<form action="" method="get" name="iframeform">';
echo '<select name="selJudet">';
echo '<option selected value="">Alege City</option> ';
$id_Country = $_GET['selCountry'];
$sql = "SELECT id_City, nume_City FROM City WHERE id_Country = '".$id_Country."' ORDER BY nume_City ASC";
$resursa = mysql_query($sql);
while($row = mysql_fetch_array($resursa))
{
echo '<option value="'.$row['id_City'].'">'.$row['nume_City'].'</option>';
}
echo '</select>';
echo '</form>';
?>
This is untested but it should work. Also, I made some changes to how you print strings in php.
You can't print a string by doing the following:
Code: Select all
<?php
print "<select name="selJudet">";
?>
It should look like this:
Code: Select all
<?php
print "<select name="selJudet">";
//or
print '<select name="selJudet">';
//or
echo "<select name="selJudet">";
//or
echo '<select name="selJudet">';
//or
?>
<iframe> question
Posted: Thu Aug 05, 2004 7:13 pm
by Think Pink
not working. now, not even the country name is aded to the $db.
I really don't get this. Some how I see the solution in my head, but it just doesnt work. And I have the same problem with double combos that are in the same page.
in dropdown 1 I chhose country, with an onchange event the page is submited, in dropdown 2 coresponded cities are shown. But now the problem comes with the first dropdown. After the page is submited (to load the second dropdown) the first option selected should be the country I just selected, but appears the first thing that is first in the list.
maybe you could help me with that, and i'll seee later about the other problem with the <iframe>.
Posted: Sat Aug 07, 2004 1:21 pm
by Think Pink
ok, i made it.
i made a javascript tjhat takes the value from dropdown in the <iframe> and puts it in a hidden field on the form in main page.
Thx fro uyour help.