We help IT Professionals succeed at work.

Run a php script with a form select

Last Modified: 2013-12-03
Is it possible to have a php script called when a select is selected? Without a submit button?

How can I do this? Even if it takes ajax or something?
Watch Question

Dan CraciunIT Consultant

You can use the onclick or onchange events for your select to make an ajax call.

No need for a submit button.

Here's how to call a js script on onchange:

var myDiv = document.getElementById("myDiv");
document.getElementById("mySelect").onchange = function(){
  your code here



Can you provide an ajax example?

I already know JavaScript.
IT Consultant
This one is on us!
(Get your first solution completely free - no credit card required)
Most Valuable Expert 2018
Distinguished Expert 2019

If you intend to use jQuery, then just bind the change event directly:

$('#mySelect').change(function() {
      url: 'myScript.php',
      type: 'post',
      data: { selectValue: $(this).val() }
   .done(function(response) {
      //do something with response

Open in new window

This will fire the AJAX call when an element with an ID of mySelect is changed. It will call a file called myScript.php and pass the value of the SELECT in the POST array as $_POST['selectValue']


Thanks, I'm about to pick up a book on AJAX. I just realized this will do a lot of things I was wondering about.
Most Valuable Expert 2011
Author of the Year 2014

Make a Google search for "Learning jQuery" and follow the links.  A book on AJAX would have been a good idea in 2002.  The whole industry has gone beyond that now and jQuery powers a great many AJAX requests.  You might also be interested in "bootstrap.js"


Thanks I'll read AJAX and visit links and determine what fits our needs.


I'll examine the js file


But again Ray this is debugging the form distortion so I'm contingent upon loading a php echo
Most Valuable Expert 2011
Author of the Year 2014

this is debugging the form distortion so I'm contingent upon loading a php echo
It's quotes like that which make me want to lead you toward learning the fundamentals.  Web development is like most technologies -- it has its own language.  Without the language, you're crippled and with it you'll make progress in leaps and bounds but only after you learn the vocabulary and syntax.

One really good way to learn a language is by "immersion" so if you can find a local web development user group, I encourage you to join, make presentations, participate in code reviews and generally become active.

Best of luck with your project, ~Ray


Ray I'm right on this. I will accept your advice any day of the week but this is the only way to do what my boss asked.

JavaScript writing html is gimmicky.

Php is great because you can keep the double quotes.

Your intentions are good I know, but this is the easiest solution to the problem.

Thanks for your input ~ Brian

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.