add value from javascript to database

Discussion in 'JavaScript' started by anisFarim, Jun 14, 2010.

  1. #1
    <html>
    <head>
    </head>

    <body>

    <SCRIPT language="javascript">

    function total(){
    var total_value = 0;
    var all_others = document.getElementsByTagName("input");

    for(var i=0; i<all_others.length; i++){
    if(all_others.type!="text" || all_others.name!="others"){
    continue;
    }

    total_value += parseFloat(all_others.value);
    }

    document.getElementById("g_total").value = total_value;
    }

    function addRow(tableID) {

    var table = document.getElementById(tableID);

    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);

    var cell1 = row.insertCell(0);
    cell1.innerHTML = 'Others ';

    var cell2 = row.insertCell(1);
    cell2.innerHTML = ': ';

    var cell3 = row.insertCell(2);
    var element3 = document.createElement("textarea");
    element3.cols = "20";
    element3.rows = "1";
    cell3.appendChild(element3);


    var cell4 = row.insertCell(3);
    var element4 = document.createElement("input");
    element4.type = "text";
    element4.size = "4";
    element4.name= "others";
    cell4.innerHTML = '$: ';
    cell4.appendChild(element4);

    }

    </SCRIPT>

    <table id = "dataTable" width="325" border="0">
    <form id="form2" name="form2" method="post" action="">
    <td width="38">Others</td>
    <td width="7">:</td>
    <td width="182"><textarea name="textarea" id="textarea" cols="20" rows="1"></textarea></td>
    <td width="80">$: <input type="text" name="others" size="4" /></td>

    </form>

    <input type="button" value="Add Others" onclick="addRow('dataTable')"/>
    </table>

    <br /><br />
    <input type="text" id="g_total" name="g_total" /> <input type="button" value="Grand Total" onclick="total()" />

    </body>
    </html>

    can i input the value from textarea name="textarea" and input type="text" name="others" in one table in database but in one row. with one unique id? it means the field in the table increase with the increasing of how many user want to add others.

    can anybody help me..
     
    anisFarim, Jun 14, 2010 IP
  2. netload

    netload Member

    Messages:
    105
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #2
    You must use another language for this (for example, PHP)
     
    netload, Jun 15, 2010 IP
  3. anisFarim

    anisFarim Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks netload.
    :):)
     
    anisFarim, Jun 24, 2010 IP
  4. GFX_Lover

    GFX_Lover Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes, netload's correct.
    You can make a PHP page to enter value in the Database. And use AJAX in the index page to send request to the PHP page, which will initially put the data in DB! xD
     
    GFX_Lover, Jun 29, 2010 IP