1

I've a checkbox as mentioned below.

<table>
  <tr>
    <td>
         <input type='checkbox' name='testing1' value='testing1' onclick='javascript: testingFunction(this.checked,'testing1');'>
    </td>
    <td>
         <input type='text' name='tesing1_qty' id='testing1_qty' class='inputtext' readonly=''>
    </td>
  </tr>
</table>

I want to enable the textbox once the checkbox is selected.

I've used a function as below.

function testingFunction(checkboxStatus,checkboxValue){ 
     if(checkboxStatus==true){ 
           $("#"+checkboxValue+"_qty").attr('readonly', false);
     }
}

But i'm getting a syntax error. I'm not sure where I go wrong. Please help me on this. Thanks in advance

2
  • what does the syntax error say? Commented Mar 25, 2013 at 20:28
  • This is the error SyntaxError: syntax error [Break On This Error] javascript: testingFunction(this.checked, Commented Mar 25, 2013 at 20:30

2 Answers 2

2

it is your onclick, you are using all single quotes

onclick='javascript: testingFunction(this.checked,'testing1');'

change one of the sets to double quotes

onclick="javascript: testingFunction(this.checked,'testing1');">

I would change other stuff too since you tag this as jquery but I will leave this as is to solve your syntax error

Sign up to request clarification or add additional context in comments.

Comments

0

Is this what you're trying to do?

$('#testing1').click(function() {
  $("#testing1_qty").attr('disabled', !this.checked);
});

I used jquery for this, as you tagged this post as jquery..

Edit: fixed to use this.checked :)

2 Comments

Thanks for your help. I've made mistake in quotes.
np; we all have our days with string interpolation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.