If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

I guess im confused on how to parse all the information seperatly when each stream list two "name" fields with slightly different info and as far as i can tell there is no distinction between each streams info as it pertains to the fields.

Ultimately i'm trying to get the following information on each stream into variables to pass back to the HTML on the page listing the streams

Name:
Viewers:
URL:
status:
preview:

If i just parse for "name" how to i pull multiple "name" fields from the proper channels... i guess i might not have a solid concept of how to parse complex data like this

*edit: I noticed the second "name" field is nested under the "channel" field.... is there something to referencing the object# + "channel" as well that would enable me to get that perticular "name"... im hoping im kind on the right path

Looking at the way you wrote your script i'm wondering if that is possible best practice to implement it onto my page...

I have a div with alot of formatting and other html and i had filler images, and ipsum text for the design process. Now i want to replace with the images and text im extracting from this JSON query....

If i use something likethis for instance

Code:

document.getElementById("streamlogo1").src=base[0].channel.logo;

Then there is a moment where the images are defualt and then change to the proper image....

Would the best practice way of implementing the JSON links and images be to use the document.write in the same mannor you did and just include the formatting HTML into the document.write allowing JS to essentially write that portion of the site including all HTML aspects

or is there another way that's considered best practice?

* correction: you utilized the thediv.innerHTML which since this code all exists inside a div would be applicable.. would this be best practice? cause i would have to include more embeded <div> into the html the thediv.innerHTML was genertaing to maintain formatiing

best practice, from what I understand, is to have the js do as little as possible and the html and css do as much as possible.

you set up the structure with a skeleton html, do all of your styling in css and let the js "fill in" the bits that you have no control over - basically the text, links and image paths from your JSON.

note that document.write and innerHTML are two very different methods and the former is pretty much frowned on for all but very specialised circumstances.

it's also worth noting, maybe, that things don't have to exist yet for them to be styled by css once they do come into existence - in my code for example the css specifies image dimensions, but the images are "created" later.

if you have div id's with incrementing numbers, you might look at how you can populate them more dynamically, for example:

Code:

document.getElementById("streamlogo"+i+1).src=base[i].channel.logo;

hopefully that answers your question, although I was a little unsure about what you were asking. If you'd like to post your code (or a portion of it) maybe it will become clearer.

as for the existing content being shown first, there's nothing much you can do about that. that content gets overwritten after the script has made a request for the info and the sending page has sent it back. If you don't want that content to show on page load, why do you have it coded there?

I don't understand the bit about inserting the viewers into the beginning of the ipsum text. Do you mean the text that appears on page load? in that case you would change that line to:

the add viewers part was already added in the script i attached so its already integrated...

I like the dynamic way of doing the script... if for no other reason then for the fact that i will continue to work even if i want a list that is longer then three... infact there is no reason that it wouldent work for any number of returns from the JSON request...

And yes... i guess i could leave the, to be inserted, portions blank so the only thing to load on the page will be the inserted content... which would alleviate the changing of content and appear to be more of a fraction of a second loading time...

Id like to take a moment to really thank you for your assistance, as im sure you may have guessed i'm very new to javascript. However, despite you providing a peice of code that ill most likely use directly... minus utilizing the API way to pull the info as opposed to the yahoo way... i still managed to learn a considerable amount in our exchange about what i should and shouldn't be looking for when trying to achieve things of this nature. Not to mention ill have to write slightly different versions of the same thing for two other sections of the page that now have a stunning example and reference for...

I dont see a reputation addon for this forum, pls let me know if there is one... either way thank you!

Final question and ill consider the thread solved... does the onload event happens after the HTML and therefore all the ID's are created correct? would that be how you would personally trigger the function?

*edit: Found the reputation button.. + 1 rep!

*edit: nevermind, in asking the question i looked again and realized how he function is already being called... lol

and im not sure if its due to the fact that the load time decreased by not having to preload the content and then replace it... but by removed the content that was coded there and leaving the fields blank to be filled by the script... the delay is almost gone and the section appears to load instantly... by not just taking the final step of removing the stock content once i had the actual content i created a delay that wouldent have existed anyways... if that makes sense...

a lot depends on response times. Possibly once you start using the API you will notice a difference from the time it takes yahoo to retrieve the info as well. If it's better or worse or variable depends on a lot of things out of your control. You could consider having one of those whirly "loading" things if you don't want your users to be put off by a blank screen.

if you are interested in making it really dynamic, you might consider creating the html on the fly, so that you can load in as many games as you like and not have to worry about adding extra html to accommodate...

thanks, ill study that code for a future application i can foresee already. As for this instance it literly always going to be for that JSON request and always displaying the 3 results only... so the last function works like a charmer...

Ill toss this one here before making a thread on what could be a very simple answer... not to mention you seem sharp and id love your opinion on it in particular. I only have space for about 77 characters of the status.. then i would like to cut off the status and append it with ... or something indicating there is additional text that was cut off... i modified the code to do this... It appears to work but im curios if this would be your implentation as well...

However, how do you accommodate for ['s and various other characters that don't take up that much space and some characters that do take up allot of space to best fit as much as you can into the area? or is this a concern?

I don't know if it is a concern - that would be up to you I guess. This definitely seems like a topic for a new thread, but I would be happy with the way you are doing things. The only other possibility would be to actually measure the space taken up and decide how many pixels you want to dedicate. The example below gives 400px to the text before cutting it off and adding the dots. If you want to change that you have to do it in the "content" css and the checkLength function... it seems like more trouble than it's worth, but it was an interesting little exercise...