W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2003

after createElement('input'), get a value

From: yj <yuh108@psu.edu>
Date: 06 Aug 2003 17:14:28 -0400
Message-ID: <002301c358b6$3896e090$2c5c4742@hewlett9por0s0>
To: <www-dom@w3.org>
I am using DOM in HTML.
Like the following, I make a new Input form in <span> position.
And if a user enter a value and press a button, I like to show the value.
Making the new input works.
But, getting a value from it does not work.
I cannot find any example to get a value from a input form which is newly made in the same page.
Someone tell me what's wrong with it?

<script language="javascript>
function getValue()
{
   var value = document.form1.newInput.value;
   alert("your value is "+value);   
}

function addForm()
{
...
 var newForm = document.createElement('input');
 newForm.setAttribute('name','newInput');
 newForm.setAttribute('type','text');
 newForm.setAttribute('size','20');

...
}


<body>
....
<form name="form1" ..>
<span id="here"></span>
<type="button" onClick="getValue();" ..>
Received on Wednesday, 6 August 2003 19:40:39 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:57 GMT