Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generating Textfield dynamically 1

Status
Not open for further replies.

pokhran98

Programmer
Dec 8, 2003
4
0
0
IN
Hello friends,
can i generate textfields dynamically, i.e. on click of a button. I have a situation where i have to display textfields on button click. I was trying to do it through document.write() but no luck so far. I can't use layers as i have to generate 4 new textfields every time user clicks the button.
Is it possible?.
Plz Help. thanks in advance
 
<script>
count = 0
function addEm(){
count ++
val1 = document.getElementById(&quot;field1&quot;).value
val2 = document.getElementById(&quot;field2&quot;).value
val3 = document.getElementById(&quot;field3&quot;).value
val4 = document.getElementById(&quot;field4&quot;).value
theDiv = document.getElementById(&quot;myDiv&quot;)
theDiv.innerHTML += &quot;<h5>Number &quot; + count + &quot;</h5>&quot;
theDiv.innerHTML += val 1 + &quot;<br>&quot; + val2 + &quot;<br>&quot; + val3 + &quot;<br>&quot; + val4 + &quot;<hr>&quot;
}
</script>


<input id=&quot;field1&quot;>
<input id=&quot;field2&quot;>
<input id=&quot;field3&quot;>
<input id=&quot;field4&quot;>
<input type=button onClick=&quot;addEm()&quot; value=&quot;Add&quot;>
<div id=&quot;myDiv&quot;></div>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 

Hi mwolf00,
Thanks for the reply, it was very helpful, i was able to solve the problem(with slight changes), but got stuck somewhere else. I have to display textfields in table, therefore i have to insert rows(<tr> tags) as well but some how i am unable to generate <tr> tags through <div>. Although the code works fine without table. Plz help

thanks







Here is my revised code:
<html>
<head>
<title>
Test
</title>

<script>
count = 0;
function addEm(){
count ++;

val1 = &quot;<input id='field1'>&quot;;
val2 = &quot;<input id='field1'>&quot;;
val3 = &quot;<input id='field1'>&quot;;
val4 = &quot;<input id='field1'>&quot;;
theDiv = document.getElementById(&quot;myDiv&quot;);
theDiv.innerHTML += &quot;<tr> <td><input id='field1'></td> <td><input id='field1'></td> </tr>&quot; ;
}
</script>
<body>
<form name=&quot;f1&quot;>
<table border=&quot;1&quot;>
<tr>
<td><input id=&quot;field1&quot;></td>
<td><input id=&quot;field1&quot;></td>
</tr>
<tr>
<td><input id=&quot;field1&quot;></td>
<td><input id=&quot;field1&quot;></td>
</tr>
<div id=&quot;myDiv&quot;></div>
<tr>
<td colspan=&quot;2&quot;><input type=button onClick=&quot;addEm()&quot; value=&quot;Add&quot;></td>
</tr>
</form>
</body>
</html>

 

theDiv.innerHTML += &quot;<tr> <td><input id='field1'></td> <td><input id='field1'></td> </tr>&quot; ;
should be

theDiv.innerHTML += &quot;<table><tr> <td><input id='field1'></td> <td><input id='field1'></td> </tr></table>&quot; ;








 
Was out yesterday, did simonchristieis post solve your problem?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Thanks mwolf00 for asking simonchristieis's post solved my problem. Thanks simonchristieis. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top