Hi,

Very, very hard to read that code, next time you need to paste a large
amount of code, I'd suggest something like Pastie[1].

It looks to me like you're looping through 'response.result', which
suggests it can have more than one entry.  But within your #each loop,
you're creating all sorts of elements with literal IDs, like:

   var row = new Element("div", {'id':'details'});

Which, if I'm reading correctly, means you'll end up adding more than
one div to the document with the ID 'details' (and this is just one of
many of these).

That won't work, IDs have to be unique in the docmuent.[2]  That could
be part of the problem.

Separately, you're doing a huge amount of element creation and
appending there.  You're doing it via the DOM API which you might
reasonably expect to be a quick way to do it; it isn't, you're much
better off building up a string and then passing the string into
Element#update.  Template[3] can be helpful for building up those
strings in a readable way.

[1] http://pastie.org
[2] http://www.w3.org/TR/html401/struct/global.html#adef-id
[3] http://prototypejs.org/api/template

HTH,
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com

On Sep 7, 11:30 pm, gomzie <gom...@gmail.com> wrote:
> Hi,
>
> I am trying to create some dynamic content, which has got some
> checkboxes as well. Neither it is selected nor the onclick works in
> IE. It works fine Firefox. Any help would be highly appreciated.
>
> Here is the code:
> function buildReviews(response) {
>         var reviewResults = $("reviewResults");
>         var reviewsRow = new Element("div");
>         reviewsRow.insert(new Element("hr"));
>                 response.result.each(function(review){
>                     var row = new Element("div", {'id':'details'});
>                     row.insert(new Element("div",{'id':'prodIdLbl'}).update
> ("<b>Product Id:</b> " + review.productId));
>                     row.insert(new Element("div",{'id':'bookTitleLbl'}).update
> ("<b>Book Title:</b> " + review.bookTitle));
>                     row.insert(new Element("div",{'id':'reviewerLbl'}).update
> ("<b>Reviewer:</b> " + review.reviewer));
>                     row.insert(new Element("div",{'id':'emailAddrLbl'}).update
> ("<b>Email Address:</b> " + review.emailId));
>                     row.insert(new 
> Element("div",{'id':'reviewText'}).insert(new
> Element("div").update("<b>Review Text:</b>")).insert(review.text));
>
>                 var dispFlag = new Element("div",{'id':'displayFlag'});
>                 dispFlag.insert(new Element("div",{'id':'flagLbl'}).update
> ("<b>Display on website <br> Product page:</b> "));
>                     var flagCheckBox = new 
> Element("div",{'id':'flagCheckBox'});
>                     var infoId = 'rollOverInfo_'+review.id;
>                     dispFlag.insert(new Element('img',{'src':'/img/Info.png',
> 'class':'bttnInfo', 'onMouseOut':'showRollover("'+infoId
> +'",event);return false;','onMouseOver':'showRollover("'+infoId
> +'",event);return false;'}));
>
>                     dispFlag.insert(new Element("div",
> {'id':'rollOverInfo_'+review.id, 'style':'display:none',
> 'class':'rollOverInfo'}).update("Check this check box to display on
> Product page."));
>
>                     var chkBox;
>                     if (review.displayReview)
>                          chkBox = new Element('input',{'type':'checkbox',
> 'id':review.id, 'onclick': 'javascript:setDisplayReviews(this.id,
> this.checked)', 'checked':true});
>                     else
>                          chkBox = new Element('input',{'type':'checkbox',
> 'id':review.id, 'onclick': 'javascript:setDisplayReviews(this.id,
> this.checked)'});
>
>                     flagCheckBox.insert(chkBox);
>                     dispFlag.insert(flagCheckBox);
>
>                     var reviewInfo = new Element("div",
> {'id':'setReviwInfo_'+review.id, 'style':'display:none',
> 'class':'reviwInfo'});
>                     reviewInfo.insert(new Element('img',{'src':'/img/
> infoReviewSetToDisplay.gif', 'class':'reviwInfoImg'}));
>                     reviewInfo.insert("This Review is set to display on 
> Product
> page.");
>                     var unsetReviewInfo = new Element("div",
> {'id':'unSetReviwInfo_'+review.id, 'style':'display:none',
> 'class':'reviwInfo'});
>                     unsetReviewInfo.insert(new Element('img',{'src':'/img/
> infoReviewSetToDisplay.gif', 'class':'reviwInfoImg'}));
>                     unsetReviewInfo.insert("This Review will not display on 
> Product
> page.");
>                     dispFlag.insert(reviewInfo);
>                     dispFlag.insert(unsetReviewInfo);
>
>                     reviewsRow.insert(row);
>                 reviewsRow.insert(dispFlag);
>                 reviewsRow.insert(new Element("hr"));
>                 reviewResults.update(reviewsRow);
>                 });
>
> }
>
> function setDisplayReviews(reviewId, checked) {
>         var url = "/setDisplayReviews.data?reviewId=" + reviewId +
> "&checked=" + checked;
>         new Ajax.Request(url, {
>                 method :'post',
>                 onSuccess: function(transport) {
>                         try{
>                                 response = transport.responseText.evalJSON();
>                 if (checked)
>                      infoDiv = $("setReviwInfo_"+reviewId);
>                 else
>                      infoDiv = $("unSetReviwInfo_"+reviewId);
>                 infoDiv.style.display="inline";
>                                 new PeriodicalExecuter(function(pe) {
>                                         infoDiv.style.display="none";
>                                    pe.stop();
>                                 }, 3);                  }
>                         catch(e){
>                                 if(console) console.log(e);
>                         }
>                 }
>         });
>
>
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to