SitePoint Sponsor |
|
User Tag List
Results 1 to 10 of 10
Thread: query dropdown menu value
Hybrid View
-
Aug 6, 2002, 02:26 #1
query dropdown menu value
Hi..
I have a dropdown menu thats pull value from MySQL.
Now i want to query the selected value from dd menu so then it will display a list that match with it in database without submit the page.
Do i have to use onChange function and how?
Sorry i'm new to javascript.
Thanks in advance.
-
Aug 6, 2002, 08:07 #2
-
Aug 6, 2002, 18:15 #3
Ok
My problem is something like this.
This is my dd menu. (Actually its pullout data from MySQL)
PHP Code:<select name="semester" size="1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
2. Query the database based on selected value.
$query = "SELECT * FROM semester WHERE sem = '1'"
3. Then it will display a result that match with the query without submit the page.
Any ideas?
Please help.
-
Aug 6, 2002, 22:35 #4
- Join Date
- Jul 2002
- Location
- Dallas, TX
- Posts
- 2,900
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well, you couldn't acutally do this w/o submitting the page. However, if you devised an algorithm to stuff all the results from SELECT * FROM semester into a javascript array, then you can use the onChange() event attached to the SELECT to display what you need. Something like this perhaps
PHP Code:$result = mysql_query("SELECT * FROM semester");
$fetch = mysql_fetch_array($result);
echo("<script>\n var arr = new Array();\n");
$count = 0;
foreach($fetch as $val) {
echo("arr[".$count."] = '".$val."\n");
count++;
}
echo("</script>\n");
-
Aug 8, 2002, 00:38 #5
Hi.
I've tried that one but it doesnt work.
I'm more into php rather than javascript.
Is there any other way?
-
Aug 8, 2002, 07:14 #6
- Join Date
- Jul 2002
- Location
- Dallas, TX
- Posts
- 2,900
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hmmm, maybe a bit more like this...
PHP Code:$result = mysql_query("SELECT * FROM semester");
echo("<script>\n var arr = new Array();\n");
$countOuter = 0;
$countInner = 0;
foreach (mysql_fetch_array($result) as $tempArr)
{
echo("arr[".$countOuter."] = new Array()\n");
$countInner = 0;
foreach($tempArr as $val)
{
echo("arr[".$countOuter."][".$countInner."] = '".$val."\n");
$countInner++;
}
$countOuter++;
}
echo("</script>\n");
-
Aug 8, 2002, 19:55 #7
Ok. with changes at
foreach($tempArr as $val) to
foreach(mysql_fetch_array($result) as $val) it will give me array like this
arr[0] = new Array()
arr[0][0] = '2
arr[0][1] = '2
arr[0][2] = '2
This array give redundant data. One silly question from me is how the array will looklike?
Thanks.
-
Aug 9, 2002, 06:27 #8
- Join Date
- Jul 2002
- Location
- Dallas, TX
- Posts
- 2,900
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This worked for me
http://www.lanwizards.com/test.php
In put the PHP source on the page in HTML. You can View>>Source to see the javascript array.
My test semesters table looks like thisCode:+----+--------+----------+ | id | name | length | +----+--------+----------+ | 1 | Fall | 3 months | | 2 | Winter | 3 months | | 3 | Spring | 3 months | | 4 | Summer | 1 month | +----+--------+----------+
-
Aug 11, 2002, 22:14 #9
Okies
Thanks I got it.
Whats next?
-
Aug 12, 2002, 06:09 #10
- Join Date
- Aug 2001
- Location
- London
- Posts
- 2,475
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
"Well, you couldn't acutally do this w/o submitting the page", this is possible with remote scripting or using the xml dom.
heres an example of this
http://www.ashleyit.com/rs/jsrs/select/php/select.php
also
http://www.w3schools.com/xml/xml_http.asp
any way try that
Bookmarks