Solved

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

Posted on 2008-10-31
8
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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 500 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find RGB colors from a screen. 2 42
Echo values after a query in php 5 52
Ajax success not firing alert 6 45
Phone number mask 4 16
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

710 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