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

Persistent Variable when Passing via URL

New Here ,
May 12, 2006 May 12, 2006

Copy link to clipboard

Copied

Hi,

I am passing a number of variables via URL in order to sort a dataset. The problem I have is that if I also have a submit form on the same page, such as a dropdown to select a certain status, or a list of items that I can checkmark, the variable that I originally passed with the URL seems to override whatever I enter in the form, keep in mind that the form and the URL variable have the same name, which they must have in order to work correctly. Is there a way to release the passed variable when I submit on the form? Or perhaps I should pursue a different solution for data sorting?

I've condensed the code below, the "sorter" variable is passed by the column header so that the same criteria is passed into the updated page in order to properly sor the same set of data that was originally presented. But if I want to change my "sorter" criteria to something else by selecting it from the dropdown list I get the old "sorter" data that I was previously looking at. Somehow I need to be able to release the "sorter" variable so that I can submit a fresh variable. I have the same problem in different code using check boxes to create a select list to narrow the dataset.

Thanks in advance for any suggestions.

<cfquery name="tsts" datasource="#dsname#">
SELECT *
FROM tst
where status=#stats#
order by #sort_order#
<cfif sort eq 1>
desc
</cfif>

</cfquery>
<form action="" method="post">
<table>
<cfif sort neq 1>
<th><a href="tst.cfm?sort_order=id1&sort=1&stats=#x#>Item 1:</a></th>
<th><a href="tst.cfm?sort_order=id2&sort=1&stats=#x#>Item 2:</a></th>
<cfelse>
<th><a href="tst.cfm?sort_order=id1&sort=2&stats=#x#>Item 1:</a></th>
<th><a href="tst.cfm?sort_order=id2&sort=2&stats=#x#>Item 2:</a></th>
</cfif>

<cfoutput query="tsts">
<tr>
<td>#id1#</td>
<td>#id2#</td>
</cfoutput>
</table>
<select name="stats" onChange="submit()">
<option></option>
<option>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
</select>
</form>
TOPICS
Advanced techniques

Views

352

Translate

Translate

Report

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

LEGEND , May 12, 2006 May 12, 2006
If you don't scope your variables, cold fusion looks for url variables before looking for form variables. Create a local variable that gets set to the form variable if it exists and the url variable if the form variable is not there and use the local variable in your query.

Votes

Translate

Translate
LEGEND ,
May 12, 2006 May 12, 2006

Copy link to clipboard

Copied

If you don't scope your variables, cold fusion looks for url variables before looking for form variables. Create a local variable that gets set to the form variable if it exists and the url variable if the form variable is not there and use the local variable in your query.

Votes

Translate

Translate

Report

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
New Here ,
May 12, 2006 May 12, 2006

Copy link to clipboard

Copied

Thanks Dan,

I was looking at scoped variables as well as caching earlier but was not sure that I was looking in the right direction. I'll have to do some more research to understand how to properly scope my variables so that this behaviour does not exist anymore.

Off the top of my head, if I remember correctly, I would differentiate the scoping as form.var vs. url.var, is that right?

Cheers

Votes

Translate

Translate

Report

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
LEGEND ,
May 12, 2006 May 12, 2006

Copy link to clipboard

Copied

LATEST
quote:

Originally posted by: Suva1
Thanks Dan,

I was looking at scoped variables as well as caching earlier but was not sure that I was looking in the right direction. I'll have to do some more research to understand how to properly scope my variables so that this behaviour does not exist anymore.

Off the top of my head, if I remember correctly, I would differentiate the scoping as form.var vs. url.var, is that right?

Cheers

That's correct.

Votes

Translate

Translate

Report

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
New Here ,
May 12, 2006 May 12, 2006

Copy link to clipboard

Copied

Dan,

Many thanks! Your quick and accurate answer really helped prevent a very frustrating day. I've been looking for an answer to this for a few days. It took a wee bit of fiddling to work it out but now it's perfect! I really appreciate the help!

Cheers

Votes

Translate

Translate

Report

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
Documentation