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 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2012
    Posts
    33
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Question jQuery code problem

    Code:
    <!DOCTYPE html>
    <html>
    <head>
      <script src="jquery-1.8.3.min.js" type="text/javascript"></script>
      <script type="text/javascript">
      $(document).ready(function(e) {
        $("#myOption").change(function(){
            var textval = $(":selected",this).val();
            $('input[name=student_mark]').val(textval);
    		myTestForm.student_mark.disabled=true; // if selecta value , text feild readonly
        })
    });</script>
    </head>
    <body>
    <form name="myTestForm">
    Selection :<select name="myOption" id="myOption">
        <option value="">===select option===</option>
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
    </select></br>
    Selected value :<input type="text" name="student_mark"  id="student_mark"/>   
      </form> 
    </body>
    </html>

    This code has no errors..this works fine..when I select a option
    then its value automatically set to the text box & text box become read only...that's ok..It's my target..But I have little bit problem when I select a option (One,Two or Three).. If I again select the default value "===select option===" then automatically read only text field is not come normally(means read & write mode)...I want if I select "===select option===" option then text field will be automatically become normal mode....Can any one fix this problem by editing this code...thanxx in advanced.....

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    You can simplify your code because your select is not "multiple".
    Code:
      $(document).ready(function(e) {
        $("#myOption").change(function(){
            var textval = $(this).val();
            $('input[name=student_mark]').val(textval);
            if(textval!="") {
              myTestForm.student_mark.disabled=true; // if selecta value , text field readonly
            } else {
              myTestForm.student_mark.disabled=false; // if not selecta value , text field read/write
            }
        });
    });

  • Users who have thanked devnull69 for this post:

    ebookz (11-21-2012)


  •  

    Posting Permissions

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