Hello and welcome to our community! Is this your first visit?
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
    Thanked 0 Times in 0 Posts

    Question jQuery code problem

    <!DOCTYPE html>
      <script src="jquery-1.8.3.min.js" type="text/javascript"></script>
      <script type="text/javascript">
      $(document).ready(function(e) {
            var textval = $(":selected",this).val();
    		myTestForm.student_mark.disabled=true; // if selecta value , text feild readonly
    <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>
    Selected value :<input type="text" name="student_mark"  id="student_mark"/>   

    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. #2
    Senior Coder
    Join Date
    Dec 2010
    Thanked 570 Times in 563 Posts
    You can simplify your code because your select is not "multiple".
      $(document).ready(function(e) {
            var textval = $(this).val();
            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

  3. 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