JavaScript Function Problem [from onSubmit]
Posted: Fri Feb 17, 2006 9:44 am
Another JS prob...
My function:
How I call it:
If the user clicks Cancel, I do NOT want the page to submit. If the user clicks OK, the page should submit, but the page is submitting on Cancel aswell as on OK.
I though this would work because the below code only submits the form if the user clicks OK, not when the user clicks Cancel:
Have I made a very simple error that someone can point out for me?
Thanks
My function:
Code: Select all
//Define a function to alert the user of cross entered details if necessary
function cross_entry() {
//If the user has chosen to use an existing make but has entered something in the new make box *OR*
//If the user has chosen to add a new make but has chosen an existing make from the selection box
if ((document.getElementById('makechoice').value == 'existing' && document.getElementById('newmake').value != '') ||
(document.getElementById('makechoice').value == 'addnew' && document.getElementById('make').value != 'none')) {
//Show a confirmation alert
return confirm("You have cross-entered make details.\n\nAre you sure you want to use the details corresponding to the radio button choice?");
}
}Code: Select all
<form action="<?php echo basename(__FILE__); ?>" method="post" enctype="multipart/form-data" onSubmit="javascript: cross_entry();">I though this would work because the below code only submits the form if the user clicks OK, not when the user clicks Cancel:
Code: Select all
<form name="editrecord" action="' . basename(__FILE__) . '" method="post" onsubmit="return confirm(\'Are you sure?\');">Thanks