1

This should be really simple but what i'm doing is pulling data from a mysql db in php into a table and what i'd like to do is when i click a cell in the ID column, for it to turn white. i can get that to work but once it does one it doesnt do another!?

$('#addtocart').click(function(){
                $('#addtocart').css("color","white");
                return false;
});

In my php i'm doing this:

while($row = mysql_fetch_array($result))
                    {       
                        echo "<tr>";
                        echo "<td id='addtocart'>" . $row['id'] . "</td>";
                        echo "<td>" . $row['om_part_no'] . "</td>";
                        echo "<td>" . $row['supplier_part_no'] . "</td>";
                        echo "<td>" . $row['category'] . "</td>";
                        echo "<td>" . $row['description'] . "</td>";
                        echo "<td>" . $row['manufacturer'] . "</td>";
                        echo "<td>" . $row['list_price'] . "</td>";
                        echo "<td>" . $row['discount'] . "</td>";
                        echo "<td>" . $row['price_each_nett'] . "</td>";
                        echo "</tr>";
                    }
                echo "</tbody>
                </table>";

Should this be causing me this many problems!?

2 Answers 2

1

You are doing that only for the element with id="addtocart".

I would change it and make it that every element with class="addtocart" onclick will become white.

$('.addtocart').click(function(){
$(this).css("color","white");
return false;
});

And use echo "td class='addtocart'" . $row['id'] . ""; onstead of ID. You should not have more than one element with the same ID.

P.S. How to add tabs in my code?

Sign up to request clarification or add additional context in comments.

2 Comments

So would change anything in the PHP code? if i "inspect element" in Firefox every cell in the id column has an id of "addtocart"...but no luck!
Just make it class="addtocart" not id="addtoclass". You could not many element with the same ID. The ID is unique for the document.
0

Maybe some mistakes:
1) Where is your open table tag <table>?
2) Is jQuery script included in to html?
3) Try to make the next thing. It can be helpful:

$(document).ready(function(){
   $('#addtocart').click(function(){
      $('#addtocart').css("color","white");
      return false;
   });
});

4) Install Firebug add-on for Firefox for debug JS errors.
5) Id should be an unique value. But you have more than 1 element with same id. Try to generate unique id.

1 Comment

I'm pretty sure the PHP is fine, i'm also using jQuery plugin "TableData" not sure if that is interfering!? I've done all the 3 things you put down...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.