dwax
asked on
list data from db and submit query?
hi everyone,
i am trying tot create the following, but i can't figure out how to do this.
A listbox (list/menu) gets names from db,
user selects a name from the list,
a query is send to db (where InputName=selected name),
output comes in texfields.
The problem for me is the following, how can i get the selected item from the list,
without using PHP_SELF?InputName=etc.
I've got something like this, but it has to function (if possible) without
getting the data from the browser...By the way, below code isn't working, anyway.
Is this possible? Anyone who kows how to this in a proper way?
Thanks in advance,
derek
code
-------------------------- ---------- ---------- ---------- --
$result=mysql_query("selec t * from $dbTable3", $link);
$rowCheck = mysql_num_rows($result);
echo "<form name=\"CityName\" id=\"CityName\" action=\"$PHP_SELF\" method=\"get\">";
echo "<select name=\"InputName\" onchange=document.all.City Name.submi t();>";
if($rowCheck > 0){
while($row = mysql_fetch_array($result) ){
//put in list
echo "<option>".$row['Name']."< /option>";
}
echo "</select>";
$InputName = addslashes($_GET['InputNam e']);
$result=mysql_query("selec t * from $dbTable3 where Name = '$InputName'", $link);
// get data from db etc..
}else
{
echo "fault";
}
-------------------------- ---------- ---------- ---------- --------
end code
i am trying tot create the following, but i can't figure out how to do this.
A listbox (list/menu) gets names from db,
user selects a name from the list,
a query is send to db (where InputName=selected name),
output comes in texfields.
The problem for me is the following, how can i get the selected item from the list,
without using PHP_SELF?InputName=etc.
I've got something like this, but it has to function (if possible) without
getting the data from the browser...By the way, below code isn't working, anyway.
Is this possible? Anyone who kows how to this in a proper way?
Thanks in advance,
derek
code
--------------------------
$result=mysql_query("selec
$rowCheck = mysql_num_rows($result);
echo "<form name=\"CityName\" id=\"CityName\" action=\"$PHP_SELF\" method=\"get\">";
echo "<select name=\"InputName\" onchange=document.all.City
if($rowCheck > 0){
while($row = mysql_fetch_array($result)
//put in list
echo "<option>".$row['Name']."<
}
echo "</select>";
$InputName = addslashes($_GET['InputNam
$result=mysql_query("selec
// get data from db etc..
}else
{
echo "fault";
}
--------------------------
end code
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Actually I just thought of a somewhat kludgy way. The onChange, instead of submitting the data and having PHP reload the page with new info, could trigger a Javscript function. Within that Javascript function you could already have a switch statement with all the corresponding data that you want outputted to the text field. If the argument matches a case, that text is returned and displayed in your text box. This solution is only feasible with small amounts of data though. You don't want to have a gigantic Javascript function containing all your data if at all possible.
which is what i suggested in the first place...
the difficulties can be smoothed however by using a hidden iframe...
with this solution the javascript doesn't load the list, it loads the iframe which contains the list. after it's done loading then the javascript repopulates the dropdown
the difficulties can be smoothed however by using a hidden iframe...
with this solution the javascript doesn't load the list, it loads the iframe which contains the list. after it's done loading then the javascript repopulates the dropdown
Haven't had the chance to use iframe before, but wouldn't it be safer to use "object" instead, since it's part of the 4.0 standard? Plus, wouldn't using iframe to store the data be the same as coding it directly into the Javascript function as far as the amount of data that needs to be delivered before the page loads? How about some sample code or pseudocode to demonstrate how it would be beneficial?
Either way, I think your solution should work.
Either way, I think your solution should work.
with the iframe solution, you change the src as you change your text entry...
e.g.
<INPUT Type="TEXT" OnChange="GetMyOptions" id="mytext" name="mytext">
<SELECT name="myselect">
</SELECT>
<SCRIPT Language="JavaScript">
myframe.src = "www.mypage.com/myopts.php?" + encode(document.getElement ById("myte xt").text) ;
function TwoBoxMove(a,b,c)
//Andrew Komasinski 2004-10-25 This will move the items from one box to the other
{
if (c == '>>') {
var from = document.getElementById(a) ;
var to = document.getElementById(b) ;
} else
{
var from = document.getElementById(b) ;
var to = document.getElementById(a) ;
}
while (from.selectedIndex > -1)
{
var lastoption = new Option();
lastoption.text = from.options[from.selected Index].tex t;
lastoption.value = from.options[from.selected Index].val ue;
to.options[to.length] = lastoption;
from.options[from.selected Index] = null;
}
}
function reloadQ()
{
TwoBoxMove('myselect','shh ','<<');
}
setTimeout('reloadQ();',10 00*60*5);
</SCRIPT>
where shh is the name of the one being loaded in the iframe and has all of the options set to selected
(I use this code for some other stuff, edit it to fit your requirements exactly)
e.g.
<INPUT Type="TEXT" OnChange="GetMyOptions" id="mytext" name="mytext">
<SELECT name="myselect">
</SELECT>
<SCRIPT Language="JavaScript">
myframe.src = "www.mypage.com/myopts.php?" + encode(document.getElement
function TwoBoxMove(a,b,c)
//Andrew Komasinski 2004-10-25 This will move the items from one box to the other
{
if (c == '>>') {
var from = document.getElementById(a)
var to = document.getElementById(b)
} else
{
var from = document.getElementById(b)
var to = document.getElementById(a)
}
while (from.selectedIndex > -1)
{
var lastoption = new Option();
lastoption.text = from.options[from.selected
lastoption.value = from.options[from.selected
to.options[to.length] = lastoption;
from.options[from.selected
}
}
function reloadQ()
{
TwoBoxMove('myselect','shh
}
setTimeout('reloadQ();',10
</SCRIPT>
where shh is the name of the one being loaded in the iframe and has all of the options set to selected
(I use this code for some other stuff, edit it to fit your requirements exactly)
ASKER
Thanks guys,
The reason why i the info not from the browser, is because i have wuite a heavy
flashmovie on the same page. With every form submit, the movie loads again...
One possible solution, not very neat is put it into frames...
The other one is using an iframe as you suggested. I will look into that a.s.ap.
thanks for your replies!
derek
The reason why i the info not from the browser, is because i have wuite a heavy
flashmovie on the same page. With every form submit, the movie loads again...
One possible solution, not very neat is put it into frames...
The other one is using an iframe as you suggested. I will look into that a.s.ap.
thanks for your replies!
derek
Typically in such a situation I would use Javscript's onChange to submit the data and reload the page with the new data passed along to PHP so it can handle the query and output the proper HTML.