Link to home
Start Free TrialLog in
Avatar of SouthDallas40
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?
<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>

Open in new window

Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Hello SouthDallas40,

Simplest is as below, simply adding runat="server" allows you to assign values directly.

Regards,

TimCottee

  <script runat="server">         
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)        
          username.value = somevalue
          password.value = somevalue             
      End Sub
  </script>  
      <input name="username" value="exchangetest1" type="hidden" class="txt" id="username" runat="server" />
      <input name="password" value="12345" type="hidden" class="txt" id="password" onfocus="g_fFcs=0" runat="server"/>        
  <script type="text/javascript">  
    document.forms(0).action='https://email.mycompany.com/CookieAuth.dll?Logon';
    document.forms(0).submit();
 </script>

Open in new window

Avatar of SouthDallas40
SouthDallas40

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" />

 
SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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" />
 
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Closing
Closing
Closing my account.