Click here to Skip to main content
15,886,104 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have textbox in repeater.

so in some condition i want to changes textbox background color.

and my function is below:-
I m pass the textbox id in txtvalue argument from aspx.cs using javascript so how can i change txtbox background color.

C#
function QtyPriUMChanged(PlusCtrl, MinusCtrl, txtValue, PlusVal, MinusVal) {

            if(MinusVal <= txtValue.val() && txtValue.val() <= PlusVal)
            {

              txtValue.style.background = "Red";
            }
            else
            {
                alert("InCorrect");
            }
        }
Posted
Comments
Mohibur Rashid 11-Jun-14 3:32am    
If you are passing id in txtValue variable then first thing you need to do is get the object first. you are creating TypeError.
try either of the process to get input object:
document.getElementById(txtValue);
document.querySelector(txtValue);
document.querySelector("INPUT[ID="+txtValue+"]");
there is more.
Member 10453691 11-Jun-14 4:42am    
what is the output of these line document.querySelector("INPUT[ID="+txtValue+"]");?
Mitesh Gadhiya 11-Jun-14 3:47am    
Code is correct..i think there is a problem in passing Values
Member 10453691 11-Jun-14 4:42am    
No problem in passing value.
Mitesh Gadhiya 11-Jun-14 4:49am    
Are you passing textbox object in parameter txtVal ??

JavaScript
function QtyPriUMChanged(PlusCtrl, MinusCtrl, txtValue, PlusVal, MinusVal) {
 
            if(MinusVal <= document.getElementById(txtValue).value &&      document.getElementById(txtValue).value <= PlusVal)
            {
 
              document.getElementById(txtValue).style.background = "Red";
            }
            else
            {
                alert("InCorrect");
            }
        }



Try this, hope this will work..

Enjoy..:)
 
Share this answer
 
Comments
Member 10453691 11-Jun-14 5:04am    
sory not working because i already pass id in txtvalue
try this.. :)

JavaScript
function QtyPriUMChanged(PlusCtrl, MinusCtrl, txtValue, PlusVal, MinusVal) {
 
            if(MinusVal <= txtValue.val() && txtValue.val() <= PlusVal)
            {
               var Repeater1 = document.getElementById ('<%=RepeaterID.ClientID %>'); 
               var textValue= Repeater1.getElementById ('txtValue');

                textValue.style.backgroundColor = "Red";
            }
            else
            {
                alert("InCorrect");
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900