Fix existing JavaScript (code included)

This project was awarded to soner for $30 USD.

Get free quotes for a project like this
Project Budget
$30 - $100 USD
Total Bids
Project Description

Hi there. We need some help with a JavaScript I've started, but I just started learning JS so I wasn't able to complete the script myself.

What we want the JavaScript to do is to show/hide table rows. The problem is that we want to hide two different types of table rows, and that's where the problem occurs...

We can't really disclose the real tables and rows, but think of it like the following:

You have a table with a lot of rows (three cells) about cars:

Car Name - Model - Price

There is also a checkbox in front of every row so people can check off what cars they already have, and a script (we have already created the script, so we don't need that) stores that in the database. When the page is loaded, all rows that the user has marked, will be tagged with <tr title="car">, and the link:

<a href="javascript:toggle('aa');">Show/hide A</a> , will show/hide all those cars.

But also visualise that the script is made to mark every car that is of the make Mercedes with <tr id="mercedes">. The link:

<a href="javascript:toggle('bb');">Show/hide B</a> , will show/hide every car of the model Mercedes.

The problem:

When a user selects a Mercedes as a car he already has, the table row code becomes:

<tr title="car" id="mercedes">

Both links works excellent one at the time, but not if the user first tries to click link A (show/hide all his cars), than link B (show/hide all Mercedes cars), and than click link A again.

What we also would want is to replace the:

$('aa').setHTML(''); code, so we don't have to use the mootools library (only using it for this purpose).

Current Code:

function toggle(attr) {

tr=[url removed, login to view]('tr')

var j = 0;

var k = 0;

for (i=0;i<[url removed, login to view];i++){

if (tr[i].getAttribute(attr)){

if (tr[i].style.display=='none' ) {

tr[i].[url removed, login to view] = '';

if (attr=='title')

$('aa').setHTML('Status: <font color="red"><b>Visible</b></font>');

if (attr=='id')

$('bb').setHTML('Status: <font color="red"><b>Visible</b></font>');


else {

tr[i].[url removed, login to view] = 'none';

if (attr=='title' && attr=='id') {




if (attr=='title') {



if (attr=='id') {



$('aa').setHTML('Status: <font color="red"><b>' + (j/2) + ' hidden</b></font>');

$('bb').setHTML('Status: <font color="red"><b>' + (k/2) + ' hidden</b></font>');





Awarded to:
Skills Required

Looking to make some money?

  • Set your budget and the timeframe
  • Outline your proposal
  • Get paid for your work

Hire Freelancers who also bid on this project

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online