How to check for existance of Input elements that are type=TEXT???

K

KathyB

Sorry this is a bit of a repost because I wasn't quite accurate in my
original.

I have an hmtl page with a function to see if there are any input
type=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 text boxes when the user is clicking the
FINISH
button. I have the following which checks for just INPUT, but how to
specify type=text?

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>
 
E

Egbert Beuker

i thought you could also use .type, but you first have to check wether it
isn't null

if (item.type != null)
{
if (item.type == "text")
{
[code goes here]
}
}
 
G

Greg

Sorry this is a bit of a repost because I wasn't quite accurate in my
original.

I have an hmtl page with a function to see if there are any input
type=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 text boxes when the user is clicking the
FINISH
button. I have the following which checks for just INPUT, but how to
specify type=text?

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>

I'm no expert, but I'd think that you could check the type property of
the input objects.

By the way, wouldn't using document.getElementsByTagName('input') to
return the inputs easier than iterating through the all collection?

How does your style sheet change the inputs to text?

Just wondering.

FWIW
 
L

Lasse Reichstein Nielsen

By the way, wouldn't using document.getElementsByTagName('input') to
return the inputs easier than iterating through the all collection?

Absolutely. And more portable.
And even if one wants to use document.all, it is still faster to
use document.all.tags("input").

/L
 
K

Kathy Burke

In my html, there are only a small number (if any) of text inputs
(mostly a procedure document). Each input already has a SAVE box that
runs its own validation and save to the DOM on the server.

So then it is time to click FINISH, I just want to look if there are ANY
text inputs (empty or not). If they are not empty, they haven't been
saved yet to the DOM and the user needs to do it correctly, etc.

My xsl for each reload (after a DOM change/save), looks to see if the
text node exists for that element (measure, data, etc.) and if so, just
renders it as text, not an input box.

I need to use document.all because I never know (scriptwise) what my
input elements are named, they change according to the xml content. So
here I'm simply checking for the EXISTANCE of a text type=text. BTW, I
have other "input" elements so I'm just looking for type=text at this
point.

Thanks for the replies. Being fairly new to js, not sure which way I'm
supposed to go now...from your answers!

Please let me know what you think, now that I hope I've clarified?

:)

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

Forum statistics

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