This topic is locked

Change Text Label Colour

5/31/2010 3:39:37 PM
ASPRunnerPro General questions
J
Jay123 author

Hi!
I am using ASPRunner 6.1.
I would like to ask how to change the text LABEL colour based from the selection made in another field.
For example:

Label 1 (Fruits) is a dropdown selection: Apple, Orange

Label 2 (Cost) will become red (the word Cost, not the amount to be entered) if apple is selected.
Thanks....

A
ann 6/1/2010

Hi,
add <span> tag for the field label in the HTML mode on the Visual Editor tab.

{BEGIN Fruits_label}<span id=Fruits_label>Fruits</span>{END Fruits_label}


Then proceed to the JavaScript Onload Event on the Eventstab. Here is a sample code:

var tName = 'TableName';

var ctrl = Runner.controls.ControlManager.getAt(tName, pageid, 'Fruits');

function func(){

if (ctrl.getValue()=='Apple') {

document.getElementById("Fruits_label").style.color='red';

} else if (ctrl.getValue()=='Orange') {document.getElementById("Fruits_label").style.color='orange';}

}

ctrl.on('change',func);
J
Jay123 author 6/1/2010

Hi Ann,
Thanks a lot for the quick reply.
Questions, though.

  1. Where in the Events tab should I enter the second code (Javascript onload Event)?
  2. The Label that I would like to change the text color is the Cost, not the Fruits. Should it be Cost_Label but the var ctrl will remain as Fruit?
  3. What if the actual label name has a space and '? Example: Employee's Name. How will I declare it?
    Thanks,

    Jay

A
ann 6/2/2010

Jay,
sorry it was my mistake. I haven't noticed that you use ASPRunner 6.1

Here is a correct code to add to the Visual Editor tab in HTML mode (at the end of the page):

<script>

document.forms.editform.value_FieldName.onchange = function()

{

if (document.forms.editform.value_FieldName.value=="Apple")

document.getElementById("Cost_label").style.color='orange';

}

<script>



It doesnt' matter is there any spaces since you use Id of the label.

J
Jay123 author 6/2/2010

Hi Ann,
Thanks again.
I've tried it but it seems like I did it wrong.
The fieldname of my dropdown is RequestType. It has values of New Hire, Transfer, etc.

If the user selects New Hire, I want the label of my other field to change from black to red.

The other field is EmployeeName and the label of this field is Employee's Name.

I want the Employee's Name label to change from black to red if New Hire is selected as RequestType.
Here's the code that I have added in the HTML editor.

====================================================================

<script>

document.forms.editform.value_RequestType.onchange = function()

{

if (document.forms.editform.value_RequestType.value=="New Hire")

document.getElementById("Employee's Name_label").style.color='red';

}

<script>

====================================================================
I also tried
document.getElementById("EmployeeName_label").style.color='red';
but it didn't work either.
Thanks,

Jay

A
ann 6/3/2010

Jay,
the id you've try to change should be the same as you've assigned it before (in HTML mode on the Visual Editor tab):

{BEGIN Fruits_label}<span id=Fruits_label>Fruits</span>{END Fruits_label}