Javascript -- confused on the return false -- simple validate function?

K

KathyB

Hi.

I have an hmtl page with a function to see if there are any input text
boxes. If so, that means a user did not complete them (once entered,
my xsl stylesheet makes them text instead of text input boxes, so
there should be NO input boxes when the user is clicking the FINISH
button. However, the FINISH button script still indicates that input
boxes exist...new to this...return false issue? Is there a better way
to do this? I also need to send a querystring or form collection for
(hidden_birth2.aspx?finish=yes). I couldn't get the script right to
open the page with querystring from the function, so I ended up doing
it with this <form> element...probably not the best way. Any help
appreciated! Thanks. Kathy

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

HTML snippet:

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

Chris Leonard

HTML snippet:

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

I think you need the capital S for it to work ......... but I could be wrong

onSubmit="return validate();"
 
L

Lasse Reichstein Nielsen

Chris Leonard said:
I think you need the capital S for it to work ......... but I could be wrong

onSubmit="return validate();"

You are wrong.
In HTML, the case of the letters doesn't matter.
In XHTML, and in Javascript, the on<event> handlers are written in
all lower case.

/L
 
A

asdf asdf

Are you sure your for loop isn't detecting the "input type submit" ?

Might be worth checking the cnAll(i).type as well.

Also, I think your event handler might need to return true.

Hope that helps,
Ron
 
K

Kathy Burke

Ugh, just realized that I should have other input boxes just not
type=TEXT boxes...could someone help me with testing for input elements
where type=TEXT?

Thanks!

Kathy
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top