SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    googlicious graymatter bvarvel's Avatar
    Join Date
    Sep 2002
    Location
    Katy, TX
    Posts
    956
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Control with Dropdown

    I have the following code:

    PHP Code:
    onchange="p_complete.disabled=!(this.selectedIndex==2)" 
    Which disables form element 'p_complete' is the third option is selected from this drop down. What I need to do is disable that element if the first, second or third option is selected.

    Meaning something like:

    PHP Code:
    onchange="p_complete.disabled=!(this.selectedIndex==0 or this.selectedIndex==1 or this.selectedIndex==2)" 
    ...but of course, obviously this doesn't work or I wouldn't be posting here.

    Does anyone have an answer?

  2. #2
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bvarvel
    What I need to do is disable that element if the first, second or third option is selected.
    Try this:
    HTML Code:
    <html>
    <head>
    <title>Disable Select</title>
    <script type="text/javascript">
    function disableEm(el)
    {
    	switch(el.options[el.selectedIndex])
    	{
    		case (el.options[0]):
    		case (el.options[1]):
    		case (el.options[2]):
    			el.disabled = true;
    		break;
    	}
    }
    </script>
    </head>
    <body>
    <form>
    <select onchange="disableEm(this)">
    <option name="p_1">option #1</option>
    <option name="p_2">option #2</option>
    <option name="p_3">option #3</option>
    <option name="p_4">option #4</option>
    <option name="p_5">option #5</option>
    </select>
    </form>
    </body>
    </html>
    Last edited by xDev; Nov 19, 2003 at 12:44.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •