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:

$insert_sql = mysql_query("INSERT INTO ...... ");
if($insert_sql){
        ?>
        <script>
             alert("Query Successful");
             parent.document.forms[0].reset();
        </script>
        <?php
}else{
        ?>
         <script>
             alert("<?php mysql_error($conn);  ?>");
         </script>
         <?php
}

i have tried everything from giving the form an ID and using

document.getElementById('form').reset();

But i still cannot reset the form. What can i do. Please help. Thanks alot.

Recommended Answers

All 2 Replies

Are you getting any javascript errors?

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:

$insert_sql = mysql_query("INSERT INTO ...... ");
if($insert_sql){
        ?>
        <script>
             alert("Query Successful");
             parent.document.forms[0].reset();
        </script>
        <?php
}else{
        ?>
         <script>
             alert("<?php mysql_error($conn);  ?>");
         </script>
         <?php
}

i have tried everything from giving the form an ID and using

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

$insert_sql = mysql_query("INSERT INTO ...... ");
if($insert_sql){
        ?>
        <script>
             alert("Query Successful");
             parent.document.forms[0].reset(); //here you are resetting the form
              ........................
              ........................
         </script>
         <?php
}
<form action=...>
<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 ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.