Staredit Network

Staredit Network -> Computers and Technical -> Me finally trying to learn JavaScript
Report, edit, etc...Posted by Syphon on 2006-05-05 at 22:50:58
Ok, I need to know why this code I was writing today won't work.

CODE

var statusMessage = 'Secks';
window.status = statusMessage;
var tCell1= document.getElementsByTagName('TD');
for (i=0;i<tCell1.length;i++){
if (tCell4[i].className=="row1"){
var tCell2= document.getElementsByTagName('TD');
for (i=0;i<tCell2.length;i++){
if (tCell2[i].className=="row2" && tCell2[i].innerHTML.match("showuser=")){
var tCell3= document.getElementsByTagName('TD');
for (i=0;i<tCell3.length;i++){
if (tCell3[i].className=="row3"){
var tCell4= document.getElementsByTagName('TD');
for (i=0;i<tCell4.length;i++){
if (tCell4[i].className=="row4" && tCell4[i].innerHTML.match("showforum=")){
{tCell4[i].onmouseover=function(){tCell4.style.backgroundColor="c3d9ff";window.status=this.getElementsByTagName('a')[0].innerHTML;}
tCell4[i].onmouseout=function(){this.style.backgroundColor="E8EEF7";window.status=statusMessage;}
tCell4[i].onclick = function(){location = this.getElementsByTagName('a')[0].href;}
}}}}}}}}}


When I look I can't see anything wrong, and I don't get any errors, but it does nothnig. It's supposed to highlight entire rows in my forum instead of one cell at a time like...

CODE

window.status = 'Secks';
var tCell= document.getElementsByTagName('TD');
for (i=0;i<tCell.length;i++){
if (tCell[i].className=="row4" && tCell[i].innerHTML.match("")){
tCell[i].onmouseover=function(){this.style.backgroundColor="c3d9ff";this.style.cursor='hand';window.status=this.getElementsByTagName('a')[0].innerHTML;}
tCell[i].onmouseout=function(){this.style.backgroundColor="E8EEF7";window.status=statusMessage;}
tCell[i].onclick = function(){location = this.getElementsByTagName('a')[0].href;}
}}


Would.

I can get it to highlight any cells .onmouseover by copying the single cell code and altering the numbers for all 4 invison .row classes, but it's ONLY that cell.

Now I need it to highlight 1,2,3 and 4 in a <TR> when I mouseover the .row4 <TD>, like I would expect from the first code. Nothing happens...

Now I need teh help.
Report, edit, etc...Posted by Centreri on 2006-05-06 at 09:11:40
I would help, but I just know the basics of Javascript. Here's a little tip, though: keep your code better organized. Make indents and all that to make it more readable.
Report, edit, etc...Posted by Syphon on 2006-05-06 at 11:17:13
I wrote another with indents and the such, even though you AREN'T supposed to in JS because whitespace soemtimes affects the code.

Anyway, it doesn't work either.

CODE

window.status = 'Secks';
var tRow = document.getElementByTagName('TR');
for (i=0;i<tRow.length;i++){
if (tRow[i].innerHTML.match("row4")){
  var tCell = document.getElementByTagName('TD');
  for (i=0;i<tCell.length;i++){
  if (tCell[i].className=="row1"){
    var tCell2 = document.getElementByTagName('TD');
    for (i=0;i<tCell.length;i++){
    if (tCell2[i].className=="row2"){
      var tCell3 = document.getElementByTagName('TD');
      for (i=0;i<tCell.length;i++){
      if (tCell3[i].className=="row3"){
        var tCell4 = document.getElementByTagName('TD');
        for (i=0;i<tCell.length;i++){
        if (tCell4[i].className=="row4" && tCell4[i].innerHTML.match("showforum=")){
tRow[i].onmouseover=function(){tCell4.style.backgroundColor="c3d9ff";window.status=tCell4.getElementsByTagName('a')[0].innerHTML;}
tRow[i].onmouseout=function(){tCell4.style.backgroundColor="E8EEF7";window.status='Secks';}
tRow[i].onclick = function(){location = tCell4.getElementsByTagName('a')[0].href;}
}}}}}}}}}}
Report, edit, etc...Posted by Centreri on 2006-05-06 at 11:37:26
Oh, it was just a general hint for making code more readable and making it easier for others to decipher and find the problem. Indents don't change how it works.
Report, edit, etc...Posted by Syphon on 2006-05-06 at 11:47:39
QUOTE(Wikipedia)
Whitespace

Spaces, tabs and newlines used outside of string constants are called whitespace. Unlike C, whitespace in JavaScript source can directly impact semantics. Because of a technique called "semicolon insertion", any statement that is well formed when a newline is parsed will be considered complete (as if a semicolon were inserted just prior to the newline). Programmers are advised to supply statement terminating semicolons explicitly to enhance readability and lessen unintended effects of the automatic semicolon insertion.

Unnecessary whitespace, whitespace characters that are not needed for correct syntax, can increase the amount of wasted space, and therefore the file size of .js files. Where file compression techniques that remove unnecessary whitespace are used, performance can be improved if the programmers have included these so-called 'optional' semicolons.


Well it does when what I read.
Report, edit, etc...Posted by RexyRex on 2006-05-06 at 17:26:24
It's basically just telling you to use semicolons. mellow.gif
Report, edit, etc...Posted by Kellodood on 2006-05-06 at 18:33:50
Stick to Software programming. It's much cooler:

CODE
#include <iostream.h>

int Add()

int main()
{
 int x;
 int y;
   cout << "Moo!/n/n";
 Add();
   cout << "Muhahaha!/n/n";
 return 0;
}

int Add(int x, int y)
{
    cout << "Enter your numbers, and we will Add them together: /n/n";
    cin >> x;
    cin >> y;
 
  cout << "You added: " << x << " and " << y << "!/n/n";
  return (x + y);
}


But be warned. I had no complier to test that on, so it might be screwy.
Report, edit, etc...Posted by Pie_Sniper on 2006-05-06 at 19:37:08
QUOTE
#include <iostream>

int Add( int x, int y );

int main()
{
  int x;
  int y;
  std::cout << "Moo!\n\n";
  Add( x, y );
  std::cout << "Muhahaha!\n\n";
  return 0;
}

int Add( int x, int y )
{
  std::cout << "Enter your numbers, and we will Add them together: \n\n";
  std::cin >> x;
  std::cin >> y;
  std::cout << "You added: " << x << " and " << y << "!\n\n";
  return ( x + y );
}

tongue.gif
Report, edit, etc...Posted by Gradius on 2006-05-06 at 19:58:13
QUOTE
#include <iostream.h>
using namespace std;
int Add()

int main()
{
int x;
int y;
  cout << "Moo!/n/n";
Add();
  cout << "Muhahaha!/n/n";
return 0;
}

int Add(int x, int y)
{
    cout << "Enter your numbers, and we will Add them together: /n/n";
    cin >> x;
    cin >> y;

  cout << "You added: " << x << " and " << y << "!/n/n";
  return (x + y);
}

bleh.gif
Report, edit, etc...Posted by Syphon on 2006-05-06 at 21:07:52
QUOTE(Kellimus @ May 6 2006, 05:33 PM)
Stick to Software programming.  It's much cooler:

CODE
#include <iostream.h>

int Add()

int main()
{
 int x;
 int y;
   cout << "Moo!/n/n";
 Add();
   cout << "Muhahaha!/n/n";
 return 0;
}

int Add(int x, int y)
{
    cout << "Enter your numbers, and we will Add them together: /n/n";
    cin >> x;
    cin >> y;
 
  cout << "You added: " << x << " and " << y << "!/n/n";
  return (x + y);
}


But be warned.  I had no complier to test that on, so it might be screwy.
[right][snapback]480994[/snapback][/right]


Well I would be... But right now I need web programming. It's kinda for a school thing.
Report, edit, etc...Posted by Kellodood on 2006-05-07 at 00:46:57
QUOTE(Gradius @ May 6 2006, 04:57 PM)
bleh.gif
[right][snapback]481050[/snapback][/right]


You don't NEED that in there you twat (I'm in a pissy mood, so blow me. That's why I said TWAT)
Next Page (1)