Forum Moderators: open
I am trying to do a simple form checker using prototype.
I want, on submit, the user to be asked "are you sure.. y/n? If yes, submit the form, if no, then don't.
I also have a select box in the form and want to pass along the selected values id as a parameter.
Basically, the form is:
<form name="mform" method="post">
<select name="select">
<option name="option1">Option1</option>
<option name="option2">Option2</option>
</select>
</form>
I have something like this so far but I'm nowhere close to what I need:
<script "text/javascript">
Event.observe(window, 'load', function() {
Event.observe('mform', 'submit', function()
{
alert('test')});
});
</script>
Does anybody know how to get this to work?
Thanks in advance :)
Small mistake:
<script [b]type=[/b]"text/javascript">
<form [b]id="mform"[/b] name="mform" method="post">
To give the user the option to abort the form submission you can use a confirm dialog and check the return value:
Event.observe("mform", "submit", function(event){
var response = confirm("Are you sure you want to submit this form?");
if(!response){
event.stop();
}
});
You can access the select box's value with
$('[i]select box id here[/i]').value Andrew
I didn't add in the select box code yet, just the above.
When I add back in the:
Event.observe(window, 'load', function() {
<script type="text/javascript">
Event.observe(window, 'load', function() {
Event.observe("mform", "submit", function(event){
var response = confirm("Are you sure you want to delete?");
if(!response){
event.stop();
}
})
});
</script>