SouthDallas40
asked on
Passing variables to javascript input box
This should be an easy 500 points for someone. What I need is probably quite simple to do. I have two javascript input boxes that I need to populate with data from my vb.net code behind.
What is the syntax for getting the data from my vb.net variables into the javascript input boxes?
What is the syntax for getting the data from my vb.net variables into the javascript input boxes?
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim username, password As String
username = somevalue
password = somevalue
End Sub
</script>
<input name="username" value="exchangetest1" type="hidden" class="txt" id="username" />
<input name="password" value="12345" type="hidden" class="txt" id="password" onfocus="g_fFcs=0" />
<script type="text/javascript">
document.forms(0).action='https://email.mycompany.com/CookieAuth.dll?Logon';
document.forms(0).submit();
</script>
ASKER
Forgive me, Tim. Thanks for your prompt response, but I am a complete newbie at asp.net programming. How would I make the value assignments to javascript in this case?
<input name="username" value="username.value" type="hidden" class="txt" id="username" runat="server" />
<input name="password" value="password.value" type="hidden" class="txt" id="username" runat="server" />
<input name="username" value="username.value" type="hidden" class="txt" id="username" runat="server" />
<input name="password" value="password.value" type="hidden" class="txt" id="username" runat="server" />
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I think I understand what you're saying now, Tim.
But, when I add the suggested code I get an error:
username.value = "exchangetest1"
Error:
Name 'username' is not declared
But, when I add the suggested code I get an error:
username.value = "exchangetest1"
Error:
Name 'username' is not declared
ASKER
OK, I am past that error. I just needed to put ID="username" in the input box.
But how should I code the value= in the input box?
Should it automatically overwrite the default value currently in the string?
<input name="username" value="exchangetest1" type="hidden" class="txt" id="username" runat="server" />
But how should I code the value= in the input box?
Should it automatically overwrite the default value currently in the string?
<input name="username" value="exchangetest1" type="hidden" class="txt" id="username" runat="server" />
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Closing
ASKER
Closing
ASKER
Closing my account.
Simplest is as below, simply adding runat="server" allows you to assign values directly.
Regards,
TimCottee
Open in new window