iWillGetBetter iWillGetBetter - 1 year ago 76
PHP Question

PHP AJAX - Can an <input> element have "action" just like how a <form> does?

Forms have an

attribute to specify where (for example a
file) to post to. Do
elements have the

  1. The answer is most likely no. But I wish to know what concept am I getting wrong here?

  2. Is there a equivalent of

  3. The reason I am asking this is that I have a few checkboxes, and I wish to use AJAX to fire something to a PHP file, such that a
    changes when the checkboxes are ticked (I don't want a whole page reload). How should I go about doing this?

I am still drafting the code at this stage, but an example can be seen here.

Appreciate your suggestions!

Answer Source

Based on comments it really sounds like you want something to be sent when any number of checkboxes might be changed.

Add an event handler to all of them, serialize() the form and post it whenever any one of them changes

var $form =$('#myForm'); 
     var formData = $form.serialize();
     $.post('/someFile.php', formData, function(response){
         // do something with response
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download