Link to home
Start Free TrialLog in
Avatar of Carid
Carid

asked on

Highlight a row when a button is clicked

I am using coldfusion and I want to be able to highlight a row in a recordset when an image button (row_btn) is clicked.

I have tried various options but whenever the row_btn is clicked the highlight disappears. This I assume is because the form is being submitted to the server.

The row_btn runs a query to retreive data specific to the id selected. It then displays the selected data in readonly form fields.

I am also storing the id to a session variable.

The recordset is in a div class called OrderDetails.

I want the highlight to remain on until another row is selected.

Please help.

thank you
Avatar of bwasyliuk
bwasyliuk

If your button is submitting back to the server - then you should have some kind of Row ID that you are using to get the details.

Assuming that - then when you are outputing the information - you can test for the row ID and highlight the appropriate row:

ex: (inside your CFloop or CFoutput of the query)

<cfif url.rowid eq myquery.rowid>
  <cfset variables.highlightcolor = "cfcfcf">
<cfelse>
  <cfset variables.highlightcolor = "White">
</cfif>
<div style="background-color:<cfoutput>#variables.highlightcolor#</cfoutput>;">the record detail goes here - if selected the row details will be highlighted.</div>

If I am off track, and you are trying to do something different - let me know.

Ben
www.scheduleforce.net
Avatar of Carid

ASKER

Hi Ben

Thanks for responding. I tried your solution but it didn't work.

I've included an extract of the code.  Maybe I'm missing something.
I've various method but to no avail.

What I want is the <TR> row to be highlighted when selected and remain selected until another is selected.

<cfform method="post" name="frmOrderEntry" ACTION="#cgi.script_name#"  >
<div class="OrdDetails" style="background-color:<cfoutput>#highlightcolor#</cfoutput>;">
<table >
<cfoutput query="getOrderLine">
  <cfif SESSION.A_OrdEntry.RowButton eq getOrderLine.instID>
    <cfset highlightcolor = "cfcfcf">
      <cfelse>
  <cfset highlightcolor = "white">
</cfif>

<cfinput type="hidden" name="InstID" value="#getOrderLine.InstID#">
<tr>
<td ><cfinput type="image" name="rowbutton"img src="/images/bullet.gif"       value="#getOrderLine.InstID#" /> </td>
  <td><cfInput type="text" name="SupplierName" value="#getOrderLine.SupplierName#" class="inputTxtLL" size = "25" Readonly="true"></td>
   
</tr>
</cfoutput>      
</table>
</div>
</cfform>


<cfif IsDefined('FORM.rowbutton.y')>

<cfset SESSION.A_OrdEntry.RowButton = #form.Rowbutton#>
</cfif>      

Thanks once again for your help
cheers Cari
I don't see in your code where you are looping to create the different rows of the recordset - am I missing something...?
ASKER CERTIFIED SOLUTION
Avatar of bwasyliuk
bwasyliuk

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 Carid

ASKER

Hi Ben
Sorry I've taken so long to get back. Been having problems with my ISP so no internet connection for a couple of days.

I've managed to sort it out.

I setup a hidden form with the value of the rowid and current row. (row_btn_#getOrderLine.CurrentRow#)
The code is as follows

<<cfinput type="Hidden" name="InsIDCount" value="#getOrderLine.RecordCount#">
      <cfoutput query="getOrderLine">
      <cfinput type= "hidden" name="row_btn_#getOrderLine.CurrentRow#" value="#getOrderLine.InstID#" />
      <cfif CurrentRow eq  #SESSION.A_OrdEntry.CurrentRow#>
           <cfset bgcolor = "blue">
      <cfelse>
            <cfset bgcolor = "white">
      </cfif>
   <tr bgcolor="#bgcolor#" >
    <td ><cfinput type="image"name="rowbutton"img src="images/bullet.gif"value="#getOrderLine.InstID#" /> </td>
    <td><cfinput name="delete_select"type="checkbox" value="#getOrderLine.InstID#" /></td>
    <td><cfInput type="text" name="SupplierName" value="#getOrderLine.SupplierName#" class="inputTxtLL" size = "25" Readonly="true"></td>


When the button is clicked it extracts the currentrow from row_btn_:

<cfif IsDefined('FORM.rowbutton.y')>
   <cfset SESSION.A_OrdEntry.RowButton = #form.Rowbutton#>
      <cfloop index="LoopCount" from=1 to=#Val(form.InsIDCount)#>
             <cfset variables.RowBtnID='form.row_btn_#Evaluate(LoopCount)#'>
            <cfif #evaluate(RowBtnID)# eq #form.Rowbutton#>
               <cfset SESSION.A_OrdEntry.CurrentRow = loopCount>
              </cfif>
       </cfloop>
</cfif>

Thanks for your help

cheers Cari