Panos
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 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>
What's the problem?
Replace all URL. structs with FORM. structs.
Like this:
="#Url.nrecords#">
Will be:
="#FORM.nrecords#">
Also show what your JavaScript function slappy() is doing.
Like this:
="#Url.nrecords#">
Will be:
="#FORM.nrecords#">
Also show what your JavaScript function slappy() is doing.
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=R esults<cfi f (isdefined("form.pagenumbe r"))>&page number=#fo rm.pagenum ber#</cfif >" method="post" name="changy" id="changy">
<div align="right">Ergebnisse pro Seite :
<select id="nrecords"name="nrecord s" onChange="slappy();" class="Resultnumber">
<cfloop index="kk" list="5,10,20,30,50,100">
<option value="<cfoutput>#kk#</cfo utput>"
<cfif kk is form.nrecords>selected</cf if> > <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\Re sults.cfm: line 705
704 : <cfset MaxRows_WADAdboartikel="#f orm.nrecor ds#">
705 : <cfset StartRow_WADAdboartikel=Mi n((PageNum _WADAdboar tikel-1)*M axRows_WAD Adboartike l+1,Max(WA DAdboartik el.RecordC ount,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?nrecor ds=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.
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=R
<div align="right">Ergebnisse pro Seite :
<select id="nrecords"name="nrecord
<cfloop index="kk" list="5,10,20,30,50,100">
<option value="<cfoutput>#kk#</cfo
<cfif kk is form.nrecords>selected</cf
</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\Re
704 : <cfset MaxRows_WADAdboartikel="#f
705 : <cfset StartRow_WADAdboartikel=Mi
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?nrecor
<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.
<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>
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>
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="" />
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="" />
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?nrecor ds=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.su bmit()">20 </a>
</form></li>
<li><form action="Results.cfm?nrecor ds=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.su bmit()">50 </a>
</form></li>
<li><form action="Results.cfm?nrecor ds=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.s ubmit()">1 00</a>
</form></li>
</ul>
Something like that:
<ul>
<li><form action="Results.cfm?nrecor
<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.su
</form></li>
<li><form action="Results.cfm?nrecor
<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.su
</form></li>
<li><form action="Results.cfm?nrecor
<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.s
</form></li>
</ul>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.