sylunt1 Posted May 15, 2006 Share Posted May 15, 2006 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 BROWSERSvar 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 priceitem 2 product info price[empty] product info priceHow can I make it do that?Thanks,Chris Quote Link to comment https://forums.phpfreaks.com/topic/9683-hopefully-simple-solution/ Share on other sites More sharing options...
_will Posted May 15, 2006 Share Posted May 15, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/9683-hopefully-simple-solution/#findComment-35866 Share on other sites More sharing options...
sylunt1 Posted May 15, 2006 Author Share Posted May 15, 2006 Almost... now none of the manufacturers show up... its all blank... Quote Link to comment https://forums.phpfreaks.com/topic/9683-hopefully-simple-solution/#findComment-35871 Share on other sites More sharing options...
emehrkay Posted May 15, 2006 Share Posted May 15, 2006 yes the solution is simple (i hope it works for ya :)if(i !=0 && part[i-1] != part[i]){display part[i]}else{display nothing} Quote Link to comment https://forums.phpfreaks.com/topic/9683-hopefully-simple-solution/#findComment-35873 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.