Jquery form submit with PHP -


I thought that a simple form would submit a problem with Jquery, but I'm running into problems.

I have a form, # listing_step_1, in which the user selects a category from the first dropdown. When a category is selected, the user clicks on "Next", the subcategory dropdown appears. When both a category and subcategory are selected, clicking on the next will take them to step 2 using a redirect. Upon submission, the form is reloading the same page using $ _SERVER ['PHP_SELF'].

I want to resubmit the form automatically so that subcategories do not need to be revealed by clicking on next. I'm trying to do this on a change event on the use of jQuery, but the following code does not work.

  $ ('# item_category'). Change (function () {$ ('# listing_step_1'). Submit ();});  

I appreciate any help with it because I'm new to presenting using jQuery and AJAX. Manually, it's working fine - that is, by pressing the page button and refreshing the PHP page. I thought that the form will be changed just so that it can reload and execute the necessary actions, but this does not seem like it.

Form Code:

  & lt; Form method = "post" name = "listing_step_1" id = "listing_step_1" action = "& lt ;? Php $ _SERVER ['PHP_SELF']? & Gt;" Enctype = "multipart / form-data" & lt ;? Php if ($ errormessage! = "") {Echo 'style = "margin-top: 30px"';}? & Gt; & Gt; & Lt; Div class = "formField fullwidth" & gt; & Lt; Label = "item_category" & gt; Category * & lt; / Label & gt; & Lt; Select id = "item_category" name = "item_category" & gt; & Lt; Option value = "0" & ​​gt; Choose category ... & lt; / Options & gt; & Lt ;? Php $ cd = New category listing ("& lt; option_credits"; "," & lt; / option & gt; "); ? & Gt; & Lt; / Select & gt; & Lt; / Div & gt; & Lt; Div class = "formField fullwidth" & gt; & Lt; Label = "item_subcategory" & gt; Subcategory * * & lt; / Label & gt; & Lt ;? Php if ($ dropdownlist! = "") {? & Gt; & Lt; Id = "item_subcategory" name = "item_subcategory" & gt; Select & lt ;? Php echo $ dropdownlist; ? & Gt; & Lt; / Select & gt; & Lt ;? Php} and {? & Gt; & Lt; Id = "item_subcategory" name = "item_subcategory" disabled = "true" & gt; & Lt; Option value = "0" & ​​gt; Choose subcategory ... & lt; / Options & gt; & Lt; / Select & gt; & Lt ;? Php}? & Gt; & Lt; / Div & gt; & Lt; Input type = "submit" value = "next" id = "submit" name = "submit" style = "width: 100px;" / & Gt; & Lt; / Form & gt;  

Form submission:

  if (isset ($ _ POST ['submit']) {if ($ _ POST ['item_category'] = 0) {$ dropdown list = category listings :: get subcategory dropdown ($ _ POST ['item_gate']); } And {$ errormessage = "Please select a category"; }}  

Jquery:

  $ (document) .ready (function () {$ ('# item_category') .changes (function () { This.form.submit ();});});  

Try it instead:

  $ (Function () {$ ('# Item_category'). Change (function () {this.form.submit ();});});  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -