/    Sign up×
Community /Pin to ProfileBookmark

add html control dynamically

Hi, could anyone tell me why I am unable to collect the value of a textbox created dynamically with the code below (source:[url]http://javascriptsource.com)?[/url]
Thank you in advance.
John

code:
=====

<HEAD>
<script type=”text/javascript”>
<!– var arrInput = new Array(0);
var arrInputValue = new Array(0);

function addInput() {
//arrInput.push(createInput(arrInput.length));
arrInput.push(arrInput.length);
//arrInputValue.push(arrInputValue.length);
arrInputValue.push(“”);
display();
}

function display() {
document.getElementById(‘parah’).innerHTML=””;
for (intI=0;intI<arrInput.length;intI++) {
document.getElementById(‘parah’).innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
}
document.testone.nooftb.value = intI;
}

function saveValue(intId,strValue) {
arrInputValue[intId]=strValue;
}

function createInput(id,value) {
return “<input type=’text’ id=’test “+ id +”‘ onChange=’javascript:saveValue(“+ id +”,this.value)’ value='”+ value +”‘><br>”;
}

// End –>
</script>

<%
processtb
%>

</HEAD>

<BODY>
<form name=testone id=testone action=’now.asp’ method=post>
<input type=hidden name=nooftb id=nooftb>
<p id=”parah”>Dynamic creation of input boxes</p>

<a href=”javascript:addInput()”>Add more input field(s)</a><br>
</form>
</body>
</html>

<%
sub processtb()
dim i, nooftb
dim tb()
nooftb = request(“nooftb”)
response.write nooftb
redim tb(nooftb)
if nooftb <> “” and nooftb > 0 then
for i = 0 to nooftb
tb(i) = request(“test ” & i)
response.write “tb” & i & ” ” & tb(i)
next
end if
end sub
%>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorJan 17.2007 — innerHTML is not a standard DOM method, thus it does not really append the elements in the DOM tree structure. You should use DOM methods to create/append elements and set their attributes (createElement(), appendChild(), setAttribute() .... and so on)
Copy linkTweet thisAlerts:
@JohntoelauthorJan 17.2007 — Thank's for the info. I'll try it using DOM.
Copy linkTweet thisAlerts:
@KorJan 17.2007 — take care when adding events. IE does not consider events as attributes, thus you can use the DOM 0 crossbrowser syntax
<i>
</i>element.onchange=[B]function(){[/B][COLOR="Gray"]..... statements/function here.....[/COLOR][B]}[/B]
×

Success!

Help @Johntoel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...