Link to home
Start Free TrialLog in
Avatar of Panos
PanosFlag for Germany

asked on

How to change the MaxRows

Hello experts.
I have a search page with a search form and a result page.
Using the :
<cfoutput>
<cfloop index="thefield" list="#form.fieldnames#">
<input type="hidden" name="#thefield#" value="#form[thefield]#" />
</cfloop>
</cfoutput> in forms i could handle the sortby function (f.e. price asc ...)but i have a problem to handle now the number of results on each page.
Any help?


I did try this code in the past but now i must use method post so it is not working .
<cfset MaxRows_WADAdboartikel="#Url.nrecords#">
<cfset StartRow_WADAdboartikel=Min((PageNum_WADAdboartikel-1)*MaxRows_WADAdboartikel+1,Max(WADAdboartikel.RecordCount,1))>
<cfset EndRow_WADAdboartikel=Min(StartRow_WADAdboartikel+MaxRows_WADAdboartikel-1,WADAdboartikel.RecordCount)>
<cfset TotalPages_WADAdboartikel=Ceiling(WADAdboartikel.RecordCount/MaxRows_WADAdboartikel)>
<cfset QueryString_WADAdboartikel=Iif(CGI.QUERY_STRING NEQ "",DE("&"&XMLFormat(CGI.QUERY_STRING)),DE(""))>
<cfset tempPos=ListContainsNoCase(QueryString_WADAdboartikel,"PageNum_WADAdboartikel=","&")>
 
 
<form action="Results.cfm?lite=Results<cfif (isdefined("url.pagenumber"))>&pagenumber=#url.pagenumber#</cfif>" method="get" name="changy" id="changy">
      <div align="right">Ergebnisse pro Seite :
        <select  id="nrecords"name="nrecords" onChange="slappy();" class="Resultnumber">
            <cfloop index="kk" list="5,10,20,30,50,100">
              <option value="<cfoutput>#kk#</cfoutput>" 
	  <cfif kk is Url.nrecords>selected</cfif> > <cfoutput>#kk#</cfoutput> </option>
            </cfloop>
          </select>
<cfoutput>
<cfloop index="thefield" list="#form.fieldnames#">
<input type="hidden" name="#thefield#" value="#form[thefield]#" />
 
</cfloop>
</cfoutput>
      </div>
    </form>

Open in new window

Avatar of Jones911
Jones911

What's the problem?
Avatar of Zvonko
Replace all URL. structs with FORM. structs.
Like this:
="#Url.nrecords#">

Will be:
="#FORM.nrecords#">

Also show what your JavaScript function slappy() is doing.

Avatar of Panos

ASKER

Hi
The slappy is:
<script language="JavaScript">
<!--
     function slappy() {
          document.changy.submit();
     }
//-->
</script>

The problem i have using all form variables like:
<form action="Results.cfm?lite=Results<cfif (isdefined("form.pagenumber"))>&pagenumber=#form.pagenumber#</cfif>" method="post" name="changy" id="changy">
      <div align="right">Ergebnisse pro Seite :
        <select  id="nrecords"name="nrecords" onChange="slappy();" class="Resultnumber">
            <cfloop index="kk" list="5,10,20,30,50,100">
              <option value="<cfoutput>#kk#</cfoutput>"
        <cfif kk is form.nrecords>selected</cfif> > <cfoutput>#kk#</cfoutput> </option>
            </cfloop>
          </select>
<cfoutput>
<cfloop index="thefield" list="#form.fieldnames#">
<input type="hidden" name="#thefield#" value="#form[thefield]#" />

</cfloop>
</cfoutput>
      </div>
    </form>

is that it is working only the first time because for the second time there are passing two variables for nrecords and i have an error.
 The value 30,20 cannot be converted to a number.
 
The error occurred in C:\Inetpub\wwwroot\test\Results.cfm: line 705

704 : <cfset MaxRows_WADAdboartikel="#form.nrecords#">
705 : <cfset StartRow_WADAdboartikel=Min((PageNum_WADAdboartikel-1)*MaxRows_WADAdboartikel+1,Max(WADAdboartikel.RecordCount,1))>

I thing the best way would be to handle the nrecords as a Url variable and keep the other form variables untouched
For one it would be simple:
<form action="Results.cfm?nrecords=20">
<cfoutput>
<cfloop index="thefield" list="#form.fieldnames#">
<input type="hidden" name="#thefield#" value="#form[thefield]#" />

</cfloop>
</cfoutput>
      </div>
    </form>

but for a form with select box i don't know how to do this.
You do this and wonder that you have two times nrecords and therefore two times the values for the field nrecords:
<cfoutput>
<cfloop index="thefield" list="#form.fieldnames#">
<input type="hidden" name="#thefield#" value="#form[thefield]#" />

</cfloop>
</cfoutput>

The values for fields with the same name are submitted as list of values for one field name independant how many fields provided the value it is one field name and a list of values.
Or in simple word: by doing upper cfloop you repeat every form field to be also hidden form field with same name and double so every field value.

One solution could be to stop that cfloop or other solution to let the hidden field have some prefix or suffix in the field name.
Like this:

<cfoutput>
<cfloop index="thefield" list="#form.fieldnames#">
  <input type="hidden" name="hf_#thefield#" value="#form[thefield]#" />
</cfloop>
</cfoutput>
Avatar of Panos

ASKER

Hi zvonko.
Using your last code is solving the problem with the nrecords but this way all the names of the hidden form items do change and the results query that depends on these values does not work.
(
<input type="hidden" name="S_Pricefrom" value="" />

<input type="hidden" name="S_Priceto" value="" /> is going to be:

<input type="hidden" name="HF_S_Pricefrom" value="" />

<input type="hidden" name="HF_S_Priceto" value="" />  and the next time:

<input type="hidden" name="HF_HF_S_Pricefrom" value="" />

<input type="hidden" name="HF_HF_S_Priceto" value="" />


Avatar of Panos

ASKER

What do you thing about the idea to build a dropdown list (like a menu) with 3 menu items to look like a select box?
Something like that:
<ul>
<li><form action="Results.cfm?nrecords=20"  method="post" name="Set20" id="Set20">
<cfif isDefined( 'form.fieldnames' )>                
  <cfoutput>
   <cfloop index="thefield" list="#form.fieldnames#">
   <input type="hidden" name="#thefield#" value="#form[thefield]#" />
   </cfloop>
   </cfoutput>
   </cfif>
<a href="#" onClick="document.Set20.submit()">20</a>
   </form></li>
   <li><form action="Results.cfm?nrecords=50"  method="post" name="Set50" id="Set50">
<cfif isDefined( 'form.fieldnames' )>                
  <cfoutput>
   <cfloop index="thefield" list="#form.fieldnames#">
   <input type="hidden" name="#thefield#" value="#form[thefield]#" />
   </cfloop>
   </cfoutput>
   </cfif>
<a href="#" onClick="document.Set50.submit()">50</a>
   </form></li>
   <li><form action="Results.cfm?nrecords=100"  method="post" name="Set100" id="Set100">
<cfif isDefined( 'form.fieldnames' )>                
  <cfoutput>
   <cfloop index="thefield" list="#form.fieldnames#">
   <input type="hidden" name="#thefield#" value="#form[thefield]#" />
   </cfloop>
   </cfoutput>
   </cfif>
<a href="#" onClick="document.Set100.submit()">100</a>
   </form></li>
   </ul>
SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia 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
Avatar of Panos

ASKER

I have a search page a result page a detail page and a shopping "bag".
On the last 3 pages i have links to:
New Search (searchpage) ,Change search kriteria (searchpage).
On the detail and shopping bag i have link to the search page like the two above and back to the result page.
Because i don't want to handle this with session i pass the sarchform values from one page to the other and  back again.(see:https://www.experts-exchange.com/questions/24391703/Pass-form-values-in-coldfusion.html)
ASKER CERTIFIED SOLUTION
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