Question : Javascript to control the colour of a Label in an aspx screen for data entry

This is the javascript code that returns the error.  The applications is a web based interface to a SQL server database. (IE only).  I am attempting to set the colour of a field label.

var controlLabel = "lblknowledgelevel";
controlLabel.style.color = 'red';

These are the only two lines and "lblknowledgelevel" is the name of the label control on the screen

Once I can get this to work - I want to insert into the code in the code snippet so that if the alert box is called then the label color is set to red (so the user knows where the error is)
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
This code is an example of code that works in this application
var controlKL = "Knowledgelevel";
var Dave = $id("btnSave");
var getvalueKnowledgelevel;
// remember old save button behaviour
var oldClick = Dave[0].getAttribute("onclick");
// define new save button behaviour
var validaterecord = function()
{
            // Get Current Screen Values
            getvalueKnowledgelevel = $HRnet(controlKL).getDisplayValue();
            // Do Validation
            if ((getvalueKnowledgelevel == "" || getvalueKnowledgelevel == " "))
                    {             alert ("You may not Save a Qualification Record without first stating the Level of the Qualification")
                                   return false;
                    }
                      else      {oldClick();}       
}
Dave[0].onclick = validaterecord;
Open in New Window Select All

Answer : Javascript to control the colour of a Label in an aspx screen for data entry

Solution follows
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
var controlKL = "Knowledgelevel";
var Dave = $id("btnSave");
var getvalueKnowledgelevel;
// remember old save button behaviour
var oldClick = Dave[0].getAttribute("onclick");
// define new save button behaviour
var validaterecord = function()
{
            // Get Current Screen Values
            getvalueKnowledgelevel = $HRnet(controlKL).getDisplayValue();
            // set lable red
           // $HRnet(lbl).style.color="red";
            // Do Validation
            if ((getvalueKnowledgelevel == "" || getvalueKnowledgelevel == " "))
                    {             alert ("You may not Save a Qualification Record without first stating the Level of the Qualification")
            //Find the label of the KnowledgeLevelfield and turn it into Red and Bold
                           document.getElementById("lblknowledgelevel").style.color = "red";
                           document.getElementById("lblknowledgelevel").style.fontWeight = "bold";
                                   return false;
 
                    }
                      else      {oldClick();}       
}
Dave[0].onclick = validaterecord;
Open in New Window Select All
Random Solutions  
 
programming4us programming4us