Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using java script to validate information inside fieldset

Status
Not open for further replies.

javaarray

Programmer
Feb 10, 2001
17
US
I am trying to use the following java script to validate information inside a <fieldset>

Here is the javascript code:
<code>
<script language=&quot;JavaScript&quot;>
function check_form(form)
{
return_boolean = true;
obj = eval(form);
for(i=0;i<obj.length;i++)
{
alert(obj.length);
field_name = obj.myForm.name.element.name;
alert(field_name);
if (field_name.indexOf(&quot;_ck&quot;) != -1)
{
if (obj.element.value == &quot;&quot;)
{
obj.element.style.backgroundColor = &quot;red&quot;;
return_boolean = false
}
else
{
obj.element.style.backgroundColor = &quot;white&quot;;
}
}
}
return return_boolean;
}
</script>

Here is my simple example I am trying to get to work:

<form name=&quot;myForm&quot; onsubmit=&quot;return check_form(this)&quot;>

<fieldset style=&quot;border:1 solid blue; width:250px;height:100px;&quot;>
<legend align=&quot;left&quot;> CONTACT INFORMATION</legend><BR>
<label for=&quot;firstname&quot;>First Name</label><input type=&quot;text&quot; id=&quot;firstname_ck&quot;>

</SELECT>
</fieldset>
<input type=submit value=&quot;Submit&quot;>
</form>
</code>
Thanks for any help,


 
try this on for size:
<script language=&quot;JavaScript&quot;>
function check_form(form)
{
return_boolean = true;
obj = eval(myForm);
for(i=0;i<obj.length;i++)
{
alert(obj.length);
var field_name = obj.name;
alert(field_name);
if (field_name.indexOf(&quot;_ck&quot;) != -1)
{
if (obj.value == &quot;&quot;)
{
obj.style.backgroundColor = &quot;red&quot;;
return_boolean = false
}
else
{
obj.element.style.backgroundColor = &quot;white&quot;;
}
}
}
return return_boolean;
}
</script>

Here is my simple example I am trying to get to work:

<form name=&quot;myForm&quot; onsubmit=&quot;return check_form(this)&quot;>

<fieldset style=&quot;border:1 solid blue; width:250px;height:100px;&quot; name = &quot;myset&quot;>
<legend align=&quot;left&quot;> CONTACT INFORMATION</legend><BR>
<label for=&quot;firstname&quot;>First Name</label><input type=&quot;text&quot; name=&quot;firstname_ck&quot;>

</SELECT>
</fieldset>
<input type=submit value=&quot;Submit&quot;>
</form> How many software developers does it take to change a light bulb?
None: it works in everyone else’s office, it must work in yours too.
 
forgot that italics thing
<script language=&quot;JavaScript&quot;>
function check_form(form)
{
return_boolean = true;
obj = eval(myForm);
for(c=0;c<obj.length;c++)
{
alert(obj.length);
var field_name = obj[c].name;
alert(field_name);
if (field_name.indexOf(&quot;_ck&quot;) != -1)
{
if (obj[c].value == &quot;&quot;)
{
obj[c].style.backgroundColor = &quot;red&quot;;
return_boolean = false
}
else
{
obj.element.style.backgroundColor = &quot;white&quot;;
}
}
}
return return_boolean;
}
</script>

Here is my simple example I am trying to get to work:

<form name=&quot;myForm&quot; onsubmit=&quot;return check_form(this)&quot;>

<fieldset style=&quot;border:1 solid blue; width:250px;height:100px;&quot; name = &quot;myset&quot;>
<legend align=&quot;left&quot;> CONTACT INFORMATION</legend><BR>
<label for=&quot;firstname&quot;>First Name</label><input type=&quot;text&quot; name=&quot;firstname_ck&quot;>

</SELECT>
</fieldset>
<input type=submit value=&quot;Submit&quot;>
</form> How many software developers does it take to change a light bulb?
None: it works in everyone else’s office, it must work in yours too.
 
grief... one last time i hope.
<script language=&quot;JavaScript&quot;>
function check_form(form)
{
return_boolean = true;
obj = eval(myForm);
for(c=0;c<obj.length;c++)
{
alert(obj.length);
var field_name = obj[c].name;
alert(field_name);
if (field_name.indexOf(&quot;_ck&quot;) != -1)
{
if (obj[c].value == &quot;&quot;)
{
obj[c].style.backgroundColor = &quot;red&quot;;
return_boolean = false
}
else
{
obj[c].style.backgroundColor = &quot;white&quot;;
}
}
}
return return_boolean;
}
</script>
How many software developers does it take to change a light bulb?
None: it works in everyone else’s office, it must work in yours too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top