www.webdeveloper.com
Results 1 to 5 of 5

Thread: Please help!Color does'nt change.

  1. #1
    Join Date
    Oct 2011
    Posts
    7

    Please help!Color does'nt change.

    I've tried this,when the user enters a value in a textbox,the color of the DayTotalkWh readings should change automatically.Please help me I don't get this!.Instead, the whole text color changes.

    Here is the code:

    <HTML>
    <HEAD>
    </TITLE>Daily Meter Readings </TITLE>
    <script type="text/javascript">
    var Readme = document.getElementsByTagName(Readme);
    this.Readme;

    function ChangeTextColor(value)
    {
    if(value > 40)
    {
    document.fgColor="red";
    this.focus();
    }
    else if(value < 40)
    {
    document.fgColor="green";
    this.focus();

    }
    else
    {
    document.fgColor="amber";
    this.focus();

    }
    }


    </script>

    </HEAD>
    <BODY bgcolor="pink">
    <OBJECT CLASSID = "clsid:333C7BC4-460F-11D0-BC04-0080C7055A83" ID = Readings>
    <PARAM NAME ="DataURL" value ="Readings.csv">
    <PARAM NAME ="UseHeader" value ="True">
    </OBJECT>
    <FORM>
    <TABLE BORDER = 1 DATASRC ="#Readings">
    <THEAD>
    <TR>
    <TH>Date <TH>DayTotalkWh
    <TBODY>
    <TR>
    <TD><SPAN DATAFLD = Date>10/24/2011</SPAN>
    <TD><SPAN DATAFLD = DayTotalkWh>50</SPAN>
    </TABLE>

    <H3>Why the colour of the whole text is changing? </H3>
    <H3>Here is the obstacle,when a user enter a value in the textbox only DayTotalkWh values should change colour</H3>

    Enter Values <input type="textbox" name="Readme" onChange="if(!ChangeTextColor(this.value));this.focus()"><BR><BR>
    <IMG src=""><BR><BR>
    <INPUT type="reset">
    </FORM>
    </BODY>
    </HTML>

  2. #2
    Join Date
    Nov 2010
    Posts
    1,097
    maybe this...

    Code:
    <HTML>
    <HEAD>
    </TITLE>Daily Meter Readings </TITLE>
    <script type="text/javascript">
    var Readme = document.getElementsByTagName(Readme);
    this.Readme;
    
    function ChangeTextColor(value)
    {
    if(value > 40)
    {
    document.getElementById("day").style.color="red";
    this.focus();
    }
    else if(value < 40)
    {
    document.getElementById("day").style.color="green";
    this.focus();
    
    }
    else
    {
    document.getElementById("day").style.color="amber";
    this.focus();
    
    }
    }
    
    
    </script>
    
    </HEAD>
    <BODY bgcolor="pink">
    <OBJECT CLASSID = "clsid:333C7BC4-460F-11D0-BC04-0080C7055A83" ID = Readings>
    <PARAM NAME ="DataURL" value ="Readings.csv">
    <PARAM NAME ="UseHeader" value ="True">
    </OBJECT>
    <FORM>
    <TABLE BORDER = 1 DATASRC ="#Readings">
    <THEAD>
    <TR>
    <TH>Date <TH>DayTotalkWh
    <TBODY>
    <TR>
    <TD><SPAN DATAFLD = Date>10/24/2011</SPAN>
    <TD><SPAN DATAFLD = DayTotalkWh id="day">50</SPAN>
    </TABLE>
    
    <H3>Why the colour of the whole text is changing? </H3>
    <H3>Here is the obstacle,when a user enter a value in the textbox only DayTotalkWh values should change colour</H3>
    
    Enter Values <input type="textbox" name="Readme" onChange="if(!ChangeTextColor(this.value));this.focus()"><BR><BR>
    <IMG src=""><BR><BR>
    <INPUT type="reset">
    </FORM>
    </BODY>
    </HTML>

  3. #3
    Join Date
    Oct 2011
    Posts
    7

    Oops!

    Thanks a lot Xelawho,but the problem is still there.No changes!The page remains unresponsive.I've tried to change it in other way, no color change.Please any body out there to help me. I too still working on this.

  4. #4
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    Would this function do it?

    Code:
    function ChangeTextColor(value)
    {
    	targetObject = document.getElementById("day");
    	changeColour = (value > 40)?"red":(value < 40)?"green":"amber";
    	targetObject.style.color = changeColour;
    	this.focus();
    }
    not tested. although I am not sure what the point of the this.focus(); is. Do you mean targetObject.focus(); to apply focus to the changed object.
    Last edited by JunkMale; 10-27-2011 at 02:46 PM.

  5. #5
    Join Date
    Oct 2011
    Posts
    7
    Thanks JunkMale, Yes Sir, by applying this.focus() function, I meant targetObject.focus(); to apply focus to the changed object,but does not necessarily need to be there so it can be omitted.Again it doesn't work.This is going to be an issue!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles