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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form submit only visible elements

Status
Not open for further replies.

cmayo

MIS
Apr 23, 2001
159
US
I have a dynamic form where groups of checkboxes are shown/hidden based on combo boxes' onChange handlers, and would prefer that the state of hidden checkboxes weren't passed along on form submission:

I'd initially thought to walk the form on submission and just un-check hidden checkboxes, i.e.

Code:
for(i=0; i<form.elements.length; i++)
{
  if(form.elements[i].type=="checkbox")
  {
    if (form.elements[i].style.display == "none") {
      form.elements[i].checked = false;
    }
  }
}

But determining the visibility/display property of those form elements seems problematic and my Google chops don't seem to be helping much.

The elements' visibility is set with Javascript:

Code:
document.getElementById('theItemID').style.display = 'none';

OR

document.getElementById('theItemID')style.display = '';

Again, my main objective is not to submit values for hidden form objects. Anyone have any ideas how I can accomplish that, either by negating their values based on visibility or some other means?
 
P.S. That's whether they are visible or not, but if they're not visible, it shouldn't matter.

In fact, if they're not visible, why have them at all if you don't want their values submitted?



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Another thought: thinking on today's bandwith, it's worth doing that work just to avoid a couple of checkboxes travelling?

Cheers,
Dian
 
Wow, thanks much for the replies. Dan, that's a good thought... disabling the elements as I hide them and enabling them as I show them. In some instances, elements should be shown as disabled, but mayhaps I can code those conditions without too much trouble

Dan & Dian, the situation is that this is a site user create/edit form, and I want to hide options which don't apply to the selected user level, i.e., I don't want admin options available for selection when a regular user is being setup or edited.

Naturally, I can (and have, for the moment), filter the post variables based on the type of user... it'd just be easier if variables inappropriate to the user level (which would be hidden at the time of submission) weren't passed along to the form processing code at all, then I only have to control them in one place by hiding/showing the appropriate set of selections on the form.

I think switching the enabled/disabled properties may work for me... thanks much for the suggestions.
 
Now you've explained it, I can't help thinking you're doing this all wrong.

Security for users should NEVER be done purely as client-side code, as it gives far too much away in terms of your behind-the-scenes getup, making it much easier for anyone with malicious intent to attempt to wreak havoc on your system.

I'd go with server-side filtering to not even deliver this content if it's not applicable.

Surely this shouldn't be too hard as all your admin logic, etc, would be server-side anyway, right?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top