I am trying to make an form that is based on the myform checked checkboxes.
The myform2 should have all the checked checkboxes of myform2 with the same input fields.
How should I do this?
<h1>Heading 1</h1>
<form name="myform" method="POST" action="/cgi-bin/script.cgi">
<input name="box1" type="checkbox" value="Bike" />
<input name="box2" type="checkbox" value="Car" />
</form>
<h2>Heading 2</h2>
<form name="myform2" method="POST" action="/cgi-bin/script.cgi">
<script type="text/javascript">
var i=5;
var b=0;
while (b<=i) {
document.write('<br />' + '<input type="checkbox"' + 'value="Bike"' + '/>' + '<label for="male">'+ "Male" + '</label>' )
}
</script>
</form>
You can do something along these lines with jquery:
It should clone all the
inputdom elements under the first form element on the page and put them into the second form element on the page. Haven’t tested this, but hopefully will do what you’re looking for.If you only wanted to copy the checked input elements, you can try something like this:
However if you have checked radio buttons it will clone those too, if you want to prevent that you have to get fancier still, which will be something along the lines of:
This should copy across only the input elements that are of type checkbox and that are checked.