Reputation: 1
I want to use a javascript variable (value handed over via the url) in the asp:textbox
paramater text in order to have the field filled in:
<div id="username" class="form-group">
<label for="txtUsername">Email</label>
<script type="text/javascript">
var username = querySt("username");
//document.write(username);
</script>
<asp:TextBox ID="txtUsername" runat="server" CssClass="form-control" text="<%= username %>"></asp:TextBox>
The value is not shown. How to I get the value of the variable used in the text
parameter?
Upvotes: 0
Views: 1204
Reputation: 1881
assign the value to your textbox text like this
<script>
var username = querySt("username");
document.getElementById('<%= txtUsername.ClientID %>').value =username;
</script>
Upvotes: 0
Reputation: 11330
To get the value in JavaScript, you can read it from the element in the DOM.
<asp:TextBox ID="txtUsername" runat="server" CssClass="form-control" text="<%= username %>"></asp:TextBox>
<script>
var username = document.getElementById('<%= txtUsername.ClientID %>').value;
//document.write(username);
</script>
Upvotes: 1