Jump to content

Change State With Dropdown


ShoeLace1291

Recommended Posts

So I'm making a member group permissions form.  I have a selection box to set the group's permission level and if "banned" is selected, I want it to hide the permissions checkbox table(contained in a div called "permissions").  In firebug error console, I get a weird error that says "setting a property that has only a getter", which has completely baffled me.  This is the short and sweet code:

 

<option value='4' onclick="document.getElementById('permissions').style = 'display: none;'">Banned</option>

Link to comment
Share on other sites

First, you should not put javascript code directly in an elements event parameter; the event should call a function instead.

 

Specific to your problem though, you should use the onchange event of the select object. The options of a select list do not "officially" have an onclick event. However, each browser manufacturer tweaks the standards to their liking. So what may work in one browser may not work in another. The option objects do have an onchange event, but I would stick to the onchange of the select object.

 

<select name="permission" onchange="hidePermissionTable(this);">
<option value="1">Admin</option>
<option value="2">Moderator</option>
<option value="3">User</option>
<option value="-1">Banned</option>
</select>

 

Then have this function

function hidePermissionTable(this)
{
    var displayVal = (this.options[this.selectedIndex].value==-1) ? 'none' : '';
    document.getElementById('permissions').style.display = displayVal;
    return;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.