Welcome to WebmasterWorld Guest from 54.224.63.26

Forum Moderators: incrediBILL

Message Too Old, No Replies

drop down box

drop down box without submit button

     
2:33 am on Aug 4, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:July 23, 2005
posts:44
votes: 0


Hi all,
I am trying to make a drop down box which does not need a submit button. As soon as one of the options in the drop down box is selected, the webpage should know what is being selected and should take action accordingly.

Thanks for your help
Opiston

3:06 am on Aug 4, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 18, 2003
posts:1925
votes: 0


<select name="blah" onchange="this.form.submit()">
8:06 am on Aug 5, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:July 23, 2005
posts:44
votes: 0


Hi moltar,

Thanks for your help

I have 2 files involved in my drop down box.
The first file is named: top.php


//I have some query before this starts

print "<form method = 'post' name = 'dept_drop' action = 'top_proc.php'>";
print "<select name='sel_dept' onChange = 'form.dept_drop.action.submit();'>";
while ($myrow = mysql_fetch_array($query)) {
print "<option value=$myrow[1]>$myrow[0]</option>";
}

The second file is named: top_proc.php
When one of the options in the drop down box is selected, I want to go to top_proc.php to process the selected option.
But I don't konw how to redirect to top_proc.php after an option is selected.

I know how to redirect when a submit button is presented, but in this case, I don't want a submit button.
Do you have any suggestions?

Regards
Opiston

9:18 am on Aug 5, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 7, 2003
posts:1404
votes: 0


If you want to use a GET then you could use something like this example.

I included this javascript into my file.

<script language="JavaScript" type="text/javascript">
<!--
function ChangePage(Opt_List)
{
var sel_dept = Opt_List.options[Opt_List.selectedIndex].value;
sel_dept = sel_dept * 1;
window.location="../top_proc.php?dept=" + sel_dept ;
}
//-->
</script>

Then the form looks like:

<?php

print "<form>";
print "<select name='sel_dept' onChange='ChangePage(this);'>";
while ($myrow = mysql_fetch_row($result)) {
print "<option value=$myrow[1]>$myrow[1]</option>";
}
print "</form>";

?>

top_proc.php receives the value of sel_dept as a parm.

<?php
// top_proc.php
$dept = $_GET['dept'];
echo $dept;
?>

You could then use Mod Rewrite to remove the parameter string from the URL before its displayed to the user.

9:27 am on Aug 5, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 27, 2003
posts:63
votes: 0


Try using Dreamweaver to create the drop down box its easy to do and then copy and paste the code. This is how I do it and it works fine.

Hope this helps

11:34 am on Aug 5, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:July 23, 2005
posts:44
votes: 0


Hi Grandpa,
Nice to see you again.
Just like the last time, you solved my problem. I do not understand the javascript, but it meets my need.

Thank you for your help once again
Regards
Opiston

Hi The Grizzler,
I heard about dreamweaver before, but I never really used it.
Thanks for your recommendation.

Regards
Opiston

8:01 pm on Aug 5, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:July 23, 2005
posts:44
votes: 0


Hi grandpa,
Ahh .. I kind of understand the script now
I never knew we can pass values through url

window.location="../top_proc.php?dept=" + sel_dept ;

thanks for sharing this knowledge
Regards
Opiston

9:41 pm on Aug 5, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 7, 2003
posts:1404
votes: 0


I do not understand the javascript, but it meets my need

That's exactly how I feel about javascript. Funny thing too, it really isn't that hard.

Happy to help opiston.

7:47 am on Aug 26, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:July 23, 2005
posts:44
votes: 0


Hi grandpa,
Is there a way to obtain the value in sel_dept without using the javascript?
I am encountering a problem with that javascript.
That javascript runs sel_dept_proc.php and when I click on submit on one of my pages, sel_dept_proc.php seems to be still running and again takes the value of the whatever the user just selected into the url.

When the user click on the submit button on other page, another page, let's say test_proc.php, comes up to process the input just entered.

So the url should be www.something.com/main.php?page=test_proc.php
But instead it gives me
www.something.com/main.php?sel_dept=2&cl_text%5B0%5D=on=&update=Submit
So that test_proc.php does not get executed.

The strange thing is that it works fine with firefox, but iexplore encounters problem.

Any suggestions?