View Full Version : Form reset confirm problem

03-18-2004, 01:28 AM
I have a small form where I am using a cofirm on the reset button click. For some reason though, the confirm always acts as true. How can I fix that (I already tried if (confirm()) ). Also, how can you make it so you cancel a button click or event like "reset()" (see the *)?

function CLEARIT() {
var y=confirm('Are you sure you want to clear\?');
if (y='true') {document.g.reset()};
else { * };

03-18-2004, 01:46 AM
<input type="reset" value="Reset" onclick="return confirm('Are you sure you want to clear?');"/>

03-18-2004, 02:10 AM
Yeah, that's the easy way to do it. The reason yours wasn't working is because you just have to put if (y). y is either true or false and the if loop works on whether or not the expression is true, so you don't have to put if (y='true'). The reason that didn't work is because it was assigning the value 'true' to y and there was nothing to be false. You have to use == without quotes around true. And you don't need an else in this case. But yeah just do it the easy way. I was just telling you this for future reference.

03-18-2004, 08:39 PM
Thanks a ton!!:D