Thank you in advance to anyone who may be able to help. This is my
first attempt at JavaScript, so I apologize if I've done something
blatantly stupid in the below code. Basically, I have a form with 4
checkboxes, a submit button, and a cancel button. When the user
clicks submit, the page should build the URL, and submit the form, as
long as one or more boxes is checked. When the user clicks cancel,
they should be redirected back to the main page. The problem is that
this works in IE, but FireFox and Safari (Which I'm sure aren't as
forgiving) seem to call BOTH methods when cancel is clicked. Please
forgive the <%= %>'s. This is actually part of a JSP, and some values
come from the java.
Any help pointing out things I've done incorrectly will be greatly
appreciated! I'd really like this to work, but I'd also like to
learn, and do it correctly. Thanks again!
<SCRIPT type="text/javascript">
// Validate the form, build the URL, and submit it.
function handleForm(){
// If the user has not selected anything, display a message and don't
continue.
if (document.mainF orm.eAdmin.chec ked == false &&
document.mainFo rm.eEditor.chec ked == false &&
document.mainFo rm.iAdmin.check ed == false &&
document.mainFo rm.iEditor.chec ked == false) {
alert ('Please select at least one role before continuing.');
} else {
// Disable the button so we don't get bonus submits
document.mainFo rm.submitForm.d isabled=true;
// Build an array of chosen roles
var op_requestedApp s = new Array();
if (document.mainF orm.eAdmin.chec ked == true) {
op_requestedApp s.push("TSEA");
}
if (document.mainF orm.eEditor.che cked == true) {
op_requestedApp s.push("TSEE");
}
if (document.mainF orm.iAdmin.chec ked == true) {
op_requestedApp s.push("TSIA");
}
if (document.mainF orm.iEditor.che cked == true) {
op_requestedApp s.push("TSIE");
}
// Compose the URL and submit
document.mainFo rm.action="user/activate.jsp?id =<%= id
%>&op_enduserId =<%= id %>&op_requester Id=<%= req %>&op_requested Apps="
+ op_requestedApp s;
document.mainFo rm.submit();
}
}
// Redirect the user back to the main page.
function cancelForm(){
location.replac e("user/main.jsp");
}
</SCRIPT>
<form name="mainForm" onsubmit="handl eForm();" action=""
method="post">
<input class="input" type="checkbox" title="Access" name="eAdmin"
id="eAdmin" />
<label for="eAdmin">Ex tranet Administrator</label><br />
<input class="input" type="checkbox" title="Access" name="eEditor"
id="eEditor" />
<label for="eEditor">E xtranet Editor</label><br />
<input class="input" type="checkbox" title="Access" name="iAdmin"
id="iAdmin" />
<label for="iAdmin">In tranet Administrator</label><br />
<input class="input" type="checkbox" title="Access" name="iEditor"
id="iEditor" />
<label for="iEditor">I ntranet Editor</label>
<br /><br />
<button name="submitFor m" value="submitFo rm" type="submit">S ubmit</
button>
<button name="cancelFor m" value="cancelFo rm"
onClick="cancel Form();">Cancel </button>
</form>
first attempt at JavaScript, so I apologize if I've done something
blatantly stupid in the below code. Basically, I have a form with 4
checkboxes, a submit button, and a cancel button. When the user
clicks submit, the page should build the URL, and submit the form, as
long as one or more boxes is checked. When the user clicks cancel,
they should be redirected back to the main page. The problem is that
this works in IE, but FireFox and Safari (Which I'm sure aren't as
forgiving) seem to call BOTH methods when cancel is clicked. Please
forgive the <%= %>'s. This is actually part of a JSP, and some values
come from the java.
Any help pointing out things I've done incorrectly will be greatly
appreciated! I'd really like this to work, but I'd also like to
learn, and do it correctly. Thanks again!
<SCRIPT type="text/javascript">
// Validate the form, build the URL, and submit it.
function handleForm(){
// If the user has not selected anything, display a message and don't
continue.
if (document.mainF orm.eAdmin.chec ked == false &&
document.mainFo rm.eEditor.chec ked == false &&
document.mainFo rm.iAdmin.check ed == false &&
document.mainFo rm.iEditor.chec ked == false) {
alert ('Please select at least one role before continuing.');
} else {
// Disable the button so we don't get bonus submits
document.mainFo rm.submitForm.d isabled=true;
// Build an array of chosen roles
var op_requestedApp s = new Array();
if (document.mainF orm.eAdmin.chec ked == true) {
op_requestedApp s.push("TSEA");
}
if (document.mainF orm.eEditor.che cked == true) {
op_requestedApp s.push("TSEE");
}
if (document.mainF orm.iAdmin.chec ked == true) {
op_requestedApp s.push("TSIA");
}
if (document.mainF orm.iEditor.che cked == true) {
op_requestedApp s.push("TSIE");
}
// Compose the URL and submit
document.mainFo rm.action="user/activate.jsp?id =<%= id
%>&op_enduserId =<%= id %>&op_requester Id=<%= req %>&op_requested Apps="
+ op_requestedApp s;
document.mainFo rm.submit();
}
}
// Redirect the user back to the main page.
function cancelForm(){
location.replac e("user/main.jsp");
}
</SCRIPT>
<form name="mainForm" onsubmit="handl eForm();" action=""
method="post">
<input class="input" type="checkbox" title="Access" name="eAdmin"
id="eAdmin" />
<label for="eAdmin">Ex tranet Administrator</label><br />
<input class="input" type="checkbox" title="Access" name="eEditor"
id="eEditor" />
<label for="eEditor">E xtranet Editor</label><br />
<input class="input" type="checkbox" title="Access" name="iAdmin"
id="iAdmin" />
<label for="iAdmin">In tranet Administrator</label><br />
<input class="input" type="checkbox" title="Access" name="iEditor"
id="iEditor" />
<label for="iEditor">I ntranet Editor</label>
<br /><br />
<button name="submitFor m" value="submitFo rm" type="submit">S ubmit</
button>
<button name="cancelFor m" value="cancelFo rm"
onClick="cancel Form();">Cancel </button>
</form>
Comment