Why won't this onsubmit action fire?

K

KathyB

Hi, I have the following submit code:

<form name="finish" action="Hidden_Birth2.aspx" method="post"
onsubmit="return CheckInput(this);">
<input style="CURSOR: HAND" type="submit" name="finish"
value="FINISH"/>
<b>Click the FINISH button when work instruction is complete.</b>
</form>

and here is my CheckInput script:

function CheckInput()
{
var cnAll = document.all;
for (var i=0;i<cnAll.length;i++)
{
if(cnAll(i).tagName=='input' && cnAll(i).type=='text')
{
alert("You must first complete and SAVE all user inputs!");
return false; }
}
}

....seems to work as far as checking for the elements (type=text), but
if it does not return false; the action of the form (loading the aspx
page) doesn't seem to work. I'm working in asp.net, and I just get a
blank page. Since it is in the hmtl and if the js fails, still can't
figure out HOW to find the problem...since it just quits.

Any help appreciated.

Kathy
 
L

Lasse Reichstein Nielsen

<form name="finish" action="Hidden_Birth2.aspx" method="post"
onsubmit="return CheckInput(this);">

You send the form to CheckInput as an argument, but doesn't use it.
<input style="CURSOR: HAND" type="submit" name="finish"
value="FINISH"/>

You appear to use XHTML. I would put a space before the final "/>",
just to not confuze older non-XHTML browsers.

The correct CSS for what you want is "cursor:pointer". The "hand" is
an IE invention. For backwards compatability with IE 4, you can use both,
with "hand" last.
function CheckInput()

function CheckInput(form)

(you pass the form anyway)
{
var cnAll = document.all;
for (var i=0;i<cnAll.length;i++)
{
if(cnAll(i).tagName=='input' && cnAll(i).type=='text')

document.all is a collection, so you might want to use it as such, and
not as a function. I.e., "cnAll" instead of "cnAll(i)".


You want to iterate through all the elements of the page and
find the ones that are input elements with type "text". There
are faster ways to do that (especially if you only check inside
the form):

var inputs = (form.getElementsByTagName?
form.getElementsByTagName("input"):
form.all.tags("input")); // for IE 4

for (var i = 0; i < inputs.length; i++) {
if (inputs.type == "text")

{
alert("You must first complete and SAVE all user inputs!");
return false; }
}
}

...seems to work as far as checking for the elements (type=text), but
if it does not return false; the action of the form (loading the aspx
page) doesn't seem to work. I'm working in asp.net, and I just get a
blank page.

So the form *is* submitted, the asp.net just doesn't give the result
you expected. That probably means that the bug is in the asp code.
Since it is in the hmtl and if the js fails, still can't
figure out HOW to find the problem...since it just quits.

You can try making an asp page that displays the form elements
that are submitted, and set the form to point to that page. Then
you can see what is submitted.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top