pizzy wrote:
/*
guilllet,
Dude thanks for the code but I already know how to do that... Look at
the second form I drew. It has check boxes there that will allow the
user to add additional fields. These check boxes should view an
additional two fields. Check out my showInputs().
*/
Please quote what you are replying to and trim any excess to
reduce message length.
Please wrap code manually at about 65 characters to ensure a
couple of posts and replys without wrapping. This makes it much
easier for others to fix your code.
Indent code using 2 or 4 spaces (2 preferred) to stop wrapping
and keep lines to a reasonable length.
All the above is on the group FAQ:
<URL:http://www.jibbering.c om/faq/>
function showInputs() {
[...] for (i=1; i <= howMany; i++) {
data = data + " <input type='text' size=10 name=" + inter +
"inputMe[]" + i + inter + "'>" + " <input type='checkbox'
onClick='showIn puts2();' id='tag_1' name='checkMe'" + i + "'><br>";
}
This will create inputs with identical ids and likely some with
identical names, thereby creating invalid HTML.
field1.innerHTM L = data;
}else {
window.alert("P lease select up to 15 entries.");
Below is a better way of doing what you are attempting. It uses
DOM methods to add the extra elements and a selector to ensure
correct input. The checkboxes are added to the form, but you
could put them into a separate div if you want.
I've used document.write to create the options for brevity.
I've also added a dummy showInputs2() function.
<script type="text/javascript">
function showInputs(f,v) {
var i = 0,
oInp, oLabel;
while (i++ < v){
oLabel = document.create Element('label' );
oInp = document.create Element('input' );
oInp.type = 'checkbox';
oInp.onclick = function() {showInputs2(th is)};
oInp.id = 'tag_' + i;
oInp.name = 'checkMe' + i;
oLabel.appendCh ild(oInp);
oLabel.appendCh ild(document.cr eateTextNode(i) );
oLabel.appendCh ild(document.cr eateElement('br '));
f.appendChild(o Label);
}
}
function showInputs2(x) {
alert(
'function showInputs2()'
+ '\ncalled from ' + x.nodeName
+ ' ' + x.type
+ '\nid: ' + x.id
+ ' name: ' + x.name
);
}
</script>
# This all gets added to the form. Check it out...
<form>
<select onchange="
showInputs(this .form,
this[this.selectedIn dex].value);
">
<option selected>Select how many checkboxes to add</option>
<br>
<script type="text/javascript">
for (var i=1; i<17; i++) {
document.write( '<option value="' + i
+ '">' + i + '<\/option>');
}
</script>
</select><br>
<input type="reset" onclick="
var labels = this.form.getEl ementsByTagName ('label');
var i = labels.length;
while (i--){
labels[i].parentNode.rem oveChild(labels[i]);
}
"><br>
</form>
--
Rob