DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   javascript form help (http://www.daniweb.com/forums/thread157075.html)

realnsleo Nov 13th, 2008 7:16 am
javascript form help
 
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.

Drew Nov 19th, 2008 7:43 pm
Re: javascript form help
 
Are you getting any javascript errors?

sasankasekhar Nov 22nd, 2008 2:29 am
Re: javascript form help
 
Quote:

Originally Posted by realnsleo (Post 735010)
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 ...


All times are GMT -4. The time now is 9:25 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC