Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: Form help

  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Form help

    Hi guys

    I have a select "combobox" that when you click on an option from the list it submits the value, which is what i want it to do. But I would also like to have the select "combobox" become disabled or greyed out after an option is selected. I can get these to work seperatly but not together. Is it possible to have 2 onchange events in one form?


    here is what i am working with:
    Code:
    <script type="text/javascript">
    function makeDisable(){
        var x=document.getElementById("filter11")
        x.disabled=true
    }
    </script>
    
    <td><Select name='filter11' id="filter11" onChange="filters.submit();" onchange="makeDisable()">
    <option value=''>Months (Any)</option>
    blah blah
    </select>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Despite the similar sounding names, Java is not the same as Javascript.
    Moving from Java forum to Javascript forum.

  • #3
    New Coder
    Join Date
    May 2011
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Apologies...

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Just call both functions from the *SINGLE* onchange.

    Code:
    <Select name='filter11' id="filter11" onChange="filters.submit();makeDisable()">
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    May 2011
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi Old pendant.

    Yeah I did try that, it submits the form ok, but it only disables the form for 1 second... I have the form submiting to the same page.(index.php) Should that matter?

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Oh...once you submit the <form>, the server *RELOADS* the ENTIRE PAGE. So any changes you make via JavaScript will be completely lost in the re-loaded page.

    You will need to take care of this in you server-side code. That is, if this is a PHP page, use PHP code to detect that the <select> has been used and disable it via PHP. (Or ASP or JSP or whatever.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    amg182 (08-25-2011)

  • #7
    New Coder
    Join Date
    May 2011
    Posts
    17
    Thanks
    3
    Thanked 0 Times in 0 Posts
    ah, I see. That makes sense!

    Will have a go with the php script!

    Thanks

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Or you could use a Javascript cookie.


    Quote Originally Posted by amg182 View Post
    But I would also like to have the select "combobox" become disabled or greyed out after an option is selected.
    Why? That means that the user cannot change his mind. Surely a user-hostile approach!
    Last edited by Philip M; 08-26-2011 at 08:06 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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