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 upda开发者_StackOverflow社区te 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?
dojo.query('#tFName').val('Joe');
See the val() docs.
In plain Javascript, you can just set the .value
property:
document.<form name>.tFName.value = <whatever>
document.<form name>.tLName.value = <whatever>
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"));
Try this: document.getElementsByName("tFName")[0].value ="abc"; document.getElementsByName("tLName")[0].value ="def";
精彩评论