0

What is wrong with my code?

After clicking the button, I want to hide and show a div with another result.

This is happening, but is not running the submit code. The field value is not getting propagated.

$(document).ready(function(){ $('#conteudo').hide(); $('#button').click(function(event){ $('form#form1').submit(function(event){ $("#form").hide("slow"); $("#conteudo").show("slow"); event.preventDefault(); }); }); $('#mostrar').click(function(event){ event.preventDefault(); $("#form").show("show"); $("#conteudo").hide("show"); }); }); 
5
  • 4
    Why are you preventing default? That's why it isn't submitting. Commented Dec 23, 2013 at 17:34
  • Are you attempting to refresh just part of the page and do the submit "silently"? If so, you will need more code than this... you'll need to call some sort of AJAX routine to submit the data without the whole page loading the form target. My guess is that's what you're trying to avoid by preventing the submit in the first place, and hiding and showing things doesn't matter if you're going to a whole new page, anyhow. Commented Dec 23, 2013 at 17:41
  • Someone could help me? I'm just doing it with the submit, because when I put this option to hide a div and show another, annulled the command that occurred directly on the form. Commented Dec 23, 2013 at 18:07
  • impossible to know nobody do it here. Have helped me with the most difficult things ... Commented Dec 23, 2013 at 18:50
  • possible duplicate of Hiding div after submit button pressed - not workin Commented Jun 15, 2015 at 19:57

2 Answers 2

2

http://api.jquery.com/submit/ says:

...so we can cancel the submit action by calling .preventDefault() on the event object or by returning false from our handler. ...

You should remove the preventDefault()

Sign up to request clarification or add additional context in comments.

1 Comment

If I remove the "event.preventDefault()", the submit happens, but does not appear to another div.
0

Unable to do. If a friend has the same problem solved in this way.

$(document).ready(function(){ $('#conteudo').hide(); <?php if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { ?> $(document).ready(function(){ event.preventDefault(); $("#form").hide("slow"); $("#conteudo").show("slow"); }); <?php } ?> $('#mostrar').click(function(event){ event.preventDefault(); $("#form").show("show"); $("#conteudo").hide("show"); }); }); 

Comments