jquery:将附加元素的值添加到数据库中

时间:2009-10-13 09:25:17

标签: jquery sql database ajax append

问候,

我遇到了以下问题:

点击“添加风味”按钮(参见完整的示例代码),动态生成一个下拉框,文本字段和两个复选框,每次执行按钮时都会执行。

有没有办法通过ajax将动态生成的(实际“附加”)元素的值添加到数据库?

这里是示例代码,我想在其中找到它

[代码]

<html>
<head>
  <script type="text/javascript" src="jquery-1.3.2.min.js"></script> 
  <script type="text/javascript">

  function addUsedComp(){
      var id = document.getElementById("id").value;
      $("#divFlav").append("<p id='row" + id + "'><label for='txt" + id + "'>&nbsp;Flavor " + id + "&nbsp;&nbsp;<select id='select'><option selected='selected'>Vanilla</option><option >Chocolate</option><option >Strawberry</option><option >Coconut</option></select>&nbsp; amount: &nbsp;<input name='val' type='text' size='8' />&nbsp;<input type='checkbox' name='concentration1' value='gramm' id='id+1' />gramm<input type='checkbox' name='concentration2' value='percent' id='id' />percent&nbsp;&nbsp;<input name='Remove' type='button' value='Remove' onClick='removeSelectionField(\"#row" + id + "\"); return false;' /><p>"); 
      id = (id-1)+2;
      document.getElementById("id").value = id;
    }   

  <!--function removes an selection field-->
  function removeSelectionField(id) {
      $(id).remove();
  }

  </script>

  <!--ajax process/http process should get dynamically send all the data of each step, each time clicked on the "next step" button-->

</head>

<body>
  <p><input name="Add" type="button" value="Add Flavor" onClick="addUsedComp(); return false;" /></p>
     <form action="#" method="get" id="form1">
     <input type="hidden" id="id" value="1">
     <div id="divFlav"></div>
</body>
</html>

[/代码]

提前感谢您提供任何提示

1 个答案:

答案 0 :(得分:1)

Thisthis可以帮助您