funstad Posted February 20, 2015 Share Posted February 20, 2015 (edited) Hey all, I'm looking for a way to mark all matching id's So if a id is found more then one time it has to been marked (red in jsfiddle) I already solved it for 1 id but now I'm searching to do this for multiple id's. Look on jsfiddle for what i already achieved . http://jsfiddle.net/Crezzur/7wk27w5d/ Edited February 20, 2015 by funstad Link to comment Share on other sites More sharing options...
davej Posted February 20, 2015 Share Posted February 20, 2015 Oh, you have your own data-id. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 20, 2015 Share Posted February 20, 2015 Your code shows a function to highlight a single value, couldn't you just call that function multiple times with different values? Link to comment Share on other sites More sharing options...
funstad Posted February 20, 2015 Author Share Posted February 20, 2015 (edited) I'm looking for a way that it automatic search for all values and not only 1 specif so im also trying to get rid off highlight('4'); So it needs to highlight all data-convid="id" that's shown more than 1 time I have a comparison table and every feature has it own idfor example screen color = (1) Black, (2) Red, (3) GreenWeight = (4) 1kg, (5) 5kg, (6) 11kgAnd when people compare two or more products i want to search by the id number if it is shown more than 1 time on the page, if it is shown more than one time products has the same value. This is my goal: same features are getting marked with green color. Edited February 20, 2015 by funstad Link to comment Share on other sites More sharing options...
davej Posted February 20, 2015 Share Posted February 20, 2015 Dump jQuery. This problem is trivial in plain vanilla Javascript. Link to comment Share on other sites More sharing options...
funstad Posted February 20, 2015 Author Share Posted February 20, 2015 Could you assist me ? my javascript / jquery is really bad I'm trying to search the Internet and put something together I'm already happy i got this far Link to comment Share on other sites More sharing options...
davej Posted February 20, 2015 Share Posted February 20, 2015 So, am I understanding that you want to search the entire document for duplicate data-convid attribute values inside td elements? Link to comment Share on other sites More sharing options...
funstad Posted February 20, 2015 Author Share Posted February 20, 2015 (edited) Yes that my goal so that when I'm starting a comparison it automatically color the field which are the same in green.as you can see here http://dev.fietsendezwaluw.be/webshop/index.php?controller=products-comparison&compare_product_list=1|3 multiple features are active and i want to mark the ones that are the same so my customers see much better which different there is between products Edited February 20, 2015 by funstad Link to comment Share on other sites More sharing options...
davej Posted February 20, 2015 Share Posted February 20, 2015 Perhaps something like... <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><title>title</title><style>table, th, td { border: 1px solid black; }</style><script>window.onerror = function(a, b, c, d){alert('Javascript Error:n'+a+'nURL: '+b+'nLine: '+c+' Column: '+d);return true;}</script><script>'use strict';window.onload = init;function init() {document.getElementById('btn1').onclick = searchdups;}function searchdups(){ var list = document.getElementsByTagName('TD'); var attr; var seen = []; var dups = []; for (var i=0, len=list.length ; i<len ; i++){ attr = list[i].getAttribute('data-convid'); if(attr != null){ if (seen.indexOf(attr)==-1){ seen.push(attr); }else{ if (dups.indexOf(attr)==-1){ dups.push(attr); } } } } for (var i=0, len=list.length ; i<len ; i++){ attr = list[i].getAttribute('data-convid'); if (attr!=null && dups.indexOf(attr)!=-1){ list[i].style.backgroundColor = 'green'; } }}//end of function</script></head><body><table><tr> <td class="message">Screensize</td> <td data-convid="4" class="conversationid">Screen 4"</td> <td data-convid="8" class="conversationid">Screen 8"</td> <td data-convid="4" class="conversationid">Screen 4"</td></tr><tr> <td class="message">Color</td> <td data-convid="11" class="conversationid">Green</td> <td data-convid="11" class="conversationid">Green</td> <td data-convid="15" class="conversationid">Black</td></tr></table><br/><input type="button" id="btn1" value="Search for dups"></body> </html> 1 Link to comment Share on other sites More sharing options...
funstad Posted February 20, 2015 Author Share Posted February 20, 2015 Amazing! you just made my day! i was searching for this for so long! damn :/ If you are payed by w3schools i should ask a wage increase! Link to comment Share on other sites More sharing options...
justsomeguy Posted February 20, 2015 Share Posted February 20, 2015 I'll put in a 20% raise for him. He'll keep the same insurance plan. 1 Link to comment Share on other sites More sharing options...
funstad Posted February 20, 2015 Author Share Posted February 20, 2015 can u increase his insurance plan ? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 20, 2015 Share Posted February 20, 2015 OK, I'll increase his benefits by 20%. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now