PDA

View Full Version : Detect whether form field is HIDDEN or not



hyefive
06-07-2004, 09:10 PM
Hi,

I have a form that passes a field either as a HIDDEN variable or as variable chosen by the user, depending on answers from a previous page.

In validating the form upon submission, I want to ensure the presence of a value for this field (when the user is choosing), but I'm having trouble doing this.

My question:
Is there a way for my form validation script to determine whether this field is being passed as a HIDDEN variable or as one input by the user? Or is there a better way to accomplish this?

Many thanks,
hyefive

sage45
06-07-2004, 10:18 PM
Perhaps a link for us to look at or your code...

-sage-

hyefive
06-07-2004, 11:09 PM
Hi again,

Well this seems to have worked, at least with IE6 & Mozilla....

function CheckForms(f){
validMessage="Please complete the following field(s):\n\n";
dataEntered = new Boolean(true)
if (f.search_tp.hidden){
if (!f.search_tp[0].checked && !f.search_tp[1].checked){
dataEntered = false;
validMessage += "Search Type\n";
}
}
...

Thanks for looking anyways,
Mark
:)

hyefive
06-08-2004, 12:34 AM
No, I take it back. That didn't work after all...

glenngv
06-08-2004, 03:32 AM
Do you mean hidden field like this?

<input type="hidden" ... />

If yes, then this should be the solution:

if (f.search_tp.type=="hidden"){
...
}

But it seems to be a checkbox?

if (!f.search_tp[0].checked && !f.search_tp[1].checked){


Maybe you meant a hidden div or span that contains the checkbox fields.

hyefive
06-08-2004, 05:10 PM
Hey thanks, glenngv!

Yea, that was the form I was referring to. And just for closure, the second scenario is using radio boxes and not checkboxes, as you inferred.

Thanks again.