Is there a way to do this without building a function
Clark
6:44 pm on Feb 14, 2006 (gmt 0)
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)
<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)
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)
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)
OK, thanks, I'll try it.
Clark
11:22 pm on Mar 1, 2006 (gmt 0)
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?
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)
That would not, however, submit the form if JavaScript is turned off. And, it would fail silently.