Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dropdown so no submit button is needed...No javascript

Posted on 2008-10-31
8
Medium Priority
?
351 Views
Last Modified: 2013-12-13
I have a dropdown menu and when I select the option I have to hit the submit button. Is there a way without using java scrip that if I select an entry from drop down list, it executes this code
<?php //air code
if (isset('submit')) //this part will be replaced as I will take out the submit button
{
run my code
}

thanks
0
Comment
Question by:syedasimmeesaq
  • 4
  • 3
8 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 22853367
>>without using java script
No. a dropdown is NOT a submit element. To submit the form you will need a submit button OR scripting to do the submission.
0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 22853433
ok how would I do that in javascript so it runs the php code
Thanks
0
 
LVL 6

Expert Comment

by:fourice
ID: 22853442
Perhaps this is what you want?
<script>
	function submitForm(selObj)
	{
		var selIndex = selObj.selectedIndex;
		if(selObj.options[selIndex].value != "")
		{
			document.testForm.submit();
		}
	}
</script>
<form name="testForm" method="post" action="yourfile.php">
	<select name="selectBox" onchange="submitForm(this)">
		<option value="">Choose an option</option>
		<option value="1">1</option>
		<option value="2">2</option>
		<option value="3">3</option>
	</select>
</form>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 22853471
no I want to run this code when the list is chosen
<?php //air code
if (isset($_POST['submit'])) //this part will be replaced as I will take out the submit button
{
$value = $_POST['dropdownvalue'];
header("location: newpage.php");
exit;
}
?>
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 22853474
<select name="selectBox" onchange="this.form.submit()">
0
 
LVL 82

Expert Comment

by:hielo
ID: 22853489
<?php //air code
if (isset($_POST['selectBox'])) //this part will be replaced as I will take out the submit button
{
$value = $_POST['dropdownvalue'];
header("location: newpage.php");
exit;
}
?>
0
 
LVL 9

Author Closing Comment

by:syedasimmeesaq
ID: 31512164
thanks!
0
 
LVL 82

Expert Comment

by:hielo
ID: 22854677
you are welcome
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question