Jump to content

Hopefully simple solution


sylunt1

Recommended Posts

Hello...

I am trying to do some basic js stuff and need a little help. I have the following code;

[code]
<script LANGUAGE="JavaScript">
<!-- HIDE FROM OTHER BROWSERS

var side = new Array("Oki 590-88", "Oki 590-79", "Oki 473C");
var top = new Array("Manufacturer", "Description", "OEM Price", "HDC Price");
                            

var manu = new Array("IBM", "IBM", "Okidata", "Okidata");
var part = new Array(976, 726, 590, 473);
var fits = new Array("2380, 2381, 2390, 2391", "3262, 5262", "590, 591", 120);
var price = new Array("6.00", "6.25", "16.50", "10.75");

document.write("<table border=1 width=95% cellspacing=0 height=1 cellpadding=1><tr><th>Manufacturer</th><th>Part</th><th>Fits Model</th><th>Price</th></tr>");

for (i=0; i<manu.length; i++){

  
document.write("<tr><td>", manu[i], "</td>",
"<td>", part[i], "</td>",
"<td>", fits[i], "</td>",
"<td>", price[i], "</td></tr>")


}
document.write("</table>");

// STOP HIDING FROM OTHER BROWSERS -->
</SCRIPT>
[/code]

It does what it is supposed to do, but what I want is this:
on the left column - if the item repeats I only want the word to show up one time - like this...

item 1 product info price
[empty] product info price
item 2 product info price
[empty] product info price

How can I make it do that?


Thanks,
Chris
Link to comment
Share on other sites

try this in your for loop...

[code]
var last = "";
var display = "";
for (i=0; i<manu.length; i++){
if (last == manu[i]) {
  display = manu[i];
  last = manu[i];
}
else {
  display = "";
}
  
document.write("<tr><td>", display, "</td>",
"<td>", part[i], "</td>",
"<td>", fits[i], "</td>",
"<td>", price[i], "</td></tr>")


}
[/code]

All I added was a variable to track the last product shown and then an if statement to see if the next product is the same as the last product shown. If it is, then no product name is printed.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.