1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

HTML create array problem

Discussion in 'HTML & Website Design' started by fhatzis, Jan 3, 2009.

  1. #1
    I have the following problem in my jscript program..My programm has the following structure:

    <html>
    <head>
    <title></title>
    <script type="text/javascript">

    var result;

    function func(add)
    {
    result=add+5;
    return result;
    }

    <script>
    </head>

    <form action="#" onsubmit="func(this.add.value); return false">

    <p>

    <input type="text" size="60" name="add"/>

    <input type="submit" value="Go!" />

    </p>

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





    My problem is that I want to create a table with "result" values. The variable result is being returned as you see when I press the button "Go!" and is calculated in the "func" function. How Can I create this table in the <body> </body> section without knowing the value of the "result" variable ???

    For example:


    I write in the textbox the number 4.Then I press the button Go! Then the function func calculates the result variable and give it the value 4+5=9. (result=add+5).My problem here is that I dont know how to create a table with length = 9..I know how to create generally a table in html language but I dont know how to create it in the <body> </body> section and with a special number as result..

    Please help me if you know how..
    Thank you for your time and I wish u happy new year!!!
     
    fhatzis, Jan 3, 2009 IP
  2. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try to search on DOM element creation using javascript
     
    fairuz.ismail, Jan 3, 2009 IP
  3. ThePickyOne

    ThePickyOne Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'm not sure I fully understand what you are trying to achieve but here is an example of what I believe you are striving for, see code snippit below:

    <HTML><HEAD><TITLE></TITLE>
    <SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
    var theseValues = '0';
    function button1_onclick() {
    var thisValue;
    var thisArray;
    var thisTable = '';
    thisValue = document.getElementById("text1").value
    theseValues = theseValues + '~' + thisValue;
    document.getElementById("text1").value = '';
    thisArray = theseValues.split('~');
    var indexCount;
    var indexTotal = thisArray.length;
    thisTable = '<table border="1"><tr><td>Equation</td><td>Result</td></tr>';
    for(indexCount = 1; indexCount < indexTotal; indexCount++){
    var thisNum = parseInt(thisArray[indexCount]) + 5 ;
    var thisNumText = thisNum.toString();
    thisTable = thisTable + '<tr><td>5 + ' + thisArray[indexCount] + ' = </td><td>' + thisNumText + '</td></tr>';
    }
    thisTable = thisTable + '</table>';
    document.getElementById('myContainer').innerHTML = thisTable;
    }
    function button2_onclick() {
    document.getElementById('myContainer').innerHTML = '';
    }
    </SCRIPT></HEAD><BODY>
    <INPUT type="text" id=text1 name=text1><br />
    <INPUT type="button" value="Enter a number and click here" id=button1 name=button1 LANGUAGE=javascript onclick="return button1_onclick()">
    <INPUT type="button" value="Clear" id=button2 name=button2 LANGUAGE=javascript onclick="return button2_onclick()">
    <!-- This is my container object -->
    <table><tr><td id='myContainer'></td></tr></table>
    </BODY></HTML>
     
    ThePickyOne, Jan 15, 2009 IP