我想在我的MVC應用程序的數據庫中插入值,但我通過javascript獲取值。請告訴我該怎麼做,是否有任何方式通過它我們可以在mvc應用程序中處理javascript。請提供一些有用的資源。在mvc中通過javascript在數據庫sql server 2008中插入值/
我的JavaScript代碼是關於通過用戶創建動態字段的動態字段創建。我從用戶那裏獲得值,請告訴我該怎麼做。
的JavaScript代碼如下:
<script language="javascript" type ="text/javascript" >
function addRow(tableID) {
var elem = document.getElementById("linkid");
if (typeof elem.onclick == "function") {
elem.onclick.apply(elem);
}
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
if (rowCount < 25) {
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
var element2 = document.createElement("input");
element2.type = "text";
cell2.appendChild(element2);
var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
cell3.appendChild(element3);
var cell4 = row.insertCell(3);
var element4 = document.createElement("a");
element4.setAttribute("href", "#");
var anchortext = document.createTextNode('Edit');
element4.appendChild(anchortext);
// cell4.appendChild(element4);
}
else {
alert("you can add only upto 25 fields");
}
}
function deleteRow(tableID) {
try {
debugger;
var table = document.getElementById(tableID);
var rowCount = table.rows.length; 1
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if (null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch (e) {
alert(e);
}
}
function hideVisible(divid, divid1) {
try {
if (divid == "Advertiser")
{
if (document.getElementById(divid).style.display == "block") {
document.getElementById(divid).style.display == "none"
document.getElementById(divid).style.visibility = "hidden";
if (document.getElementById(divid1).style.display == "none") {
document.getElementById(divid1).style.display = "block"
document.getElementById(divid1).style.visibility = "visible";
var text = document.getElementById("advertiser_Text");
text.setAttribute("class", "newtext1");
text.value = "Advertiser";
}
}
}
if (divid == "Brand")
{
if (document.getElementById(divid).style.display == "block")
{
document.getElementById(divid).style.display == "none"
document.getElementById(divid).style.visibility = "hidden";
if (document.getElementById(divid1).style.display == "none")
{
document.getElementById(divid1).style.display = "block"
document.getElementById(divid1).style.visibility = "visible";
var text = document.getElementById("brand_Text");
text.setAttribute("class", "newtext1");
text.value = "Brand";
}
}
}
if (divid == "Target")
{
if (document.getElementById(divid).style.display == "block")
{
document.getElementById(divid).style.display == "none"
document.getElementById(divid).style.visibility = "hidden";
if (document.getElementById(divid1).style.display == "none")
{
document.getElementById(divid1).style.display = "block"
document.getElementById(divid1).style.visibility = "visible";
var text = document.getElementById("Target_Text");
text.setAttribute("class", "newtext1");
text.value = "Target";
}
}
}
if (divid == "Timing") {
if (document.getElementById(divid).style.display == "block") {
document.getElementById(divid).style.display == "none"
document.getElementById(divid).style.visibility = "hidden";
if (document.getElementById(divid1).style.display == "none") {
document.getElementById(divid1).style.display = "block"
document.getElementById(divid1).style.visibility = "visible";
var text = document.getElementById("Timing_Text");
text.setAttribute("class", "newtext1");
text.value = "Timing";
}
}
}
if (divid == "Program") {
if (document.getElementById(divid).style.display == "block") {
document.getElementById(divid).style.display == "none"
document.getElementById(divid).style.visibility = "hidden";
if (document.getElementById(divid1).style.display == "none") {
document.getElementById(divid1).style.display = "block"
document.getElementById(divid1).style.visibility = "visible";
var text = document.getElementById("Program_Text");
text.setAttribute("class", "newtext1");
text.value = "Program Scope";
}
}
}
if (divid == "Media") {
if (document.getElementById(divid).style.display == "block") {
document.getElementById(divid).style.display == "none"
document.getElementById(divid).style.visibility = "hidden";
if (document.getElementById(divid1).style.display == "none") {
document.getElementById(divid1).style.display = "block"
document.getElementById(divid1).style.visibility = "visible";
var text = document.getElementById("Media_Text");
text.setAttribute("class", "newtext1");
text.value = "Media Buy";
}
}
}
if (divid == "Distribution") {
if (document.getElementById(divid).style.display == "block") {
document.getElementById(divid).style.display == "none"
document.getElementById(divid).style.visibility = "hidden";
if (document.getElementById(divid1).style.display == "none") {
document.getElementById(divid1).style.display = "block"
document.getElementById(divid1).style.visibility = "visible";
var text = document.getElementById("Distribution_Text");
text.setAttribute("class", "newtext1");
text.value = "Distribution Goal";
}
}
}
if (divid == "Added") {
if (document.getElementById(divid).style.display == "block") {
document.getElementById(divid).style.display == "none"
document.getElementById(divid).style.visibility = "hidden";
if (document.getElementById(divid1).style.display == "none") {
document.getElementById(divid1).style.display = "block"
document.getElementById(divid1).style.visibility = "visible";
var text = document.getElementById("Added_Text");
text.setAttribute("class", "newtext1");
text.value = "Added Value";
}
}
}
if (divid == "Objective") {
if (document.getElementById(divid).style.display == "block") {
document.getElementById(divid).style.display == "none"
document.getElementById(divid).style.visibility = "hidden";
if (document.getElementById(divid1).style.display == "none") {
document.getElementById(divid1).style.display = "block"
document.getElementById(divid1).style.visibility = "visible";
var text = document.getElementById("Objective_Text");
text.setAttribute("class", "newtext1");
text.value = "Objective";
}
}
}
if (divid == "Strategy") {
if (document.getElementById(divid).style.display == "block") {
document.getElementById(divid).style.display == "none"
document.getElementById(divid).style.visibility = "hidden";
if (document.getElementById(divid1).style.display == "none") {
document.getElementById(divid1).style.display = "block"
document.getElementById(divid1).style.visibility = "visible";
var text = document.getElementById("Strategy_Text");
text.setAttribute("class", "newtext1");
text.value = "Strategy";
}
}
}
if (divid == "Market") {
if (document.getElementById(divid).style.display == "block") {
document.getElementById(divid).style.display == "none"
document.getElementById(divid).style.visibility = "hidden";
if (document.getElementById(divid1).style.display == "none") {
document.getElementById(divid1).style.display = "block"
document.getElementById(divid1).style.visibility = "visible";
var text = document.getElementById("Market_Text");
text.setAttribute("class", "newtext1");
text.value = "Market Research";
}
}
}
if (divid == "Refusal") {
if (document.getElementById(divid).style.display == "block") {
document.getElementById(divid).style.display == "none"
document.getElementById(divid).style.visibility = "hidden";
if (document.getElementById(divid1).style.display == "none") {
document.getElementById(divid1).style.display = "block"
document.getElementById(divid1).style.visibility = "visible";
var text = document.getElementById("Refusal_Text");
text.setAttribute("class", "newtext1");
text.value = "Right of First Refusal Date";
}
}
}
}
catch (e) {
alert(e);
}
}
</script>
在此先感謝 麗思
建議你接受一些更正確的答案...... – 2009-12-08 06:39:38