SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to set values in rows

    Hi I am new here and also not very good at javascript at all
    I want to set an attribute called scope with a value row for the first cell in the first 2 columns.
    I was able to set this successfully using the JavaScript code underneath, however due to the use of rowspan the first 2 cells is not always the right one to set I want to set xes only in the country and city column. I need to somehow to do this take into account the rowspan attribute and set only the country and city column.


    here is the function.

    function testColum(){
    var colsToAddScope = 2;
    allNodes = document.getElementsByClassName("ResultsTable");
    //alert(allNodes);
    for(i=0;i < allNodes.length;i++) {

    // Set the scope attribute of the right columns
    if (allNodes[i].hasChildNodes()){
    // Get the rows of the table
    allTrElements = allNodes[i].getElementsByTagName("tr");
    for(j=0;j < allTrElements.length;j++) {
    // Get the columns of the row
    allTdElements = allTrElements[j].getElementsByTagName("td");
    for(k=0;k < allTdElements.length ;k++) {
    // Set the scope tag for the appropriate columns
    if (k<colsToAddScope){

    allTdElements[k].setAttribute("scope","row");
    allTdElements[k].innerHTML = "x";

    }
    }
    }
    }
    }

    }

    HERE is the table:

    <table id="saw_6063_2" class="ResultsTable" onmouseover="RTOver(event)" onmouseout="RTOut(event)" title="Results" border="4" cellpadding="2" cellspacing="0">
    <tr>
    <th>Country</th>
    <th>City</th>
    <th>Launch</th>
    <th>Account Name</th>
    <th> Internal Name
    </th>
    <th scope="col" class="ColumnHdgSortable" >Street Address</th>
    <th dir="ltr" scope="col" class="ColumnHdgSortable" >ROW_ID</th>
    </tr>
    <tr>
    <td dir="ltr" scope="row" rowspan="3">BE</td>
    <td dir="ltr" rowspan="2">BRUXELLES</td>
    <td dir="ltr"></td>
    <td dir="ltr">Fortis Banque s #Fortis Bank nv</td>
    <td dir="ltr">FORTIS - HQ</td>
    <td dir="ltr">Rue Montagne du Parc 3 1GA1E</td>
    <td dir="ltr">12KX+FUZ+360</td>
    </tr>
    <tr>
    <td dir="ltr">
    </td>
    <td dir="ltr" >
    Toyota Motor Europe nv#Toyota Motor Europe sa</td>
    <td dir="ltr" >TOYOTA - HQ</td>
    <td dir="ltr" >Avenue du Bourget 60</td>
    <td dir="ltr" >12KX+FQA+4792</td>
    </tr>
    <tr>
    <td dir="ltr" >RONSE</td>
    <td dir="ltr" ></td>
    <td dir="ltr" >Associated Weavers
    Europe nv</td>
    <td dir="ltr">Associated Weavers Europe
    nv - HQ</td>
    <td dir="ltr" >Industriepark Klein
    Frankrijk 1</td>
    <td dir="ltr" >12KX+FVF+1186</td>
    </tr>
    <tr>
    <td dir="ltr" scope="row" rowspan="7">FR</td>
    <td dir="ltr">BAGNOLET</td>
    <td dir="ltr"></td>
    <td dir="ltr">ETABLISSEMENTS DARTY
    ET FILS</td>
    <td dir="ltr" >DARTY - HQ</td>
    <td dir="ltr" >40 RUE JEAN JAURES
    TOUR LEVANT LES MERCURIALE</td>
    <td dir="ltr">12KX+2QN+4569</td></tr>
    <tr><td dir="ltr">BEAUSEMBLANT</td>
    <td dir="ltr">
    </td>
    <td dir="ltr">NORBERT DENTRESSANGLE</td>
    <td dir="ltr">NORBERT DENTRESSANGLE - HQ</td>
    <td dir="ltr">LES PIERRELLES</td>
    <td dir="ltr">12KX+221+1932</td>
    </tr>
    <tr>
    <td dir="ltr">BONDOUFLE</td>
    <td dir="ltr">
    </td>
    <td dir="ltr" >STIME</td>
    <td dir="ltr" >STIME - HQ</td>
    <td dir="ltr" >2 ALLÉE DES MOUSQUETAIRES</td>
    <td dir="ltr" >12KX-I7LT87</td>
    </tr>
    <tr><td dir="ltr"
    rowspan="2">BOULOGNE BILLANCOURT</td><td dir="ltr">
    </td>
    <td dir="ltr" >RENAULT</td>
    <td dir="ltr" >RENAULT - HQ</td>
    <td dir="ltr">13 QU ALPHONSE LE GALLO
    013-015</td>
    <td dir="ltr" >12KX+22H+2985</td>
    </tr>
    <tr>
    <td dir="ltr">
    </td>
    <td dir="ltr">THOMSON</td>
    <td dir="ltr">THOMSON - HQ</td>
    <td dir="ltr">46 QUAI ALPHONSE LE GALLO</td>
    <td dir="ltr">12KX+2N4+2188</td>
    </tr>
    <tr>
    <td dir="ltr" >CLERMONT FERRAND</td>
    <td dir="ltr" >
    </td>
    <td dir="ltr" >MANUF FRANC
    PNEUMATIQ MICHELIN</td>
    <td dir="ltr" >MICHELIN - HQ</td>
    <td dir="ltr" >LA COMBAUDE</td>
    <td dir="ltr" >12KX+22H+4637</td>
    </tr>
    <tr>
    <td dir="ltr" rowspan="1">CLICHY</td>
    <td dir="ltr" value="12KY-N2U76X">
    </td>
    <td dir="ltr" >CRMP8003TEST2-Looser</td>
    <td dir="ltr" >8003TEST2-HQ</td>
    <td dir="ltr" >5 BD RAPP</td>
    <td dir="ltr" >12KY-N2U76X</td>
    </tr>
    <tr><td></td><td></td><td></td><td></td><td><input type="button" value="setXX" onclick="testColum()"></td></tr>
    <tr></tr><
    </table>

  2. #2
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hellooo does anyone knows how to or have tried to do something similar? Let me know if my question is clear ok. I really need the help.

  3. #3
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you please clarify the question?

    Also, a tip, when you insert (you could edit your original post) code, wrap it around the code tags.

  4. #4
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think is clear in the html page when you click in the button. What I meant is that I want to write strings(x) only in the rows under the Country and city colunm of this table but because I have rowspan in it the string (x) is going under other colunms.
    Code:
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE>TESTING.html</TITLE>
    <script language="JavaScript" type="text/javaScript" src="js/prototype.js"></script>
    <script language="Javascript" type="text/javascript">
    
    document.getElementsByClassName = function(clsName){
        var retVal = new Array();
        var elements = document.getElementsByTagName("*");
        for(var i = 0;i < elements.length;i++){
            if(elements[i].className.indexOf(" ") >= 0){
                var classes = elements[i].className.split(" ");
                for(var j = 0;j < classes.length;j++){
                    if(classes[j] == clsName)
                        retVal.push(elements[i]);
                }
            }
            else if(elements[i].className == clsName)
                retVal.push(elements[i]);
        }
        return retVal;
    }
    function testColum(){
    	var colsToAddScope = 2;
    	var total = 0;
    			allNodes = document.getElementsByClassName("ResultsTable");
    		//alert(allNodes);
    		for(i=0;i < allNodes.length;i++)  {
    		    
    	       // Set the scope attribute of the right columns 
    	       if (allNodes[i].hasChildNodes()){
    	            // Get the rows of the table
    	    		allTrElements = allNodes[i].getElementsByTagName("tr");
    	       		for(j=0;j < allTrElements.length;j++)  {
    	       		  // Get the columns of the row
    	       	      allTdElements = allTrElements[j].getElementsByTagName("td");
    	       	      for(k=0;k < allTdElements.length ;k++)  {
    	       	          // Set the scope tag for the appropriate columns
    	       	          if (k<colsToAddScope){
    	       	          
    	       	   	          allTdElements[k].setAttribute("scope","row");
    	       	   	          allTdElements[k].innerHTML = "x";
    	       	   	          
    	       	   	          }
    	       	   	      }
    	       	      }
    	            }
    	       }
    	   
    }
    
    </script>
    </HEAD>
    <BODY>
    <P>Place content here.</P>
    
    <table class="TitleTable" cellspacing="0" style="" width="100&#37;">
    <tr><td class="TitleCell" style="" title=""></td></tr>
    <tr><td class="TitleNameCell" style="" title=""></td></tr>
    </table>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td class="CVView" vid="m:portlet~r:AcctList~v:compoundView!1~v:tableView!1" sid="2ffi9vaj06uola77p8vf1lgusm">
    <table class="CVFormatTable" style="width:100%;height:100%;" cellspacing=0 >
    <tr>
    <td class="CVFormatCell" align=center>
    <a href="javascript:void(null)" onclick="IgnoreEvent();" title="Table" name="SectionElements"></a>
    <div id="idResultsTableParent">
    <table id="saw_6063_2" class="ResultsTable"  border="4" cellpadding="2" cellspacing="0">
    <tr>
    <th>Country</th>
    <th>City</th>
    <th>Launch</th>
    <th>Account Name</th>
    <th> Internal Name
    </th>
    <th scope="col" class="ColumnHdgSortable" >Street Address</th>
    <th dir="ltr" scope="col" class="ColumnHdgSortable" >ROW_ID</th>
    </tr>
    <tr>
    <td dir="ltr" scope="row" rowspan="3">BE</td>
    <td dir="ltr"  rowspan="2">BRUXELLES</td>
    <td dir="ltr"></td>
    <td dir="ltr">Fortis Banque s #Fortis Bank nv</td>
    <td dir="ltr">FORTIS - HQ</td>
    <td dir="ltr">Rue Montagne du Parc 3 1GA1E</td>
    <td dir="ltr">12KX+FUZ+360</td>
    </tr>
    <tr>
    <td dir="ltr">
    </td>
    <td dir="ltr" >
    	Toyota Motor Europe nv#Toyota Motor Europe sa</td>
    <td dir="ltr" >TOYOTA - HQ</td>
    <td dir="ltr" >Avenue du Bourget 60</td>
    <td dir="ltr" >12KX+FQA+4792</td>
    </tr>
    <tr>
    <td dir="ltr" >RONSE</td>
    <td dir="ltr" ></td>
    <td dir="ltr" >Associated Weavers 
    Europe nv</td>
    <td dir="ltr">Associated Weavers Europe 
    nv - HQ</td>
    <td dir="ltr" >Industriepark Klein 
    Frankrijk 1</td>
    <td dir="ltr" >12KX+FVF+1186</td>
    </tr>
    <tr>
    <td dir="ltr" scope="row" rowspan="7">FR</td>
    <td dir="ltr">BAGNOLET</td>
    <td dir="ltr"></td>
    <td dir="ltr">ETABLISSEMENTS DARTY 
    ET FILS</td>
    <td dir="ltr" >DARTY - HQ</td>
    <td dir="ltr" >40 RUE JEAN JAURES
    TOUR LEVANT LES MERCURIALE</td>
    <td dir="ltr">12KX+2QN+4569</td></tr>
    <tr><td dir="ltr">BEAUSEMBLANT</td>
    <td dir="ltr">
    </td>
    <td dir="ltr">NORBERT DENTRESSANGLE</td>
    <td dir="ltr">NORBERT DENTRESSANGLE - HQ</td>
    <td dir="ltr">LES PIERRELLES</td>
    <td dir="ltr">12KX+221+1932</td>
    </tr>
    <tr>
    <td dir="ltr">BONDOUFLE</td>
    <td dir="ltr">
    </td>
    <td dir="ltr" >STIME</td>
    <td dir="ltr" >STIME - HQ</td>
    <td dir="ltr" >2 ALL&#201;E DES MOUSQUETAIRES</td>
    <td dir="ltr" >12KX-I7LT87</td>
    </tr>
    <tr><td dir="ltr"  
    	rowspan="2">BOULOGNE BILLANCOURT</td><td dir="ltr">
    </td>
    <td dir="ltr" >RENAULT</td>
    <td dir="ltr" >RENAULT - HQ</td>
    <td dir="ltr">13 QU ALPHONSE LE GALLO
    013-015</td>
    <td dir="ltr" >12KX+22H+2985</td>
    </tr>
    <tr>
    <td dir="ltr">
    </td>
    <td dir="ltr">THOMSON</td>
    <td dir="ltr">THOMSON - HQ</td>
    <td dir="ltr">46 QUAI ALPHONSE LE GALLO</td>
    <td dir="ltr">12KX+2N4+2188</td>
    </tr>
    <tr>
    <td dir="ltr" >CLERMONT FERRAND</td>
    <td dir="ltr" >
    </td>
    <td dir="ltr" >MANUF FRANC 
    PNEUMATIQ MICHELIN</td>
    <td dir="ltr" >MICHELIN - HQ</td>
    <td dir="ltr" >LA COMBAUDE</td>
    <td dir="ltr" >12KX+22H+4637</td>
    </tr>
    <tr>
    <td dir="ltr" rowspan="1">CLICHY</td>
    <td dir="ltr" value="12KY-N2U76X">
    </td>
    <td dir="ltr" >CRMP8003TEST2-Looser</td>
    <td dir="ltr" >8003TEST2-HQ</td>
    <td dir="ltr" >5 BD RAPP</td>
    <td dir="ltr" >12KY-N2U76X</td>
    </tr>
    <tr><td></td><td></td><td></td><td><input type="button" value="setXX" onclick="testColum()"></td><td></td>
    
    </tr>
    <tr></tr><
    </table>
    </div>
    </BODY>
    </HTML>
    Last edited by bamabam; Mar 30, 2007 at 15:58.

  5. #5
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guys. I was wondering by not getting any answers or advices about my problem if there is a solution to my problem? I am not very good in javascript and I dont have time now to learn it very well rightnow but will do as soon after getting out of this one . Is it possible or not? if wasnt the rowspan in the table that would be ok but because of rowspan iam getting my string printed out of order.

    thanks

  6. #6
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello everyone.

    So far I am getting some progress in my javascript code now. I am just going to post the function changed for not to increase this thread ok.

    Code:
    function testColum(){
    	var colsToAddScope = 2;
    	var myBoolean=new Boolean(false)
      
    		var	allNodes = document.getElementsByClassName("ResultsTable");
    		for(i=0;i < allNodes.length;i++)  {
    	
    		    // Set the scope attribute of the right columns 
    	       if (allNodes[i].hasChildNodes()){
    						
    	            // Get the rows of the table
    				allTrElements = allNodes[i].getElementsByTagName("tr");
    				
    		for(j=0;j < allTrElements.length;j++)  {
    		
    	       		 // Get the columns of the row
    	       	      allTdElements = allTrElements[j].getElementsByTagName("td");
    	       	for(k=0;k < allTdElements.length ;k++)  {
    	       	      
    		novaRow = allTdElements[k].getAttribute("rowSpan");
    		novaCol = allTdElements[k].getAttribute("colSpan");
    			if (k<colsToAddScope){
    				if(novaRow > 1){
    				    alert("novaRow " +  novaRow);
    				    myBoolean = true;
    				}
    				if(novaRow < 2){
    				    alert("myBoolean == false");
    				    myBoolean = false;
    				}
    				f(myBoolean == true){
    				    allTdElements[k].innerHTML =  "contain rowspan";
    				}
    				if(myBoolean == false){ 
    				    allTdElements[0].innerHTML = "s";
    				    //allTdElements[1].innerHTML = "f";
    				}
    				}
    		       	        // Set the scope tag for the appropriate columns
    	       	            if (k<colsToAddScope){
    	       	   	            allTdElements[k].setAttribute("scope","row");
    	       	   	          
    	       	   	          }
    	       	   	    
    	       	   	      }
    	       	       }
    	            }
    	        }
    	   
    }
    When the number of rowspan is less than 2 and setting the boolean to false, I can print the string "s" under the Country and city columns only with no problem because iam getting the cell index[0].

    Code:
    if(myBoolean == false){ 
        allTdElements[0].innerHTML = "s";
        //allTdElements[1].innerHTML = "f";
    }

    but if I take the commented code out prints the string "f" on the cells where the value of the cell index is 1 under not only the city column but also in others too because it span other rows which contain the rowspan atribute. But I dont to print the string "f" under other colunms but the Country an city ones which is the first 2 columns in the table. I am finding really hard to do! Does anyone knows how to or came across something similar in the past?

    I really need a hand on this one please

  7. #7
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello??


Bookmarks

Posting Permissions

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