Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submit form from Hyperlink

Status
Not open for further replies.

DH

Programmer
Dec 8, 2000
168
0
0
Is there a way to submit a form from a hyperlink and use the querystring at that same time?

Instead of using the submit button I would like to the form submitted when the user clicks a hyperlink. I also would like to attach querystring info to the hyperlink such as:

<a href=&quot;webpage.asp?contactid=<% =objRS(&quot;ID&quot;)%>&quot;</a>

How can I get this hyperlink to submit the webpage and carry the querystring info?

Thanks,

DH
 
Ok, say you have a form like so:
Code:
<form method=&quot;POST&quot; action=&quot;wherever.asp&quot; name=&quot;frmSample&quot;>

You could submit the form like so:
Code:
<a href=&quot;#&quot; onClick=&quot;frmSample.submit();&quot;>Submit</a>

Now in order to add your variables to the querytring, rather than add them to the address in the anchor (which we don't want to use, as we would like to submit the form) we can add them to the action in the form like so:
Code:
<A href=&quot;#&quot; onClick=&quot;frmSample.action='wherever.asp?contactid=?<%=objRS(&quot;ID&quot;)%>';frmSample.submit();&quot;>

A second option is to create a hidden field and populate it using the onClick:
Code:
<input type=&quot;hidden&quot; name=&quot;contactid&quot; value=&quot;&quot;>
<a href=&quot;#&quot; onClick=&quot;frmSample.contactid.value='<%=objRS(&quot;ID&quot;)%>';frmSample.submit();&quot;>

Hope that helps,
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Thanks, worked great!

DH
 
I'm trying to do something very similar except I'm looping through a recordset and creating multiple hyperlinks. My problem is when I post to my target page the request variable is receiving the value of every hidden text box (hyperlink) instead of just the one that was clicked.

<%if(!RST.eof && !RST.bof){%>
<%while(!RST.eof){%>
<form method=&quot;POST&quot; action=&quot;Test.asp&quot; name=&quot;frmTest&quot;>
<table>
<tr>
<td>
<input type=&quot;hidden&quot; name=&quot;userid&quot; value=&quot;<%=RST(&quot;user_id&quot;).value%>&quot;>
<a href=&quot;#&quot; onClick=&quot;frmTest.userid.value='<%=RST(&quot;user_id&quot;).value%>';frmTest.submit();&quot;><%=RST(&quot;user_id&quot;).value%></a>
</td>
</tr>
<%
RST.MoveNext();
}%>
<%DestroyRecordSet(RST);
}%>
</table>
</form>

Thanks,
-Ic
 
Move things around a bit and change some names like this:
Code:
<%if(!RST.eof && !RST.bof){
x == 0 %>
<%while(!RST.eof){
x += 1
%>
<form method=&quot;POST&quot; action=&quot;Test.asp&quot; name=&quot;frmTest_<%=x%>&quot;>
<table>
<tr>
<td>
<input type=&quot;hidden&quot; name=&quot;userid_<%=x%>&quot; value=&quot;<%=RST(&quot;user_id&quot;).value%>&quot;>
<a href=&quot;#&quot; onClick=&quot;frmTest.userid_<%=x%>.value='<%=RST(&quot;user_id&quot;).value%>';frmTest_<%=x%>.submit();&quot;><%=RST(&quot;user_id&quot;).value%></a>
</td>
</tr>
</table>
</form>
<%
RST.MoveNext();
}%>
<%DestroyRecordSet(RST);
}%>

For each time through the loop you're create a new form with a new name containing a new hidden field with a new name. The result should be that only one value is posted to the Test.asp page. Please excuse any javascript syntax errors. This should give you an idea anyway.
 
Thanks Veep!

Works good. I just had to also post the value of the x variable too in order for the target page to reference the correct form name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top