Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: Function

  1. #1
    New Coder
    Join Date
    May 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Function

    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

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    May 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New Coder
    Join Date
    May 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    New Coder
    Join Date
    May 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Function

    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

  • #7
    New Coder
    Join Date
    May 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

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