Jump to content

javascript and PHP


traxion

Recommended Posts

hey alli got a script of javascript

   function sum() {        for (var col=0; col<numberOfCols; col++) {          var total = sumCol(col);          var totalCell = document.getElementById("total"+col);          if (totalCell != null) {            // Hier kun je de stijl van de totalen aanpassen           document.write(total)		    if (total == <?php echo $a_uren[$z]; $z++?>) 			{			totalCell.innerHTML = "<SPAN STYLE='background-color:  #FF0000;'>"+total+"</SPAN>";			}			else			{			totalCell.innerHTML = "<SPAN STYLE='background-color: : #000FFF;'>"+total+"</SPAN>";			}	          }        }      } 

i got the php array with some numbers 5 5 5 4.5 4.5 5 5 5 5 5 5 <= from my databaseand total is also made of some numbers 5 5 5 4.5 4.5 5 5 5 5 5 5 <= these numbers come from document.write(total)as u can see the numbers are the same but the code give @ both of the 4.5 's that it is incorrect.. i dont use javascript much so i think i made a mistake somewhere but where?i got a new problemi put the text in a cell of a table if the stament is correct or not that must change the background of the complete cell and not just only the background of the text

Link to comment
Share on other sites

i found i script on the web for my planning.i got a php array to a javascript array ut i dont get it in the ifstatmentCode:myarray = new Object(); myarray[1] = 5; myarray[2] = 5; myarray[3] = 5; myarray[4] = 4.5; myarray[5] = 5; myarray[6] = 4.5; myarray[7] = 5; myarray[8] = 5; myarray[9] = 5; myarray[10] = 5; myarray[11] = 6.5;obove is the arrayand i was hoping to read it out like this. the second statment is to check is the array works it does..Code: if (var i = 1 ;total == myarray[$i]; var i++) or if (total == myarray[5]) { totalCell.innerHTML = "<SPAN class='gelijk'> "+total+" </SPAN>"; } else { totalCell.innerHTML = "<SPAN class='ongelijk'> "+total+" </SPAN>"; }now i need to have the myarray [ variable ] so i can check the valuas but i cant make it varible plz help

Link to comment
Share on other sites

First, for changing the background color of the entire cell rather than just the span, you can do something like this:

// rather than:// totalCell.innerHTML = "<SPAN STYLE='background-color: #FF0000;'>"+total+"</SPAN>";// try this:totalCell.style.backgroundColor = "#ff0000";totalCell.innerHTML = total;

As for the other problem, I'm not entirely certain what you are trying to accomplish. Are you trying to loop through an array to add up all the elements to come up with a total? If so, try this:

var total = 0;for(var i = 0; i < myarray.length; i++){	total += myarray[i];}

Link to comment
Share on other sites

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...