473,388 Members | 873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Method being called on wrong button in FireFox

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.mainForm.eAdmin.checked == false &&
document.mainForm.eEditor.checked == false &&
document.mainForm.iAdmin.checked == false &&
document.mainForm.iEditor.checked == false) {
alert ('Please select at least one role before continuing.');

} else {
// Disable the button so we don't get bonus submits
document.mainForm.submitForm.disabled=true;
// Build an array of chosen roles
var op_requestedApps = new Array();
if (document.mainForm.eAdmin.checked == true) {
op_requestedApps.push("TSEA");
}
if (document.mainForm.eEditor.checked == true) {
op_requestedApps.push("TSEE");
}
if (document.mainForm.iAdmin.checked == true) {
op_requestedApps.push("TSIA");
}
if (document.mainForm.iEditor.checked == true) {
op_requestedApps.push("TSIE");
}

// Compose the URL and submit
document.mainForm.action="user/activate.jsp?id=<%= id
%>&op_enduserId=<%= id %>&op_requesterId=<%= req %>&op_requestedApps="
+ op_requestedApps;
document.mainForm.submit();
}
}

// Redirect the user back to the main page.
function cancelForm(){
location.replace("user/main.jsp");
}
</SCRIPT>

<form name="mainForm" onsubmit="handleForm();" action=""
method="post">
<input class="input" type="checkbox" title="Access" name="eAdmin"
id="eAdmin" />
<label for="eAdmin">Extranet Administrator</label><br />
<input class="input" type="checkbox" title="Access" name="eEditor"
id="eEditor" />
<label for="eEditor">Extranet Editor</label><br />

<input class="input" type="checkbox" title="Access" name="iAdmin"
id="iAdmin" />
<label for="iAdmin">Intranet Administrator</label><br />

<input class="input" type="checkbox" title="Access" name="iEditor"
id="iEditor" />
<label for="iEditor">Intranet Editor</label>

<br /><br />
<button name="submitForm" value="submitForm" type="submit">Submit</
button>
<button name="cancelForm" value="cancelForm"
onClick="cancelForm();">Cancel</button>
</form>
Aug 5 '08 #1
2 1783
On Aug 5, 2:08*pm, TheSouthLondonSlasher <bigdave.sm...@gmail.com>
wrote:
>
* * * * * * * * * * * * <button name="submitForm" value="submitForm" type="submit">Submit</
button>
* * * * * * * * * * * * <button name="cancelForm" value="cancelForm"
onClick="cancelForm();">Cancel</button>
* * * * * * * * </form>
Hello.

The following is from here: http://www.w3schools.com/tags/tag_button.asp

------
HTML <buttontag

Definition and Usage

Defines a push button. Inside a button element you can put content,
like text or images. This is the difference between this element and
buttons created with the input element.

Important: Be careful when using the button element in a form. In a
form the different browsers will submit different values. Internet
Explorer will submit the text between the <buttonand </buttontags,
while other browsers will send the content of the value attribute.
When in a form, use the input element instead.

Note: The type attribute should always be specified. The default
button type for Internet Explorer is "button", while in other browsers
(and the W3C specification) it is "submit".

------

In particular, notice the last sentence above. ^
Aug 5 '08 #2
On Aug 5, 5:34*pm, Doug Gunnoe <douggun...@gmail.comwrote:
On Aug 5, 2:08*pm, TheSouthLondonSlasher <bigdave.sm...@gmail.com>
wrote:
* * * * * * * * * * * * <button name="submitForm" value="submitForm" type="submit">Submit</
button>
* * * * * * * * * * * * <button name="cancelForm" value="cancelForm"
onClick="cancelForm();">Cancel</button>
* * * * * * * * </form>

Hello.

The following is from here:http://www.w3schools.com/tags/tag_button.asp

------
HTML <buttontag

Definition and Usage

Defines a push button. Inside a button element you can put content,
like text or images. This is the difference between this element and
buttons created with the input element.

Important: Be careful when using the button element in a form. In a
form the different browsers will submit different values. Internet
Explorer will submit the text between the <buttonand </buttontags,
while other browsers will send the content of the value attribute.
When in a form, use the input element instead.

Note: The type attribute should always be specified. The default
button type for Internet Explorer is "button", while in other browsers
(and the W3C specification) it is "submit".

------

In particular, notice the last sentence above. ^
Doug,

Thank you so much for your help. Going back and looking at some
examples, I now see the error of my ways. I was afraid it was
something so simple :)

If there are any other anomalies in the code I presented, please let
me know, and thanks again!
Aug 5 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vinita Sharma | last post by:
Hi All, I have a strange problem. I have 2 text boxes and a button in my form. There is a function called on onchange event of the first text box. There is another function called on onclick...
3
by: Arulraja | last post by:
Hello, I have created 2 custom server controls, The parent custom control contains multiple child custom controls. The Child control has a button on it. If I Click the button control, it...
15
by: Patrick.O.Ige | last post by:
Hi All i'm getting error with my TreeView Menu(I want to have a button with ExpandALL and CollapseALL):- Error:- 'AddressOf' operand must be the name of a method; no parentheses are needed. I...
3
by: paulgor | last post by:
Hi, May be it's a know issue but my search brought nothing... We have static HTML files with Japanese text in UTF-8 encoding - it's on-line Help for our application, so there are no Web...
11
by: osmarjunior | last post by:
I have a sequence of commands like this: Form1 frm = new Form1(); frm.LoadData(); Boolean confirm = (frm.ShowDialog() == DialogResult.OK); The LoadData method loads information from...
0
by: Erik | last post by:
Why isn't my update method getting called? Pasted below is an aspx from a 1.1 application I'm working on. It has two textboxes and a button for inserting data into the database, and a datagrid...
5
by: Earl | last post by:
I need to call a method on an owned child form, and am wondering if the best way of doing this is to capture the Closing event of the form that passes control back to the form where I have the...
1
by: Charlie | last post by:
I am trying to make an XMLHttpRequest which violates the default "same- origin"policy in Firefox. I checked the archives and found a method that should work but it does not. Below is the test code...
0
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, Our asp programs seem to have different behaviors when users use IE and firefox. One of most annoying things is the data disappearing problem in IE but not in firefox.(Note: Sometimes a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.