Solved

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

Posted on 2008-10-31
8
339 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now