ugrás a tartalomhoz

js új input hozzáadása gombnyomásra

Ghostika · 2009. Május. 30. (Szo), 12.23
Üdv mindenkinek.

amit szeretnék megcsinálni az a címben is látható, ha egy gombra rányomom akkor adjon hozzá egy plusz input mezőt a weboldalhoz, ez mind szép és jó, de a fenti kód IE-ben szépen megy, de Firefoxban nem nagyon akar. Másik dolog hogy FF-ben fenn van a firebug ami néha beleszól a javascriptbe nálam, nem tudok miért ,de itt tuti nem az a baj, csak nem tudok rájönni mi.
Ha valakinek van egyszerűbb ötlete azt is szívesen fogadom.

előre is köszönöm:

Ghostika

a kód pedig:

<html>
<head>
<script>
function doIt()
{
var doc = document;
var f = doc.getElementById('myForm');

// show hidden
var el = f.elements.unseen;
el.style.display = "";

// create/insert new
el = doc.createElement("input");
el = f.appendChild(el);
el.name = "newinput";
el.type = "text";
el.value = "added on the fly";
}

</script>
</head>
<body>

<form name="myform" action=#>
<input type=text style="display: none;"
name="unseen"
value="present but unseen">
</form>

<button onclick="doIt()">do it</button>


</body>
</html>
 
1

így

mgergo90 · 2009. Május. 30. (Szo), 13.07

<html>
<head>
<script>
function doIt() {
	var f = document.getElementById('myform');

	// show hidden
	var el = document.getElementById('unseen');
	el.style.display = "block";

	// create/insert new
	el = document.createElement("input");
	el = f.appendChild(el);
	el.name = "newinput";
	el.type = "text";
	el.value = "added on the fly";
	f.innerHTML += '<br>';
}

</script>
</head>
<body>
	<form name="myform" id="myform" action="#">
		<input type=text style="display: none;" id="unseen" value="present but unseen">
	</form>
	<button onclick="doIt()">do it</button>
</body>
</html>
Így gondoltad remélem.
2

Pontosan, köszönöm szépen a

Ghostika · 2009. Május. 30. (Szo), 13.17
Pontosan,

köszönöm szépen a segítséget:)