Amen
Amen

Reputation: 713

How do I use javascript to update the values of hidden input fields

I have the following fields:

First Name: <input type="text" id="tFName" name="tFName" maxlength="50" />
Last Name:  <input type="text" id="tLName" name="tLName" maxlength="50" />

I want to use javaScript specifically dojo to update the value of the following hidden input fields:

<input type="hidden" name="tFName" value=""/>
<input type="hidden" name="tLName" value=""/> 

what are some ways in Javascript and Dojo to accomplish this?

Upvotes: 2

Views: 9735

Answers (4)

Tobias
Tobias

Reputation: 883

If we modify the html some (setting an ID on the hidden ones) we can:

First Name: <input type="text" id="tFName" name="tFName" maxlength="50" />
<input type="hidden" id="hiddenFName" name="tFName" value=""/>


var fName = dijit.byId("tFName");
var hFName = dijit.byId("hiddenFName");

hFName.attr("value", fName.attr("value"));

Upvotes: 2

nobitavn94
nobitavn94

Reputation: 327

Try this: document.getElementsByName("tFName")[0].value ="abc"; document.getElementsByName("tLName")[0].value ="def";

Upvotes: 1

eykanal
eykanal

Reputation: 27067

In plain Javascript, you can just set the .value property:

document.<form name>.tFName.value = <whatever>
document.<form name>.tLName.value = <whatever>

Upvotes: 3

Emil Ivanov
Emil Ivanov

Reputation: 37653

dojo.query('#tFName').val('Joe');

See the val() docs.

Upvotes: 5

Related Questions