0

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?

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

Comments

0

assign the value to your textbox text like this

<script>
    var username = querySt("username");
    document.getElementById('<%= txtUsername.ClientID %>').value =username;
</script>

1 Comment

I tried your solution but still the value is not displayed in the field. When I uncomment the document.write, I can see that the variable is set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.