简体   繁体   中英

adding rows dynamically in classic asp and giving the connection to the new rows to database

I am just a beginer in asp and i have a problem. I have a common function which add rows dynamically and the code is as follows

function Myfunction(tableid) 
{

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

var rowCount = table.rows.length;        

var row = table.insertRow(rowCount);        


var cell1 = row.insertCell(0); 

cell1.innerHTML = rowCount + 1;


var cell2 = row.insertCell(1);

var element2 = document.createElement("input");

cell2.appendChild(element2);


var cell3 = row.insertCell(2);

var element3 = document.createElement("input");

cell3.appendChild(element3);


var cell4 = row.insertCell(3);

var element4 = document.createElement("input");

cell4.appendChild(element4);

}

And the AddPage code of html is as follows:

"table id="tablerow"

tr align="center"

input type="textbox" name="subjectid"

input type="textbox" name="subjectname"

input type="Checkbox" name="status"  value="Y"

input type="Checkbox" name="status"  value="N"

input type="textbox" name="internal"

input type="textbox" name="external"

tr

And an insert query as follows:

sql1="INSERT INTO SUBJECT_MASTER (SUBJECT_ID,SUBJECT_NAME,ACTIVE_STATUS,INTERNAL,EXTERNAL) VALUES ("&subjectid & ",'" &subjectname &"','"&activestatus &"','"&internal &"','"&external &"')"

Now if i add a row and insert the data using the new added rows, It is not inserting the data. So please can you help me.And also Please also clear me the checkbox issue.

Classic ASP read the form data based on the elements name - each element send its value based on its name. Without a name, the value won't be sent to the server at all.

So to have the newly added elements send their value, simply give them a name. Assuming you want same name as your existing text boxes:

var cell2 = row.insertCell(1);
var element2 = document.createElement("input");
element2.name = "subjectid"
cell2.appendChild(element2);

var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.name = "subjectname"
cell3.appendChild(element3);

This way the values will be sent as comma separated string.

IMPORTANT : your current code is wide open for SQL injection attacks. If you don't want your database to be hacked, copied and/or deleted you better learn about SQL injection (just Google it) and fix your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM