Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Run a php script with a form select

Posted on 2013-12-01
11
Medium Priority
?
405 Views
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?
0
Comment
Question by:burnedfaceless
[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
  • 6
  • 2
  • 2
  • +1
11 Comments
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39688446
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
}

HTH,
Dan
0
 

Author Comment

by:burnedfaceless
ID: 39688464
Cool
Can you provide an ajax example?

I already know JavaScript.
0
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 39688468
var myDiv = document.getElementById("myDiv");
document.getElementById("mySelect").onchange = someFunction(this);

function someFunction(object){  
    $.ajax({
        url: 'yourscript.php',
        data: 'content=' + object.value,
        cache: false,
        error: function(e){
            alert(e);
        },
        success: function(response){
            // A response to say if it's updated or not
            alert(response);
        }
    });  
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 44

Expert Comment

by:Chris Stanyon
ID: 39688488
If you intend to use jQuery, then just bind the change event directly:

$('#mySelect').change(function() {
   $.ajax({
      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']
0
 

Author Comment

by:burnedfaceless
ID: 39688537
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.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39694111
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"
0
 

Author Comment

by:burnedfaceless
ID: 39694184
Thanks I'll read AJAX and visit links and determine what fits our needs.
0
 

Author Comment

by:burnedfaceless
ID: 39694187
I'll examine the js file
0
 

Author Comment

by:burnedfaceless
ID: 39694192
But again Ray this is debugging the form distortion so I'm contingent upon loading a php echo
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39694245
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
0
 

Author Comment

by:burnedfaceless
ID: 39694373
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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 dynamically set the form action using jQuery.

715 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