Skip to main content
Inspiring
January 22, 2014
Answered

How to submit form by clicking on hyperlinks

  • January 22, 2014
  • 2 replies
  • 1155 views

Hi there,

I've an <a href="a">A</a> and <a href="b">B</a>.  I want to know which letter user cliked on so that I can run a database query.

How can I do this. Any ideas?

Thanks

Joe Green

This topic has been closed for replies.
Correct answer Fernis

This is not really a ColdFusion issue, rather a Javascrip/HTML question, unless you want to do a background Ajax query with CF.

Anyway, I would trigger javascript events, filling up a hidden form field with either "a" or "b", then submitting the form.

In the style of:

<a href="javascript:document.getElementById('myhiddenformfield').value='a';document.getElementById('myform').submit();">A</a>

<a href="javascript:document.getElementById('myhiddenformfield').value='b';document.getElementById('myform').submit();">B</a>

<cfform name="myform" id="myform" method="post" action="...">

<cfinput type="hidden" name="myhiddenformfield">

...

</cfform>

Hope this helps?

2 replies

BKBK
Community Expert
January 24, 2014

If user clicks on link A he will be sent to page a. If he clicks on B he will be sent to page b. So, the page where he lands correponds to the link he clicked.

It is therefore enough for you to know the landing page, where you currently are after the click. In most platforms, you can usually find it by combining the strings CGI.HTTP_HOST and CGI.REQUEST_URI. For example, in ColdFusion, this is

current_url = CGI.HTTP_HOST & CGI.REQUEST_URI;

However, you may want to know whether the user is coming here from the original page that contains the links A and B. Suppose that the original page's URL is c. Then the code to implement on page a and b is something like

clicked_url_on_page_c = "";

if (CGI.HTTP_REFERER == c) {

     /* Then user coming in from c by means of click */

     clicked_url_on_page_c = CGI.HTTP_HOST & CGI.REQUEST_URI;

}

Fernis
Inspiring
January 27, 2014

>If user clicks on link A he will be sent to page a. If he clicks on B he will be sent to page b. So, the page where he lands correponds to the link he clicked.

I think you misread the question or missed the point. He was asking about submitting forms by clicking a hyperlink.

The href's were there clearly for no purpose, as a sign of needing a clue.

BKBK
Community Expert
January 27, 2014

Cheers, Fernis. So he did! However, I didn't misread his question. I missed the title.

Fernis
FernisCorrect answer
Inspiring
January 23, 2014

This is not really a ColdFusion issue, rather a Javascrip/HTML question, unless you want to do a background Ajax query with CF.

Anyway, I would trigger javascript events, filling up a hidden form field with either "a" or "b", then submitting the form.

In the style of:

<a href="javascript:document.getElementById('myhiddenformfield').value='a';document.getElementById('myform').submit();">A</a>

<a href="javascript:document.getElementById('myhiddenformfield').value='b';document.getElementById('myform').submit();">B</a>

<cfform name="myform" id="myform" method="post" action="...">

<cfinput type="hidden" name="myhiddenformfield">

...

</cfform>

Hope this helps?