1

I have an input on a form where I am displaying an amount owed. Basically if the amount owed is zero, I add a special class called "paid" and I can $(".paid") using jquery. All of this is working well.

The question is, how do I prevent users form clicking or entering text or doing anything else with these inputs ?

This is my finction so far.

function disablepaid(){ $(".paid").on("click", function(){ alert("Do disabling stuff now"); }); } 

In some other posts I saw people trying jquery blur(), and seting the disabled attribute as seen here How do i grey out the input field and the submit button

Please advise, thanks.

3
  • 1
    The answer is to set the disabled property to true. Commented Nov 15, 2012 at 14:49
  • why dont you show this by ajax ...like if condition match only than show the fild since i can disable js Commented Nov 15, 2012 at 14:49
  • @NullPointer - surely if you disable the js then the ajax call wouldn't work either..?... Commented Nov 15, 2012 at 14:52

3 Answers 3

2

you can set the disabled attribute on the input..

something like:

 function disablepaid(){ $(".paid").on("click", function(){ alert("Do disabling stuff now"); $(this).prop('disabled', true); }); } 

If at any time you need to renable it then:

 $(".paid").prop('disabled', false); 

Update

Also, rather than allowing the user to click on the paid input field and THEN disabling it, why not disable it when you set the zero amount?

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

2 Comments

Thanks man, I preferred this as I am using the newest jquery version
@Binaryrespawn, you're welcome. Once you get to grips with the library you'll be amazed at what you can do with little code :)
1

Just use prop() and set the disabled property to true

$(".paid").on("click", function(){ $(this).prop('disabled', true); // or this.disabled = true; }); 

2 Comments

Or just this.disabled = true;
@Pointy - yea i just added that
0

You can disable your input

$(".paid").attr("disabled", "disabled"); 

1 Comment

Better to just use this.disabled = true; in the "click" handler. Using .attr() like that has been sort-of wrong since jQuery 1.6.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.