...

View Full Version : check a form with an idea and no name



rewben
08-21-2002, 10:28 AM
hi.

I got a XHTML 1.1 file and i want to post with it, and check if certain inputs are filled in or not, that worked fine with this code :

<!--
function checkformulier(veld)
{
loopdoor = false;
while (true)
{
if (form1.naam.value== null || form1.naam.value=="" || form1.naam.value== form1.naam.defaultValue)
{
form1.naam.select();
form1.naam.focus();
break;
}
if (form1.message.value== null || form1.message.value=="" || form1.message.value== form1.message.defaultValue)
{
form1.message.focus();
form1.message.select();
break;
}
loopdoor = true;
break;
}
if (loopdoor) {document.form1.submit()}
}
//-->
GO TO THE LINK BELOW TO SEE THE FULL CODE

but that worked when you use <form name="form1"> and i because i write xhtml i have to use <form id="form1"> and i have tried it with document.formID.elementname.value== null but thats not working. So does anybody know how to check a form with an idea and no name?

check it out at http://www.generation.nl/~rewben/jn/

glenngv
08-21-2002, 11:17 AM
if you are using that function in many pages, you can make it generic by using document.forms[0] if you have only one form tag in a page.
so to access a field, use:
document.forms[0].naam.value

rewben
08-21-2002, 12:00 PM
Originally posted by glenngv
if you are using that function in many pages, you can make it generic by using document.forms[0] if you have only one form tag in a page.
so to access a field, use:
document.forms[0].naam.value

this is what i tried :

<!--
function checkform(veld)
{
loopdoor = false;
while (true)
{
if (document.forms[0].naam.value == null || document.forms[0].naam.value=="" || document.forms[0].naam.value == form[0].naam.defaultValue)
{
form1.naam.select();
form1.naam.focus();
break;
}
if (document.forms[0].comment.value == null || document.forms[0].comment.value == "" || document.forms[0].comment.value == forms[0].comment.defaultValue)
{
forms[0].comment.focus();
forms[0].comment.select();
break;
}
loopdoor = true;
break;
}
if (loopdoor) {document.forms[0].submit()}
}

//-->

but didnt work, i can give the form an id though, so maybe somehow use getelementbyID ? But i dont know how to write my code then, i tried, but it wasnt working, but i think it was me

glenngv
08-22-2002, 04:25 AM
but you didn't change all and you use shortcut (forms[0]) in some lines.
here is the modified code:

function checkform(veld)
{
objForm = document.forms[0];
loopdoor = false;
while (true)
{
if (objForm.naam.value=="" || objForm.naam.value == objForm.naam.defaultValue)
{
objForm.naam.select();
objForm.naam.focus();
break;
}
if (objForm.comment.value == "" || objForm.comment.value == objForm.comment.defaultValue)
{
objForm.comment.focus();
objForm.comment.select();
break;
}
loopdoor = true;
break;
}
if (loopdoor) {objForm.submit()}
}

the value of a textbox will never be null, so i removed the condition.
btw, why do you have veld parameter in checkform() function but you are not using it inside the function?

rewben
08-22-2002, 10:49 AM
wow, thanks!

it worked fine :)

if you ever need some help with something just let me know.


rewben@generation.nl
http://www.generation.nl/~rewben/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum