Hi list!
I wrote a little script for a star-rating-thing which looks like:
function rate_dvd(id, score)
{
new Ajax.Request(''/dvd/'' + id + ''/rate/'' +
score, {
method:''get'',
requestHeaders: {Accept: ''application/json''},
onSuccess: function(transport){
var json = transport.responseText.evalJSON(true);
var new_score = json.new_score;
var new_width = new_score * 25;
var ul = document.getElementById(id);
var current_rating =
ul.getElementsByClassName(''current-rating'')[0];
current_rating.setStyle({
width: new_width + ''px''
});
}
});
}
The html looks something like:
<ul class="star-rating" id="2">
<li class="current-rating" style="width:
0.0px;"> </li>
....
</ul>
<ul class="star-rating" id="3">
<li class="current-rating" style="width:
0.0px;"> </li>
....
</ul>
As you can see above, I just want to replace the width of the li element.
But this script doesn''t work in IE (which is not that bad, but.. maybe
it''s a little thing I''ve overseen because I never wrote JS
before.)
So, maybe someone of you see what I''ve done wrong?
Thank you
Kai
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Id''s are supposed to begin with a letter. http://www.w3.org/TR/html4/types.html#type-name http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 Also, in IE you need to make sure you don''t have name attributes that conflict with ids. IE will return elements incorrectly through document.getElementById (use $(), btw), if the name attribute value matches the id you''re searching for. TAG On Jul 31, 2007, at 7:38 PM, Kai Kuehne wrote:> > Hi list! > I wrote a little script for a star-rating-thing which looks like: > > function rate_dvd(id, score) > { > new Ajax.Request(''/dvd/'' + id + ''/rate/'' + score, { > method:''get'', > requestHeaders: {Accept: ''application/json''}, > onSuccess: function(transport){ > var json = transport.responseText.evalJSON(true); > var new_score = json.new_score; > var new_width = new_score * 25; > var ul = document.getElementById(id); > var current_rating = ul.getElementsByClassName(''current- > rating'')[0]; > > current_rating.setStyle({ > width: new_width + ''px'' > }); > } > }); > } > > The html looks something like: > > <ul class="star-rating" id="2"> > <li class="current-rating" style="width: 0.0px;"> </li> > .... > </ul> > <ul class="star-rating" id="3"> > <li class="current-rating" style="width: 0.0px;"> </li> > .... > </ul> > > As you can see above, I just want to replace the width of the li > element. > But this script doesn''t work in IE (which is not that bad, but.. maybe > it''s a little thing I''ve overseen because I never wrote JS before.) > > So, maybe someone of you see what I''ve done wrong? > > Thank you > Kai > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Tom, On 8/1/07, Tom Gregory <tomg-PGZyUNKar/Q@public.gmane.org> wrote:> > Id''s are supposed to begin with a letter. > http://www.w3.org/TR/html4/types.html#type-name > http://www.w3.org/TR/html4/struct/global.html#h-7.5.2Tried it with a letter too, but it didn''t work with $(). See below.> Also, in IE you need to make sure you don''t have name attributes that > conflict with ids. IE will return elements incorrectly through > document.getElementById (use $(), btw), if the name attribute value > matches the id you''re searching for.$() gives me (e.g.) ''5'' but not the element which I need. document.getElementById does what I expect. I change the id to begin with a character, thanks Tom. Kai --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi again, I chaned the id as described from: <.. id="1"> to <.. id="dvd-1" but it still doesn''t work on internet explorer. $() still gives me (in this case) ''dvd-1'' but not the element itself. Thanks for hints Kai --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I may be wrong here but....
var current_rating =
ul.getElementsByClassName(''current-rating'')[0];
I''m not sure what the [0] is for at the end here. Do you want the
first element? I tried this and it doesn''t return a value.
current_rating will be an array. You can''t apply a style to an array:
current_rating.setStyle({
width: new_width + ''px''
});
You need to do this:
for(x=0;x<current_rating.length;x++) {
$(current_rating[x]).setStyle({width: new_width + ''px''
});
}
On Aug 1, 8:35 am, "Kai Kuehne"
<kai.kue...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi again,
> I chaned the id as described from:
>
> <.. id="1"> to <.. id="dvd-1" but it still
doesn''t work on internet explorer.
> $() still gives me (in this case) ''dvd-1'' but not the
element itself.
>
> Thanks for hints
> Kai
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Hi, On 8/1/07, Diodeus <diodeus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I may be wrong here but.... > > var current_rating = ul.getElementsByClassName(''current-rating'')[0]; > > I''m not sure what the [0] is for at the end here. Do you want the > first element? I tried this and it doesn''t return a value.current_rating always exists exactly one time, so this is correct. Kai --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Why not just grab it by ID instead of classname then?
var current_rating = $("dvd-1")
On Aug 1, 1:51 pm, "Kai Kuehne"
<kai.kue...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi,
>
> On 8/1/07, Diodeus <diod...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
>
>
>
> > I may be wrong here but....
>
> > var current_rating =
ul.getElementsByClassName(''current-rating'')[0];
>
> > I''m not sure what the [0] is for at the end here. Do you want
the
> > first element? I tried this and it doesn''t return a value.
>
> current_rating always exists exactly one time, so this is correct.
>
> Kai
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---