Cashmgmt
asked on
I need a javascript button to move data from one table to another
I currently have a submit button that will move a field or all fields from the table on the left to the table on the right. I need to replace it with a javascript function. this is my javascript function:
function custRpt()
{
document.Form1.action = 'custRpt.cfm';
document.Form1.submit();
}
I have attached a copy of the cfm page. When I click on a field and click on the javascript link I created nothing happens. Same when I click the add all button. I'm new to this so I'm not sure what I'm doing wrong.
function custRpt()
{
document.Form1.action = 'custRpt.cfm';
document.Form1.submit();
}
I have attached a copy of the cfm page. When I click on a field and click on the javascript link I created nothing happens. Same when I click the add all button. I'm new to this so I'm not sure what I'm doing wrong.
<script language="javascript" src="inc/dcd.js"></script>
<link href="https://www.sovereignbank.com/inc/all.css" rel="stylesheet" type="text/css">
<style type="text/css"></style>
<cfset #pageTitle# = "Administration">
<cfset #curPage# = 77>
<cfset #custContent# = "AP1">
<cfset #LbxName# = RemoveChars(#session.lbxformattable#,1,8)>
<!---<cfif #Session.lbxtype# is "Wholesale">--->
<cfset #RptTableName# = "lbx_rpt_#LbxName#">
<!---<cfelse>
<cfset #RptTableName# = "rlb_rpt_#LbxName#">
</cfif>--->
<cfquery name = "checkforrpttable" datasource="#Application.dsname#">
SELECT * from sysobjects where name = '#RptTableName#'
</cfquery>
<cfif #checkforrpttable.Recordcount# is 0>
<cfquery name = "createrpttable" datasource = "#Application.dsname#">
SELECT * INTO #RptTableName# FROM #SESSION.LBXFORMATTABLE#
</cfquery>
<cfelse>
<cfquery name = "comparefmt" datasource = "#Application.dsname#">
SELECT * FROM #Session.LbxFormatTable# T1
WHERE (T1.layout = 'AP') AND
NOT EXISTS(SELECT * FROM #RptTableName# T2 where (T1.fld_order = T2.fld_order) and layout='AP')
</cfquery>
<cfif #comparefmt.RecordCount# gt 0>
<cfquery name = "insertintoReportTable" datasource = "#Application.dsname#">
INSERT INTO #RptTableName#(layout,fld_order,fld_name,fld_otype,fld_len,fld_dec,fld_prompt,fld_head1,fld_head2,can_modify,can_search,at_info,at_caption,at_trans,at_chkbody,at_invbody,at_cpnbody,at_support,at_report,rollup,total)
(SELECT * FROM
#Session.LbxFormatTable# T1
WHERE (T1.layout = 'AP') AND
NOT EXISTS(SELECT * FROM #RptTableName# T2 where (T1.fld_order = T2.fld_order) and layout='AP'))
</cfquery>
<cfelse>
<cfquery name = "comparerpt" datasource = "#Application.dsname#">
SELECT * FROM #RptTableName# T1
WHERE (T1.layout = 'AP') AND
NOT EXISTS(SELECT * FROM #Session.LbxFormatTable# T2 where (T1.fld_order = T2.fld_order)and layout='AP')
</cfquery>
<cfif #comparerpt.RecordCount# gt 0>
<cfloop query = "comparerpt">
<cfquery name="Del" datasource="#Application.dsname#">
DELETE FROM #RPTTableName# where (fld_order = #comparerpt.fld_order#) and (layout = 'AP')
</cfquery>
</cfloop>
</cfif>
</cfif>
<cfquery name ="checkforcan_search" datasource="#Application.dsname#">
SELECT T2.fld_name,T2.layout,T2.fld_order,T2.can_search FROM #RptTableName# T1,#Session.lbxFormatTable# T2 WHERE
(T1.layout = T2.layout) And (T1.layout = 'AP') AND
(T2.can_search <> T1.can_search) AND (T1.fld_name = T2.fld_name)
ORDER BY T1.fld_order
</cfquery>
<cfif #checkforcan_search.RecordCount# gt 0>
<cfloop query = "checkforcan_search">
<cfquery name = "updaterpttable" datasource= "#Application.dsname#">
UPDATE #RptTableName# SET can_search = #checkforcan_search.can_search#
WHERE (layout = 'AP') AND
(fld_name = '#checkforcan_search.fld_name#')
</cfquery>
</cfloop>
</cfif>
</cfif>
<cfif #ParameterExists(form.add)# AND #Len(Trim(form.add))# gt 0>
<!--- added isDefine to make sure form.flds exist --->
<cfif isdefined("form.Flds")>
<cfset #form.reportFields#="#form.reportFields#,#form.flds#">
</cfif>
</cfif>
<cfif #ParameterExists(form.addAll)# AND #Len(Trim(form.addAll))# gt 0>
<cfquery name="getAll" datasource="#Application.dsname#">
<!---SELECT fld_name, layout, can_search FROM #session.lbxformattable# WHERE layout='AP' AND can_search=1--->
SELECT fld_name, layout, can_search FROM #RptTableName# WHERE layout='AP' AND can_search=1
</cfquery>
<cfset #lcv# = 1>
<cfloop query="getAll">
<cfquery name="updateAll" datasource="#Application.dsname#">
<!---UPDATE #session.lbxformattable# SET at_report=#lcv# WHERE layout='AP' AND fld_name='#getAll.fld_name#'--->
UPDATE #RptTableName# SET at_report=#lcv# WHERE layout='AP' AND fld_name='#getAll.fld_name#'
</cfquery>
<cfset #lcv# = #lcv# + 1>
</cfloop>
</cfif>
<cfif #ParameterExists(form.remove)# AND #Len(Trim(form.remove))# gt 0>
<!--- added isDefine to make sure form.rptflds exist --->
<cfif isdefined("form.rptFlds")>
<cfset #tmpList# = #form.reportFields#>
<cfset #tmpFindVal# = #ListFindNoCase(tmpList, form.rptFlds, ",")#>
<cfif #tmpFindVal# gt 0>
<cfset #form.reportFields# = #ListDeleteAt(tmpList, tmpFindVal, ",")#>
<cfquery name="remove" datasource="#Application.dsname#">
<!---UPDATE #session.lbxformattable# SET at_report=0 WHERE layout='AP'--->
UPDATE #RptTableName# SET at_report=0 WHERE layout='AP'
</cfquery>
</cfif>
</cfif>
</cfif>
<cfif #ParameterExists(form.removeAll)# AND #Len(Trim(form.removeAll))# gt 0>
<cfset #form.reportFields# = "">
<cfquery name="removeAll" datasource="#Application.dsname#">
<!---UPDATE #session.lbxformattable# SET at_report=0 WHERE layout='AP'--->
UPDATE #RptTableName# SET at_report=0 WHERE layout='AP'
</cfquery>
</cfif>
<cfif (#ParameterExists(form.finished)# AND #Len(Trim(form.finished))# gt 0) OR
(#ParameterExists(form.add)# AND #Len(Trim(form.add))# gt 0) OR
(#ParameterExists(form.remove)# AND #Len(Trim(form.remove))# gt 0) OR
(#ParameterExists(form.removeAll)# AND #Len(Trim(form.removeAll))# gt 0)>
<cfset #lcv# = 0>
<cfloop index="fldName" list="#form.reportFields#">
<cfoutput>
<cfset #lcv# = #lcv# + 1>
<cfquery name="addRptFields" datasource="#application.dsname#">
<!---UPDATE #session.lbxformattable# SET at_report=#lcv# WHERE fld_name='#fldName#' AND layout='AP'--->
UPDATE #RptTableName# SET at_report=#lcv# WHERE fld_name='#fldName#' AND layout='AP'
</cfquery>
</cfoutput>
</cfloop>
</cfif>
<cfif #ParameterExists(form.finished)# AND #Len(Trim(form.finished))# gt 0>
<cfif #ParameterExists(form.reportFields)# AND #Len(Trim(form.reportFields))# gt 0>
<cfset #tmpUrl# = "custRpt.cfm?errMsg=Custom%20report%20updated">
<cfelse>
<cfset #tmpUrl# = "custRpt.cfm?errMsg=Unable%20to%20update%20custom%20report">
</cfif>
<cflocation url="#tmpUrl#">
<cfelse>
<cfinclude template="intra-main2.cfm">
<cfquery name="getMaxFields" datasource="#Application.dsname#">
<!---SELECT fld_name, layout, can_search FROM #session.lbxformattable# WHERE layout='AP' AND can_search=1--->
SELECT fld_name, layout, can_search FROM #RptTableName# WHERE layout='AP' AND can_search=1
</cfquery>
<cfquery name="getFields" datasource="#application.dsname#">
<!---SELECT * FROM #session.lbxformattable# WHERE layout='AP' and can_search=1 AND at_report=0 ORDER BY fld_name--->
SELECT * FROM #RptTableName# WHERE layout='AP' and can_search=1 AND at_report=0 ORDER BY fld_name
</cfquery>
<cfquery name="getRptFields" datasource="#application.dsname#">
<!---SELECT * FROM #session.lbxformattable# WHERE layout='AP' and at_report>0 ORDER BY at_report--->
SELECT * FROM #RptTableName# WHERE layout='AP' and at_report>0 ORDER BY at_report
</cfquery>
<p><br></p>
<cfif #ParameterExists(URL.errMsg)# AND #Len(Trim(URL.errMsg))# gt 0>
<p><div align="center"><font color="#Application.emphtext#"><b><cfoutput>#URL.errMsg#</cfoutput></b></font></div></p>
</cfif>
<p><br></p>
<CFSET tmpReportFields = #ValueList(getRptFields.fld_name)#>
<table style="border:1px solid #d1cdc6; margin-left:10px;">
<form name="Form1" method="post" action="custRpt.cfm">
<input type="hidden" name="reportFields" value="<cfoutput>#tmpReportFields#</cfoutput>">
<tr>
<td><font size="-2"><b>Available Fields:</b></font></td>
<td> </td>
<td><font size="-2"><b>Selected Fields:</b></font></td>
</tr>
<tr>
<td valign="top" bordercolor="#d1cdc6">
<select name="flds" size="<cfoutput>#getMaxFields.RecordCount#</cfoutput>">
<cfif #getFields.RecordCount# is 0>
<option value="">-- All Selected --</option>
<cfelse>
<cfoutput query="getFields">
<option value="#getFields.fld_name#">#getFields.fld_head1# #getFields.fld_head2#</option>
</cfoutput>
</cfif>
</select>
</td>
<td valign="top">
<a href="javascript:document.Form1.submit()" class="red10"><img src="images/double_arrow1_left.gif" border="0"> Remove</a>
<p><input type="submit" class="red10" name="add" value=" > "></p>
<a href="javascript: custRpt()" class="red10"><img src="images/double_arrow1_left.gif" border="0"> Remove All</a>
<p><input type="submit" class="red10" name="addAll" value=" >> "></p>
<a href="javascript: custRpt()" class="red10">Add <img src="images/double_arrow.gif" border="0"></a>
<p><input type="submit" class="red10" name="remove" value=" < "></p>
<a href="javascript: custRpt()" class="red10">Add All <img src="images/double_arrow.gif" border="0"></a>
<p><input type="submit" class="red10" name="removeall" value=" << "></p>
</td>
<td valign="top" bordercolor="#d1cdc6">
<select name="rptFlds" size="<cfoutput>#getMaxFields.RecordCount#</cfoutput>">
<cfif #getRptFields.RecordCount# is 0>
<option value="">-- None Selected --</option>
<cfelse>
<cfoutput query="getRptFields">
<option value="#getRptFields.fld_name#">#getRptFields.fld_head1# #getRptFields.fld_head2#</option>
</cfoutput>
</cfif>
</select>
</td>
</tr>
</form>
</table>
<p><br /></p>
<cfinclude template="footer.cfm">
</cfif>
ASKER
I copied the Custrpt function when I described my issue. the function is in another file I include in this one, that's why it's not in the code I pasted. when I click on remove, remove all, add, or add all, nothing happens. It submits cause the page refreshes, but the fields that I select do not move to the other table. I still have the original submit buttons in the code which work fine. i need to replace those with a link instead. Here's the function:
function custRpt()
{
document.Form1.action = 'custRpt.cfm';
document.Form1.submit();
}
function custRpt()
{
document.Form1.action = 'custRpt.cfm';
document.Form1.submit();
}
OK - Cool - just needed to check it wasn't supposed to be in that cf page.
The reason that nothing is happening is because the code is looking for the press of the button to act upon.
When you click on the "Add All" button it creates a variable called "addall" in the form scope. Take a look at line 83 in your above code. You'll see <cfif ParameterExists(form.addal l) ....>
What you'll need to do is recreate this with your javascript function. What I would recommend is creating a hidden field called something like "moveaction". On your link pass through the action that is being taken to your function eg. <a href="javascript:custRpt(' addall')" ...>
In your function set the hidden field you created to this value:
function custRpt(moveaction)
{
document.Form1.moveaction. value = moveaction;
document.Form1.action = 'custRpt.cfm';
document.Form1.submit();
}
What you'll need to do with the cf code is change all the references to form.add or form.addall etc. to be form.moveaction EQ "add" or form.moveaction EQ "addall" as appropriate. eg. line 83 would look like this:
<cfif StructKeyExists(form,"move action") AND form.moveaction EQ "addall">
Hope that makes sense and helps.
The reason that nothing is happening is because the code is looking for the press of the button to act upon.
When you click on the "Add All" button it creates a variable called "addall" in the form scope. Take a look at line 83 in your above code. You'll see <cfif ParameterExists(form.addal
What you'll need to do is recreate this with your javascript function. What I would recommend is creating a hidden field called something like "moveaction". On your link pass through the action that is being taken to your function eg. <a href="javascript:custRpt('
In your function set the hidden field you created to this value:
function custRpt(moveaction)
{
document.Form1.moveaction.
document.Form1.action = 'custRpt.cfm';
document.Form1.submit();
}
What you'll need to do with the cf code is change all the references to form.add or form.addall etc. to be form.moveaction EQ "add" or form.moveaction EQ "addall" as appropriate. eg. line 83 would look like this:
<cfif StructKeyExists(form,"move
Hope that makes sense and helps.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help! I was able to get it working using your sample code.
What are you click in on when you get no response? The "add all" button or the "add"+double arrow image?
There are somethings you also need to be aware of:
The coldfusion code you have there could do with some TLC.
For example.
<cfset #pageTitle# = "Administration"> only needs to be <cfset pageTitle = "Administration">
<cfif #comparefmt.RecordCount# gt 0> should be <cfif comparefmt.RecordCount gt 0>
<cfset tmpReportFields = #ValueList(getRptFields.fl
Also, ParameterExists is a deprecated coldfusion function and should be replaced with IsDefined() or StructKeyExists() eg. ParameterExists(form.finis