Link to home
Start Free TrialLog in
Avatar of yo_bee
yo_beeFlag for United States of America

asked on

ASP Form Get Question

I have a very simple ASP for that I am trying to parse URL

 <form id="form1" runat="server" method="get" action=" https://commerce.wsj.com/auth/group/login?">
    <input type="hidden" name="groupSignOnId" value="XXXXXLaw"/>
    <input type="hidden" name="groupSignOnPassword" value="**********"/>
    <input type="text" name="groupUserKey"/>
    <input type="submit" value="WSJ.com"/>

Open in new window


And I have VB snippet that gets the current username.

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label1.Text = Environment.UserName()
    End Sub

Open in new window


I want to pass the username to the <input type="text" name="groupUserKey"/> Value=

The final goal of this whole this is to put a Hyperlink on our Intranet to redirect the user to a webpage with the imputs parsed in the URL.

I know it is probably super simple, but I am a newbie at this.
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America 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
Is this for classic asp?  

It would be better to use a function instead of a sub.  Then the function can return a value.  Are you getting the username from a querystring? or the sub/function?
<%
username= "yo_bee"  ' or request.querystring("user")
%>
<input type="text" name="groupUserKey" value="<%=username%>"/>

Open in new window

Avatar of yo_bee

ASKER

Your code changed worked for my preliminary test, but now if I want to put a hyperlink on my SharePoint page to redirect sort of like the form1.
since you're using the GET method in your form, you can just submit it. to do that using a <a> tag, put this in your form:

<a href="#" onclick="return document.form1.submit();">submit form</a>
Avatar of yo_bee

ASKER

but do I really need a form to do this?
Could I create a link to point to a code snippet?
it would be more code, but yes, you could. is there a specific reason you don't want to use a form?
keep in mind, this will pass ALL form data to the redirect page, and the page it goes to will be the one in the form action attribute. if you want to redirect to another page, then you'd have to create a custom form submit handler. if you don't mind ALL of the data going to another page, you could do:

<a href="#" onclick="document.form1.action = 'somePage.htm';  document.form1.submit();">submit form</a>
Avatar of yo_bee

ASKER

I am getting the username from the Protect Sub on load.

If there is a better way to get the username I am open to suggestions.
Avatar of yo_bee

ASKER

I do not think there is a need for a form since this will just me a link on the intranet page to parse a url and redirect it to WSJ.com/logon?
that's usually where you want to load data, I would say thats the best way to do it.
what variables do you want to pass to that page? is it just the user name or is it all of your hidden variables as well? if it's the latter, there's nothing wrong with using a form tag and just submitting the form on a link click. The browser will then parse out the values you want to send in the URL.

Why do you want to write code to do that?
then use a form, it's the easiest and quickest way to get your desired results
Avatar of yo_bee

ASKER

Thank you for all you help.