views:

196

answers:

1

Greetings,

I got the following problem:

By clicking on the button "Add Flavor" (see full sample code), a dropdown-box, text field and two checkboxes are dynamically generated, - each time the click on the button is performed.

Is there a way to add the values from the dynamically generated (actually "appended") elements to the database via ajax ?

Here the sample code, on which I'd like to find it out

[code]

<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>

[/code]

Thank you in advance for any hints

+1  A: 

This and this should help you

k0ni