1

this is my code to add dynamic rows on a table when click on the add button. Now i need to get the values entered into the text boxes and submit to DB.

<div id="addinput">
    <p>
    <button name="add" onclick="myFunction(this)" value="'.$btn_count.'"><font color="#FF0000" size="4">+</font></button>
    </p>
    </div>
    </td>

This is my functon to add dynamic rows to table, just below the row where we click

<script>
function myFunction(y)
{

var f = y.parentNode;
var d = f.parentNode;
var g = d.parentNode;
var c =g.parentNode.rowIndex;   


var table = document.getElementById("myTable");

var row = table.insertRow(c+1);


var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
var cell6 = row.insertCell(5);
var cell7 = row.insertCell(6);

cell1.innerHTML = "<form name='frm_sub' id='frm_id' action='#'><input type=text  name='txt_id' id='id_id' size=10 placeholder=Id>";
cell2.innerHTML = "<input type=text name='txt_item' id='id_item' size=10 placeholder=Item>";
cell3.innerHTML = "<input type=text name='txt_cost' id='id_cost' size=10 placeholder=0.00>";
cell4.innerHTML = "<input type=text name='txt_wp' id='id_wp' size=10 placeholder=0.00>";
cell5.innerHTML = "<input type=text name='txt_rp' id='id_rp' size=10 placeholder=0.00>";

cell6.innerHTML = "<input type='button' name='submit' id='id_submitBtn' value='Save' size=10 onclick='form_submit()' ></form>";


document.getElementById("myTable");

}

function form_submit()
{


var item_name = $("input#id_item").val();

var cost = $("input#id_cost").val();

var wp = $("input#id_wp").val();

var rp = $("input#id_rp").val();

var dataString = 'item_name='+ item_name + '&cost=' + cost + '&wp=' + wp+ '&rp=' + rp;

alert(dataString);



$.ajax({

        type: "POST",
        url:newAdd.php,
        dataType: "json",
        type: "POST",
        data: {

            items : $("#id_item").val(),           
            cost : $("#id_cost").val(),
            wp : $("#id_wp").val(),
            rp : $("#id_rp").val(),
        },
        success: function () {
            alert("Success");
        }
    });



}

in newAdd.php i wrote

echo$itemName =$_POST["txt_item"];
$insert = mysql_query('INSERT INTO item (item) VALUES ('$itemName');

But this is not working..

1
  • I think this will work, quotes around. url:'newAdd.php', Commented Jul 23, 2014 at 5:28

2 Answers 2

4
if you are getting that alert  then this will work 


    function form_submit()
    {


    var item_name = $("input#id_item").val();

    var cost = $("input#id_cost").val();

    var wp = $("input#id_wp").val();

    var rp = $("input#id_rp").val();

    var dataString = 'item_name='+ item_name + '&cost=' + cost + '&wp=' + wp+ '&rp=' + rp;
    $.ajax({
        type: "post",
        url: "newAdd.php",
        data:dataString,
        success: function(msg){ 
        alert('success');   

        }
        });



    }
Sign up to request clarification or add additional context in comments.

Comments

0

Try this ajax request. Hope this will help you -

$.ajax({
        type: "POST",
        url:'newAdd.php',
        dataType: "json",
        data: {
            items : $("#id_item").val(),           
            cost : $("#id_cost").val(),
            wp : $("#id_wp").val(),
            rp : $("#id_rp").val()
        },
        success: function () {
            alert("Success");
        }
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.