2

I have trying to submit a form using jquery. Form is submitted correctly but it do not clear the form after submission.

here is my jquery code

<script type="text/javascript">
    $(document).ready(function(){   
        $("#save").click(function(){    
            $("#myform").submit();
            $("#myform")[0].reset();        
         });    

    });             
</script>

here is my form

<form action="http://localhost/newsletter/index.php/email/send" method="post" accept-charset="utf-8" id="myform" name="myforms">        
    <p>
        <label for="name">Email Address </label>
        <input type="text" name="email" id="email" value="<?php echo set_value('email');?>">

        <input type="button" value="Go" id="save"></p>

</form>

i just want to clear form after submit but it can't reset field, data is submitted and still remain in the field..Any suggestion please??

2
  • because, you aren't using ajax to post form, and after submitting its re-loading form with setting value by this line --> <?php echo set_value('email');?>" Commented Jun 19, 2014 at 8:09
  • stackoverflow.com/a/29621679 Commented Sep 18, 2023 at 14:44

3 Answers 3

0

It's because you use CodeIgniter's function set_value. That will contain the submitted e-mail. You probably use the form validation library in you controller, add some logic there so that your view 'knows' that the e-mail shouldn't be displayed when the validation succeeded.

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

1 Comment

Perhaps giving the OP some code that would add some logic there so that your view 'knows' that the e-mail shouldn't be displayed when the validation succeeded would make your answer an answer and not just a comment.
0

Have you tried using $("#myform").get(0).reset(); instead of $("#myform")[0].reset(); ?

Comments

0

you can just do.

document.getElementById("myform").reset();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.