Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-21-2012, 11:50 AM   PM User | #1
ebookz
New Coder

 
Join Date: Nov 2012
Posts: 33
Thanks: 23
Thanked 0 Times in 0 Posts
ebookz is an unknown quantity at this point
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.....
ebookz is offline   Reply With Quote
Old 11-21-2012, 12:50 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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
        }
    });
});
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
ebookz (11-21-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:23 AM.


Advertisement
Log in to turn off these ads.