Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display HTML if javascript counts to certain number

Status
Not open for further replies.

jfilan

Technical User
Aug 2, 2007
4
US
Is it possible to show an image and link IF a some type of tag is repeated enough times? For example, my search results returns ten items per page and I want to insert HTML after the 5th item.

Each item is in a template that gets repeated over and over again on the results page.

Is it possible to add some type of javascript incremental counter in the template that gets repeated and then another javascript tag that says IF COUNTER=5 THEN WRITE= <a href="#"><img src=""></a> but IF COUNTER IS <5 OR >5 THEN WRITE=""

???

Has anyone ever done anything like this? IF so can you please point me in the right direction.
 
Whilst it can be done in Javascript, I would suggest you do it server-side. You can easily set up a loop arrangement to do this in PHP, JSP, .NET... all the usual suspects.

If you are lost on this, then best to post in the forum that suits the server-side solution you are using.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
It's just a simple HTML table that gets repeated over and over w/in the search results. If I gave the table an ID# and had javascript count the number of times the ID# was on the page, and then tell it to WRITE BLAH BLAH BLAH at the 5th time it counts the ID#... is that something someone could point me into the right direction w/?
 
Hi

jfilan said:
It's just a simple HTML table that gets repeated over and over w/in the search results.
And what puts those search results there ? Not a server-side script/program ?
jfilan said:
If I gave the table an ID# and had javascript count the number of times the ID# was on the page
The [tt]id[/tt]s must be unique per page. Otherwise they would not be called identifiers. Do not repeat them. If you want just to flag them, use a style [tt]class[/tt].
jfilan said:
tell it to WRITE BLAH BLAH BLAH at the 5th time it counts the ID#... is that something someone could point me into the right direction w/?
Well, what about posting your existing code/markup ? I am too lazy to write a solution which maybe will not fit the situation.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top