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 6 of 6
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Disable a radio button on form submit

    Hello all,

    I have 2 radio buttons
    update bsc value
    update mnr value

    when user selects update mnr value, two more radio buttons should appear.
    I have mnr value
    I do not have mnr value.

    On selecing I do not have mnr value im submitting the form and enabling the user to select values from dropdown. ( not shown in the code as it is a coldfusion code.).

    On submit I am not able to still keep the 'but2', and 'my_select3' elements disabled.

    Please advice. I have been working on this since quite sometime.

    <script language="JavaScript">
    function makeChoice() {
    var obj1 = document.getElementById('box1')
    var obj2 = document.getElementById('box2')
    if (document.getElementById('but1').checked) {
    obj2.setAttribute('readOnly','readonly');
    obj1.removeAttribute('readOnly');
    document.getElementById('but1').disabled=true;
    document.getElementById('but2').disabled=true;
    }
    else if (document.getElementById('but2').checked) {

    obj1.setAttribute('readOnly','readonly');
    obj2.removeAttribute('readOnly');
    document.getElementById('but2').disabled=true;
    document.getElementById('but1').disabled=true;

    }

    }
    </script>

    <script type="text/javascript">
    function showSelect() {

    if (document.getElementById('but2').checked)
    {
    document.getElementById('but2').disabled=true;
    }

    }
    </script>

    <script type="text/javascript">
    function showSelect1() {
    if (document.getElementById('but2').checked)
    {
    document.myform.submit();
    document.getElementById('but2').disabled=true
    document.getElementById('my_select3').disabled=true
    }

    }
    </script>


    <td><input type="radio" id="but1" name="vals" onclick="makeChoice()"></td>
    <td>Update BSC Value </td>

    <tr>
    <td><input type="radio" id="but2" name="vals" onclick="makeChoice();showSelect();" ></td>
    <td>Update MNR Value </td>

    <td> <input id="my_select1" class="show" type="radio" name="my_select1" onclick="this.myform['my_select1'].disabled=true"></td>

    <td> I have a Position Number </td>


    <td><input id="my_select3" class="show" type="radio" name="my_select3" onclick="showSelect1();"></td>

    <td> I do not have a Position Number </td>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Code:
    document.getElementById('but2').disabled=true 
    document.getElementById('my_select3').disabled=true
    document.myform.submit(); 

    Obviously for us to overtake them has been a massive undertaking. - Football manager, ITV 1

    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.

  • #3
    New Coder
    Join Date
    May 2011
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I tried this too, it gets disabled before the form is submitted for a second and when the page reloads the radio buttons have no selection. (they are no disabled). Please advice

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by deepthiz View Post
    I tried this too, it gets disabled before the form is submitted for a second and when the page reloads the radio buttons have no selection. (they are no disabled). Please advice
    When the page reloads it starts over just as though it as loading for the first time. If you want to persist the state of some element you must use a cookie. But why do you want to do that? Are you trying to prevent the user from submitting the form a second time?

    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.

  • #5
    New Coder
    Join Date
    May 2011
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Can you please give me an example of this....so that I can use it in my JS

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Try using the search feature of this forum. Cookies have been covered a zillion times - including today at JavaScript Cookies!

    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.


  •  

    Tags for this Thread

    Posting Permissions

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