Forum Moderators: open

Message Too Old, No Replies

Reset button - JS function

         

js_new_bie

3:00 pm on Sep 15, 2005 (gmt 0)

10+ Year Member



Am calling this js function on clicking Reset from the form. A pop up message gets shown asking for confirmation, and if the user clicks yes - go ahead and reset. Else dont reset.

Bug is that even if the user clicks "No" on the pop up message, the form values are getting reset. What do i need to do in the else block?

function whenReset()
{
if(confirm('This will lose your changes, do you want to continue?'))
{
document.customerSurveysListsMaintenanceForm.reset();
}
return false;
}

Any pointers will be appreciated!

Thanks for your time!

ajkimoto

4:56 pm on Sep 15, 2005 (gmt 0)

10+ Year Member



Hi js_new_bie,

First of all:

Welcome to Webmaster World!

Why not change your <input type="reset" />

to a normal button <input type="button" />

and then attach the function to the onclick method of the button?

<script type="text/javascript">
<!--
function checkreset(){
if(confirm('This will lose your changes, do you want to continue?')){
//if click OK, reset the form, otherwise do nothing
document.forms[0].reset()
}
}
//-->
</script>

<style type="text/css">

</style>

</head>

<body>
<form method="post" action="" >
<input type="text" name="txt1" id="txt1" size="30" /><br />
<input type="text" name="txt2" id="txt2" size="30" />
<input type="submit" value="OK" />

<!--This is a normal button, not a reset button//-->
<input type="button" value="Reset" onclick="checkreset()" />

</form>

Hope this helps,

ajkimoto

js_new_bie

8:25 pm on Sep 15, 2005 (gmt 0)

10+ Year Member



Thanks! I did try that option. But that didn't work either. I had to add this code in the else block:

document.forms[0].listName.defaultValue = document.forms[0].listName.value;