Forum Moderators: open

Message Too Old, No Replies

Confirming move onsubmit?

Is there a way to do this without building a function

         

Clark

6:44 pm on Feb 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want a submit button that asks you "Are you sure you want to do X" with an OK button and a Cancel button. OK submits the form, Cancel leaves the page as is.

From searching for this it looks like I'd have to build a function that goes into the header. Is there an easy way to include all the javascript within the form only and not build a function?

DrDoc

6:54 pm on Feb 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<form onsubmit="return confirm('Do you really want to do X?');">

[edited by: DrDoc at 7:19 pm (utc) on Feb. 14, 2006]

Clark

7:17 pm on Feb 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks. But unfortunately it popped up an input box where I could enter a value like "yes", then I clicked cancel and it went through anyway.

DrDoc

7:20 pm on Feb 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My bad. I meant to type "confirm" and not "prompt" :)
I updated the code above to reflect the correct message box.

Clark

7:21 pm on Feb 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, thanks, I'll try it.

Clark

11:22 pm on Mar 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there a similar way for a link? Can I just stick that part into the <a href= and will it work across browsers the same way?

edit: That didn't seem to work.

DrDoc

7:01 am on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's no
onsubmit
for links. Try
onclick
though.

prasanth jvrs

12:44 pm on Mar 2, 2006 (gmt 0)

10+ Year Member



Hi,

Hope this code helps.

<form name="form1">
<input type=text name="txt1">
<input type=button onclick="checkSubmit()">
</form>

<script>

function checkSubmit() {
if(document.form1.txt1.value==null) {
alert("Please enter some value");
return false;
}
document.forms[0].submit();
}
</script>

DrDoc

6:31 pm on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That would not, however, submit the form if JavaScript is turned off. And, it would fail silently.