Jump to content

HTML Table, change cell colour on value entered


Recommended Posts

Posted

Hello,

 

This is probably very easy for web developers or coders out there but i aint got a clue, hope someone can help.

 

I have an asp web page with a table. The table consists of 2 columns, target grade and now grade for each pupil for a subject.

 

A teacher will enter a target grade say 2, and then at a predetermined month enter the pupils actual "now" grade but instead of being easy and entering 2 or 1 or 3 or whatever they want to enter +1 or -1 or 0. This bit is fine.

 

The bit i need help for is this: depending on what value is entered in the table cell, the cell background colour is to change.

eg +1 = BLUE

0 = GREEN

-1 = RED

 

Can anyone help? I am thinking it might be an IF statement i need but i do not have a clue.

 

Heres the code i have so far: Thanks in advance!

 

h4>English:































Dec S3 Apr S3 Nov S4 Feb S4
Initial Target Target Now Target Now Target Now Target Now
" " " " " " " " "

 

Miller

Posted

gonna be a Javascript job, probably something along the lines of the following, in your input tag

 

onchange="if (this.value=='+1')this.className='bluebg';if (this.value=='-1')this.className='redbg';if (this.value=='0')this.className='greenbg';"

 

with bluebg, redbg and greenbg all set up as styles in your CSS with the appropriate backgrounds.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...