This week's book giveaway is in the Testing forum.
We're giving away four copies of Practical Unit Testing with TestNG and Mockito and have Tomek Kaczanowski on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes disabling submit button not working Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "disabling submit button not working" Watch "disabling submit button not working" New topic
Author

disabling submit button not working

Soft Music
Greenhorn

Joined: Jan 17, 2002
Posts: 5
Hi All,
I'm calling an external .js file onSubmit to do edit check which returns true if edit check went ok, otherwise returns false if error found in the form.
Now I would like to disable the submit buttons in the same form and send the form data to my servlet (I used post method)once the .js file found no error in the form. But as soon as I disable the submit button, the form data got lost (IE is used, I see a blank screen, and I tried to put break point in the very begining point of the servlet, it did not hit there). What went wrong here?
FYI:
The following is the portion in the jsp file where I call this external .js file:
<FORM name="addcustomer" method="POST" action="/sales/samples/CustomersServlet2"
onSubmit='return verifyForm(this);' >
Here is the portion in the verifyForm(form) function where I tried to disable the submit buttons:
if (!err){
alert("Form has been submitted.");
for(var l=0; l<fm.length; l++){
var elem = fm.elements[l];
if (elem.type.toLowerCase() == "submit")
elem.disabled = true;
}
return true;
}

Please help! Really appreciate!
Soft Music
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Soft Music
Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however, your name is not in keeping with our naming policy here at the ranch. Please re-register under an appropriate name as shown in the policy.
As for disabling the submit button, what you're doing is disabling the button after is has been clicked and the form has already been submitted. If you're trying to prevent the form from being submitted then what you need to do is return false from the verifyFrom method. Then the form doesn't get submited.
hope that helps


Dave
Sarran Vidyakumar
Greenhorn

Joined: Mar 26, 2003
Posts: 28
the reason the form is not getting called could be because the form may be checking for a button click. our case it has been disabled already..
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
Hello Sarran,
You answerd a question that was posted on: January 18, 2002 07:43 AM
I really doubt a person needs an answer right now......
Eric
 
 
subject: disabling submit button not working
 
Threads others viewed
Which submit button was clicked?
Problem with Form Validation.
How to prevent to click multi submit button?
help pls
how to call different java script codes on different button click
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com