...

View Full Version : Can you void and null an ID in a form?



jcdevelopment
08-05-2008, 05:37 PM
I have a script that validates all elements in the form. It makes sure all Inputs have some kind of content



function validate_form ( )
{
var valid = true;
var f = document.erod;
for( var i=0; i < f.elements.length; ++i)
{
if( String(f.elements[i].type).toLowerCase()=="text" && f.elements[i].value=="" && f.elements[i].name != "nom_title")

{
alert ( "Please fill in the necassary box." );
f.elements[i].style.color="#ff0000";
valid = false;
}
}
return valid;
}


What i need is for it to not even check a section. It has about 10 radio buttons and its not necassary to fill this out.

The ID inside the form that i need overlooked is "where_seen"

If you need my HTML then let me know.

Thanks for any help in the right direction.

ninnypants
08-05-2008, 06:04 PM
What if you just appended another if statement in? or something similar


function validate_form ( )
{
var valid = true;
var f = document.erod;
for( var i=0; i < f.elements.length; ++i)
{
if(!f.elements[i].id == 'where_seen')
{
if( String(f.elements[i].type).toLowerCase()=="text" && f.elements[i].value=="" && f.elements[i].name != "nom_title")

{
alert ( "Please fill in the necassary box." );
f.elements[i].style.color="#ff0000";
valid = false;
}
}
}
return valid;
}

jcdevelopment
08-05-2008, 06:05 PM
well, i was able to make a work around, but i was hoping there was an easier way to di it rather than this way. I just made the validation not include the radio buttons and the input in that ID



function validate_form ( )
{
var valid = true;
var f = document.erod;
for( var i=0; i < f.elements.length; ++i)
{
if( String(f.elements[i].type).toLowerCase()=="text" && f.elements[i].value=="" && f.elements[i].name != "nom_title" && f.elements[i].type != "radio" && f.elements[i].name != "tv_text")

{
alert ( "Please fill in the necassary box." );
f.elements[i].style.color="#ff20000";
valid = false;
}
}
return valid;
}


is there an easier way?

EDIT** haha ninnypants thats what i came up with, is there an easier way?

ninnypants
08-05-2008, 06:08 PM
well, i was able to make a work around, but i was hoping there was an easier way to di it rather than this way. I just made the validation not include the radio buttons and the input in that ID



function validate_form ( )
{
var valid = true;
var f = document.erod;
for( var i=0; i < f.elements.length; ++i)
{
if( String(f.elements[i].type).toLowerCase()=="text" && f.elements[i].value=="" && f.elements[i].name != "nom_title" && f.elements[i].type != "radio" && f.elements[i].name != "tv_text")

{
alert ( "Please fill in the necassary box." );
f.elements[i].style.color="#ff20000";
valid = false;
}
}
return valid;
}


is there an easier way?

EDIT** haha ninnypants thats what i came up with, is there an easier way?

Only what you did here as far as I know.

jcdevelopment
08-05-2008, 06:10 PM
ok, well it works.. i suppose it will do. thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum