Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to submit form by clicking on hyperlinks

Explorer ,
Jan 22, 2014 Jan 22, 2014

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

TOPICS
Getting started
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jan 22, 2014 Jan 22, 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')

...
Translate
Enthusiast ,
Jan 22, 2014 Jan 22, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2014 Jan 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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 27, 2014 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2014 Jan 27, 2014
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources