<!doctype html> <html lang="en"> <head> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script> // serialize() will get all data from form with id "myform" and store it in data variable, that will be sent to test.php page. function getnewElementID() { var elementID = 0; if($(".form-element").length > 0) elementID = $(".form-element").length; return elementID; } $(document).ready(function() { $('#ok1').click(function () { var n = $('#box1').val(); var index = 0; var newElementID = getnewElementID(); if($(".RadioDiv").length > 0) index = $(".RadioDiv").length; var newElement = "<div class='RadioDiv form-element'><input type='hidden' name='RadioElements["+newElementID+"]' value='radiogroup'/>\n<input type='text' size='50' name='RadioElementsQueations["+newElementID+"]' placeholder='question...' >"; for (var i=1;i<=n;i++) { newElement+="<ol><input type='radio' name='RadioElementsValues["+newElementID+"]' value='radio_"+index+"' for='RadioElementsValuesText["+newElementID+"]'>\n\<input type='text' id='radtext' name='RadioElementsValuesText["+newElementID+"]' size='30' value='choice.."+index+"' ></ol>"; index++; } newElement+="</div>"; $("#myForm").append(newElement); });}); $(document).ready(function() { $('#submit').click(function () { var data = $("#myForm").serialize(); if($('input[type="radio"]:checked').length == "0") { alert("Select any value"); } else { $.post ( "test.php", data, function (response) { $('#message').html(response); } ); } return false; }); }); </script> </head> <body> <form id ="myForm" action="test.php"> <label>Select your favourite Activities:</label><br/> <input type="button" name="ok" value="ok" id="ok1"> <input type="text" value="" id="box1" name="count" size="1"><br/> <input type="submit" id="submit"/> <br/> </form> <div id="message"></div> </body> </html>
<?php var_dump($_POST); $elements = $_POST['RadioElementsValuesText']; if(is_array($elements)); $astring = implode("<br/>", $elements); echo "Choices: ". $astring."<br/>"; ?>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)