Reputation: 333
I'm having a little problem, i'm trying to make a disabled "input text type" enabled with a text in it.
function newForm(){
document.getElementsByName("name1").disabled = false;
document.getElementsByName("name1").value="TEST";
}
with this
<div id="passengers">
<div id="form">
<table>
<thead>
<tr><th></th><th>Name</th><th>LastName</th><th>Date of Birth</th></tr>
</thead>
<tbody>
<form id="formulaire" action="">
<tr><th>Passenger #1</th><th><input type="text" name="name1" tabindex="1" disabled="true"/></th><th><input type="text" name="lastname1" tabindex="2" disabled="true"/></th><th><input type="text" name="date1" tabindex="3" disabled="true"/></th></tr>
</table>
</div>
<input type="submit" value="New" onclick="newForm()"/><input type="submit" value="Send" disabled="true"/><input type="submit" value="Modify" disabled="true"/></form>
</div>
Upvotes: 0
Views: 3303
Reputation: 68576
Firstly, change the input type of the button, from submit
to button
:
<input type="button" value="New" onclick="newForm()"/>
As your function has nothing to do with submitting the form (and submit
will cause unwanted behaviour).
Secondly, getElementsByName
returns a collection of objects, not one element. Target the element by accessing the first element using [0]
:
function newForm(){
document.getElementsByName("name1")[0].disabled = false;
document.getElementsByName("name1")[0].value="TEST";
}
Upvotes: 1
Reputation: 7592
getElementsByName returns a collection of elements try this
document.getElementsByName('name1')[0].disabled = true;
Upvotes: 1