By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,652 Members | 1,317 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,652 IT Pros & Developers. It's quick & easy.

Reset the form to Null or Reload the page usign reset even after a submit

P: 46
Hi everyone,

This is the scenario:

I have two button - Submit and Reset

Submit is used for validation and after validation is passed it passes it to another form to enter into database.

Bascially the reset works fine if I use it before using the submit button in the form. For instance,if on submit there is some error as the values have not passed a validation. There is a error pop up message shown and the values are retained in the field and Now if I use reset , all the values of the field do not go back to null.

I am new with form validation. I checked online and it said that reset will not clear if we have used submit and we need to use javascript to do it.

So I made reset into a button which onclick event calls the reset() function and clears the form but I am sure that the code is not right as it is not working, I tired putting a alert message in my fucntion to reassue that the function is being called but I think it is not.

Posting my code

[code]

<INPUT id=reset1 name=reset1 type =button value=Reset onClick="reset()">

<Script>
function reset()
{
alert ("all values shall be cleared now");

document.frmUser.name = "" ;
document.frmUser.user = "" ;
document.frmUser.contactNumber = "";
document.frmUser.email = "" ;

}
</Script>

I am not sure if its the best way to do it.

I want the whole form to refresh/ reload everytime reset is clicked and all the fields to have no values.

Thanks for the help in advance.

Sree
Jul 5 '07 #1
Share this Question
Share on Google+
16 Replies


epots9
Expert 100+
P: 1,351
i might have heard about this, or maybe its somethings else but..

what language are u using to write the webpage? HTML, PHP, ASP.NET?
Jul 5 '07 #2

P: 46
i might have heard about this, or maybe its somethings else but..

what language are u using to write the webpage? HTML, PHP, ASP.NET?
I am using ASP page. Its just I want to set all the field values to null when we click reset. Javascript tutorials mention usign reset value but my IE browser says, does not support this object. So I may have to set all the values back to null??? I am nto sure, actually confused :D
Jul 5 '07 #3

kovik
Expert 100+
P: 1,044
Just like forms have a submit() function, they have a reset() function. You don't have to make your own.

Expand|Select|Wrap|Line Numbers
  1. <input type="submit" value="Submit" />
  2. <input type="reset" value="Reset" />
Jul 5 '07 #4

P: 46
@ volectrcity

We have a reset but if the form is called back after failure in validation i.e. once a submit event has happened, the reset button does not clear the form rather, it sets it with the values that were entered before.

Thats why I have to do it with javascript
Jul 5 '07 #5

epots9
Expert 100+
P: 1,351
if your using visual studio for your ASP page, right click the reset button and go to properties. then in there there should be an option for performsubmit, set that to false, and another option to use validator controls set that to false as well

good luck
Jul 5 '07 #6

P: 46
if your using visual studio for your ASP page, right click the reset button and go to properties. then in there there should be an option for performsubmit, set that to false, and another option to use validator controls set that to false as well

good luck
Thanks epots and velo.

I have solved how to set all the values to null but I think I would rather want to reload/ refersh the whole page but there is a hidden type whoes values MUSt be taken from the comign form and I am stuck as to how to pass this value along with reload event in javascript.

Can anyone help?

My code is:

[js]

function reset_page()

{
document.location.reload();
}

I am getting error saying: The page can not be refreshed without resending the information. click retry to sent the information again, or click Cancel to return to the page that you were trying to view.

Can I anyone say how can I reload/refresh my page by passing the hidden values.

Thanks for your efforts.
Sree
Jul 5 '07 #7

gits
Expert Mod 5K+
P: 5,368
[code]

<INPUT id=reset1 name=reset1 type =button value=Reset onClick="reset()">

<Script>
function reset()
{
alert ("all values shall be cleared now");

document.frmUser.name = "" ;
document.frmUser.user = "" ;
document.frmUser.contactNumber = "";
document.frmUser.email = "" ;

}
</Script>
hi ...

you have to set the value-property so add .value to the lines ... when you want to set a value of an input-field

kind regards
Jul 6 '07 #8

P: 46
hi ...

you have to set the value-property so add .value to the lines ... when you want to set a value of an input-field

kind regards
Thanks gits,

Can you help with reloading a page with parameters passed as being passed by the previous page?
Jul 6 '07 #9

P: 46
I would be of great help if someone can tell mehow to reload/ refersh the page I am in currently but I need to be able to pass a hidden parameter whoes values MUST be taken as if coming from the next page and I am stuck as to how to pass this value along with reload event in javascript.

Can anyone help?

My code is:

[js]

function reset_page()

{
document.location.reload();
}

I am getting error saying: The page can not be refreshed without resending the information. click retry to sent the information again, or click Cancel to return to the page that you were trying to view.

Can I anyone say how can I reload/refresh my page by passing the hidden values.

Thanks in advance.
Sree
Jul 6 '07 #10

P: 46
Thanks gits,

Can you help with reloading a page with parameters passed as being passed by the previous page?
Hi Solved my problem.

I figured out. My solution code is:

Expand|Select|Wrap|Line Numbers
  1. function reset_page()
  2. {
  3. document.location.reload("location?type=<%=USER_TYPE%>");
  4. }
  5.  
  6.  
[html]
<INPUT type=button value=Reset onClick = “reset_page()”>
[/html]

Thanks for all help and support.
Sree
Jul 6 '07 #11

P: 46
I would be of great help if someone can tell mehow to reload/ refersh the page I am in currently but I need to be able to pass a hidden parameter whoes values MUST be taken as if coming from the next page and I am stuck as to how to pass this value along with reload event in javascript.

Can anyone help?

My code is:

[js]

function reset_page()

{
document.location.reload();
}

I am getting error saying: The page can not be refreshed without resending the information. click retry to sent the information again, or click Cancel to return to the page that you were trying to view.

Can I anyone say how can I reload/refresh my page by passing the hidden values.

Thanks in advance.
Sree
Hi Solved my problem.

I figured out. My solution code is:

[js]
function reset_page()
{
document.location.reload("location?type=<%=USER_TY PE%>");
}

[/js]

[html]
<INPUT type=button value=Reset onClick = “reset_page()”>
[/html]

Thanks for all help and support.
Sree
Jul 6 '07 #12

dafodil
100+
P: 392
Anytime.... anytime....
Jul 6 '07 #13

gits
Expert Mod 5K+
P: 5,368
... glad you got it working ... and that you find the solution for yourself ;) ... come back when you have more questions ...

kind regards
Jul 6 '07 #14

acoder
Expert Mod 15k+
P: 16,027
Merged the threads.
Jul 6 '07 #15

acoder
Expert Mod 15k+
P: 16,027
[js]
function reset_page()
{
document.location.reload("location?type=<%=USER_TY PE%>");
}

[/js]
Sree, it's good that you got your problem solved. Just one thing about the code tags. [js] won't work. Use [code=javascript] with the ending code tag. Thanks.
Jul 6 '07 #16

P: 46
Sree, it's good that you got your problem solved. Just one thing about the code tags. [js] won't work. Use [code=javascript] with the ending code tag. Thanks.

Thanks a lot. Yes, sure will rem that the next time.

Cheers
Sree
Jul 6 '07 #17

Post your reply

Sign in to post your reply or Sign up for a free account.