943,522 Members | Top Members by Rank

Ad:
Nov 13th, 2008
0

javascript form help

Expand Post »
hi there,
i have a problem resetting my form with javascript. I have a registration form that when submitted, the action is performed in an iframe so that the browser does not have to load another page. After form validation, i want the php script in the iframe to clear all fields of the form in the parent document. i have tried all ways like:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. $insert_sql = mysql_query("INSERT INTO ...... ");
  2. if($insert_sql){
  3. ?>
  4. <script>
  5. alert("Query Successful");
  6. parent.document.forms[0].reset();
  7. </script>
  8. <?php
  9. }else{
  10. ?>
  11. <script>
  12. alert("<?php mysql_error($conn); ?>");
  13. </script>
  14. <?php
  15. }

i have tried everything from giving the form an ID and using
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. document.getElementById('form').reset();
But i still cannot reset the form. What can i do. Please help. Thanks alot.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
realnsleo is offline Offline
46 posts
since Apr 2007
Nov 19th, 2008
0

Re: javascript form help

Are you getting any javascript errors?
Reputation Points: 25
Solved Threads: 7
Junior Poster
Drew is offline Offline
166 posts
since Apr 2004
Nov 22nd, 2008
0

Re: javascript form help

Click to Expand / Collapse  Quote originally posted by realnsleo ...
hi there,
i have a problem resetting my form with javascript. I have a registration form that when submitted, the action is performed in an iframe so that the browser does not have to load another page. After form validation, i want the php script in the iframe to clear all fields of the form in the parent document. i have tried all ways like:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. $insert_sql = mysql_query("INSERT INTO ...... ");
  2. if($insert_sql){
  3. ?>
  4. <script>
  5. alert("Query Successful");
  6. parent.document.forms[0].reset();
  7. </script>
  8. <?php
  9. }else{
  10. ?>
  11. <script>
  12. alert("<?php mysql_error($conn); ?>");
  13. </script>
  14. <?php
  15. }

i have tried everything from giving the form an ID and using
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. document.getElementById('form').reset();
But i still cannot reset the form. What can i do. Please help. Thanks alot.

Its difficult to figure out the problem without viewing the code of the while form.
Just a guess:
May be in the your fields have been assigned value after the form reset.
for example
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. $insert_sql = mysql_query("INSERT INTO ...... ");
  2. if($insert_sql){
  3. ?>
  4. <script>
  5. alert("Query Successful");
  6. parent.document.forms[0].reset(); //here you are resetting the form
  7. ........................
  8. ........................
  9. </script>
  10. <?php
  11. }
  12. <form action=...>
  13. <input name="appName" value = "<?php echo $appName; ?>" > <!-- here again values are assigned -->

I guess this may be the problem ... because the code in the page is normally processed top to bottom .. the form has been reset but the values are again assigned.

If it doesnot solve your problem, please provide the whole code.
Regards ...
Reputation Points: 10
Solved Threads: 3
Newbie Poster
sasankasekhar is offline Offline
24 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Please help me
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: deleting sessions on closing browser tab





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC