Hi all,
I've been writing this script today just based on questions I've seen here over the past few days. It basically allows you to specify the number of fields to create, using a select box, then either creates or removes fields depending on the number selected.
the red line works perfectly in FF, but for some reason returns false in IE. any ideas why this is happening?
thanks!
*cLFlaVA
----------------------------
[tt]somebody set up us the bomb!
[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
I've been writing this script today just based on questions I've seen here over the past few days. It basically allows you to specify the number of fields to create, using a select box, then either creates or removes fields depending on the number selected.
the red line works perfectly in FF, but for some reason returns false in IE. any ideas why this is happening?
thanks!
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html>
<head>
<title>Untitled</title>
<style type="text/css">
label { display: block; }
</style>
<script type="text/javascript"><!--
function changeFields( objParentTargetId, intNumFields, strLabelStart ) {
var objParent = document.getElementById( objParentTargetId );
var aryElems = objParent.getElementsByTagName( "input" );
if ( aryElems.length > intNumFields ) {
for ( var intI = 0; intI < aryElems.length; intI++ ) {
if ( intI+1 > intNumFields ) {
var objRemove = aryElems[intI];
alert("removing " + aryElems[intI].name);
objParent.removeChild(objRemove.parentNode);
intI--;
}
}
}
for ( var intI = 1; intI <= intNumFields; intI++ ) {
alert(aryElems[strLabelStart + intI]?(strLabelStart + intI + " exists!"):(strLabelStart + intI + " does not exist!"));
[red]if ( !aryElems[strLabelStart + intI] ) {[/red]
var objLabel = document.createElement( "label" );
objLabel.htmlFor = strLabelStart + intI;
objLabel.innerHTML = strLabelStart + " " + intI + ":";
var objTextBox = document.createElement( "input" );
objTextBox.type = "text";
objTextBox.name = strLabelStart + intI;
objParent.appendChild( objLabel );
objLabel.appendChild( objTextBox );
}
}
}
//--></script>
</head>
<body>
<form name="f" action="blah">
<fieldset>
<select name="numTextFields" onchange="changeFields('fsTarg', this.value, 'File');">
<option value="0"></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</fieldset>
<fieldset id="fsTarg">
</fieldset>
</form>
</body>
</html>
*cLFlaVA
----------------------------
[tt]somebody set up us the bomb!
![[bomb] [bomb] [bomb]](/data/assets/smilies/bomb.gif)
[URL unfurl="true"]http://www.coryarthus.com/[/url]