...

View Full Version : Function



letchev
05-24-2005, 03:08 PM
Hi,

have actually the present code lines:


<a href="#" onclick="concatColumn(1);return false">Column 1</a>
<a href="#" onclick="concatColumn(2);return false">Column 2</a>
<a href="#" onclick="concatColumn(3);return false">Column 3</a>
<a href="#" onclick="concatColumn(4);return false">Column 4</a>

How I change this for:



<script>
function concatcols(){
for (i=0;i<cols.length[0].length;i++){
x=??
}
}
</script>



<a href="#" onclick="concatColumn(x);return false">All columns</a>



Many thanks

Letchev

Kor
05-24-2005, 03:20 PM
function concatcols(){
for(var i=0;i<cols.length;i++){
concatColumn(i)
}
}

<a href="#" onclick="concatcols();return false">All columns</a>

But you must set the collection cols somwhere else as a global variable... We need to see the function concatColumn() to tell you more

letchev
05-24-2005, 04:50 PM
Hi,

Here is the original function:

<script type="text/javascript">

function concatColumn(colIndex){
var tableObj = document.getElementById('myTable');
var string = '';
var wordFrequency = new Array();
var wordArray = new Array();
colIndex--;
for(var no=0;no<tableObj.rows.length;no++){
var word = tableObj.rows[no].cells[colIndex].innerHTML;
if(!wordFrequency[word]){
wordFrequency[word]=1;
wordArray.push(word);
}else wordFrequency[word]++;


}

var string = '<table border="1"><tr><th>Word</th><th>Frequency</th></tr>';
for(var no=1;no<wordArray.length;no++){
string+='<tr><td>'+wordArray[no]+'</td><td>'+wordFrequency[wordArray[no]]+'</td></tr>';

}
string+='</table>';
document.getElementById('resultDiv').innerHTML = string;

}

</script>




<form>
<a href="#" onclick="concatColumn(x);return false">all columns</a>
<div id="resultDiv"></div>
</form>


Thank you

Letchev

Kor
05-24-2005, 05:06 PM
Try:


function concatAll(){
var oTr = document.getElementById('myTable').getElementsByTagName('tr')[0];
var oTd = oTr.getElementsByTagName('td');
for(var i=0;i<oTd.length;i++){
concatColumn(i);
}
}

...
<a href="#" onclick="concatAll();return false">all columns</a>

letchev
05-24-2005, 05:48 PM
It no accuses error, but not working nothing!

This function was created for working with a fixed table, with 5 columns and
four lines. I would like that function saw the 'table' as a dynamic table from 3 to 'n' columns.

I was thinking also in another way...

It is possible tie up this input box:
<INPUT NAME="ypslon" TYPE="text" value="" size=2 textwidth=2><LABEL FOR=user>No. Collocates</LABEL><br>

with the number of concatColumn()?

For example:

If I input '5' to 'ypsilon' the function would generates:


<a href="#" onclick="concatColumn(1);return false">Column 1</a>
.....
.....
.....
<a href="#" onclick="concatColumn(5);return false">Column 1</a>


Thank you

Letchev

letchev
05-25-2005, 01:59 AM
Hi,


I found a script to do I wanted, but there is a problem;

the "ypslon" must starting always in '1', but zpslon must starting after
ypson value + 2 (must have an interval of '1'

In this way the values, for example, must be, for example:

left
1 2 3 4

right
6 7 8 9

or

left
1 2 3 4 5

right
7 8 9 10 11 12

or yet

left
1 2 3 4 5 6

right
8 9 10


<html>
<head>
<title>Untitled</title>

<SCRIPT LANGUAGE="JavaScript">
function createLinks()
{
var count = document.getElementById("ypslon").value;
var sHTML = "";
var ypslon=0;
var zpslon=0;

for(var x=0;x<count;x++)

{
sHTML += '<a href="#" onclick="concatColumn(' + (x+1) + ');return false">Column ' + (x+1) + '</a><BR>';

}

document.getElementById("tdLinks").innerHTML = sHTML;

}
</script>
<script>

function createLinks2(theForm){

var count2 = document.getElementById("zpslon").value;
var x=0;
var sHTML2 = "";
ypslon = document.getElementById("ypslon").value;

var count2 = count2 * 2;


for(var x2=ypslon;x2<count2;x2++)

{
sHTML2 += '<a href="#" onclick="concatColumn(' + (x2+1) + ');return false">Column ' + (x2+1) + '</a><BR>';

}

document.getElementById("tdLinks2").innerHTML = sHTML2;

}



</SCRIPT>

<script type="text/javascript">

function concatColumn(colIndex){
var tableObj = document.getElementById('myTable');
var string = '';
var wordFrequency = new Array();
var wordArray = new Array();
colIndex--;
for(var no=0;no<tableObj.rows.length;no++){
var word = tableObj.rows[no].cells[colIndex].innerHTML;
if(!wordFrequency[word]){
wordFrequency[word]=1;
wordArray.push(word);
}else wordFrequency[word]++;


}

var string = '<table border="1"><tr><th>Word</th><th>Frequency</th></tr>';
for(var no=1;no<wordArray.length;no++){
string+='<tr><td>'+wordArray[no]+'</td><td>'+wordFrequency[wordArray[no]]+'</td></tr>';

}
string+='</table>';
document.getElementById('resultDiv').innerHTML = string;

}

</script>














</head>

<body>



<form>

<textarea name="t1" rows=5 cols=50>

</textarea><br>

<INPUT NAME="ypslon" TYPE="text" value="" size=2 textwidth=2><LABEL FOR=user>left</LABEL>
<INPUT NAME="zpslon" TYPE="text" value="" size=2 textwidth=2><LABEL FOR=user>right</LABEL>

<INPUT TYPE="BUTTON" onClick="createLinks();" VALUE="Left">
<INPUT TYPE="BUTTON" onClick="createLinks2();" VALUE="Right">

<br><div id="t2"></div>
<div id="resultDiv"></div>

<TABLE>
<TR>
<TD ID="tdLinks"></TD>
</TR>
<TR>
<TD ID="tdLinks2"></TD>
</TR>

</TABLE>

</form>
</body>
</html>

Thank you again

Letchev

letchev
05-25-2005, 04:09 AM
Complicated? Hard to answer?

Ok. I would be happy if you as a good JS programmer tell me as I put in
function createlinks2(), the value of ypslon minus 1, WHAT it is hard for me!

for(var x2=ypslon-1;x2<count2;x2++)

Thank you

Letchev



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum