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
Who is Participating?

Improve company productivity with a Business Account.Sign Up

bwasyliukConnect With a Mentor Commented:
Sorry - I see it now...

The code::::::  style="background-color:<cfoutput>#highlightcolor#</cfoutput>;">

that you have on your DIV - should be on the TR

Also, you are checking SESSION.A_OrdEntry.RowButton but you should be checking a form variable that has been submitted back to the server...
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">
  <cfset variables.highlightcolor = "White">
<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.

CaridAuthor Commented:
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">
  <cfset highlightcolor = "white">

<cfinput type="hidden" name="InstID" value="#getOrderLine.InstID#">
<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>

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

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

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...?
CaridAuthor Commented:
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">
            <cfset bgcolor = "white">
   <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>

Thanks for your help

cheers Cari
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.