SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Non-Member
    Join Date
    Jan 2003
    Posts
    866
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Limiting submit for option list

    How do I disable the submit option for the first element of an option list? I have seen it done via JS but I can't seem to get it to work.

    I have tried:
    <option selected value="javascript:void(0)">

    Which works on another site I was looking at, but not at my site. I am guessing a function needs to be defined?

    I dunno. Techmonkey=JS dummie.

    Thanks in advance for help!

  2. #2
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when do you want to disable it? when someone changes the dropdown or when the page first loads? or both?

  3. #3
    Non-Member
    Join Date
    Jan 2003
    Posts
    866
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <select name="fmCategory" onchange="javascript: document.fm.submit();">
    <option value="javascript:void(0)" selected>Please select from the following
    <option value="0">All vinyls
    <option value='3'>3M
    <option value='1'>ARLON
    <option value='2'>GERBER SCIENTIFIC PRODUCTS
    </select>

    As you can see the first item in the list "Please select from the following" is not meant to be a choice that returns results. It is not possible to choose the first option when the page first loads, but if you choose another option, then hit the back button on your browser, you can select "Please select from the following" and the form calls the script, returning an empty set.

    I want to make it so that when someone hits back on their browser, and chooses this first option, the form is not submitted. I've seen it done.

  4. #4
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So you want it so that if somebody selects any option other than the first one then the page submits? If so, I think this will work:

    Code:
    <script language="javascript">
    function submitIt(ref) {
      if(!ref.selectedIndex == 0) {
        document.frmTest.submit();
      }
    }
    </script>
    
    <form name="frmTest">
    <select name="fmCategory" onchange="submitIt(this)">
    <option value="0" selected>Please select from the following</option>
    <option value="1">All vinyls</option>
    <option value="2">3M</option>
    <option value="3">ARLON</option>
    <option value="4">GERBER SCIENTIFIC PRODUCTS</option>
    </select>
    </form>
    You might want to clean up your html a little bit. Hope that helps.
    Last edited by makeda; Jan 23, 2003 at 08:33.


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
  •