2008-02-28:
[6:12] <nono> hello[6:12] <nono> anyone alive?[7:08] <nono> nope?[7:55] <zumbrunn_> hi nono[7:55] <zumbrunn_> still around?[8:09] <nono> yes[8:09] <nono> would be so cool if you could help me[8:09] <zumbrunn> I'll try :-)[8:10] <nono> Sweet![8:10] <nono> So I am messing with Greasemonkey[8:10] <nono> I want to do something hopefully simple >)[8:10] <nono> I have a multiple select box on a page[8:11] <nono> I simple want to use greasemonkey to set options of the multiple select box based on the value of said options[8:11] <zumbrunn> like an autofill[8:11] <nono> so say the box had options 1 2 3 and 4[8:11] <nono> exactlz[8:11] <nono> and I told greasemonkey to select 2 and 3[8:12] <nono> but for it to be usefull I would like to to read from an arraz[8:12] <nono> array[8:14] <nono> I have the autofill script up and I was using it as a base[8:14] <nono> http://phpfi.com/299314[8:16] <zumbrunn> so, you are already reading from an array ...or what do you mean by that?[8:16] <nono> So unlike a text field I don|t just want to set one value[8:16] <nono> Since I am dealing with a multi select box[8:16] <nono> I would like to use an array of values in my case numbers to populate the autofill[8:18] <zumbrunn> so, for some of the values you'll specify arrays instead of strings[8:19] <zumbrunn> and then change the code below to check for that and loop through them[8:19] <zumbrunn> where are you stuck?[8:19] <nono> I don't even need anything that complex[8:20] <nono> I have a field called productcolor_id[][8:20] <nono> I would like to make a simple script that selects the values 4,5,6 from an array[8:20] <nono> allFields = document.getElementsByTagName('select');[8:21] <nono> I think i should be using that[8:21] <nono> but I am not quite sure how[8:24] <zumbrunn> you mean you know the id of the select element you want?[8:24] <zumbrunn> then you don't need to use getElementsByTagName at all[8:24] <zumbrunn> and use getElementById[8:25] <nono> cool[8:26] <zumbrunn> you're in the wrong channel for this kind of stuff, by the way :-)[8:26] <nono> so that will return the elements of productcolor_id in an array?[8:26] <nono> lol sorry i found a like on some website[8:26] <zumbrunn> this belongs more on ##javascript[8:26] <zumbrunn> this channel here is about helma.org[8:26] <nono> ic[8:27] <zumbrunn> which is javascript on the server-side[8:27] <nono> sounds cool but I am still learning client side :)[8:27] <nono> Do you think you could still assist me a tad?[8:27] <zumbrunn> re: productcolor_id... no, just the parent ellement[8:28] <zumbrunn> you'll stil need to loop through the options[8:28] <zumbrunn> like it is done in the code you posted[8:29] <zumbrunn> (the inner for loop)[8:29] <nono> and can I just call .selected = true?[8:30] <zumbrunn> yes[8:32] <nono> ok only think I am not clear on is how to return the options from the select object[8:32] <nono> thing*[8:33] <nono> is there a function like in php called inarray()[8:34] <nono> which checks the array for the current value and returns true or false[9:57] <zumbrunn> nono: that's what the inner for loop does[9:58] <zumbrunn> re: inarray() ... we have a contains Array method in Helma on the server-side[9:58] <zumbrunn> http://helma.zumbrunn.com/reference/ArrayExtensions.html[9:59] <zumbrunn> but you can't extend the array prototype on the client-side like this[9:59] <zumbrunn> but many of the popular client-side js libraries offer some way to do this[10:00] <zumbrunn> for exmaple, jquery has a jQuery.inArray() helper method[10:01] <zumbrunn> m31uk3: (didn't notice you changed your name)[10:04] <zumbrunn> actually, for what you want to achieve, injecting jquery wouldn't be a bad idea[10:07] <zumbrunn> then you could do... $('productcolor_id').children().each(function(){(jQuery.inArray($(this).html(),yourArray)+1) ? $(this).attr('selected','selected') : $(this).removeAttr('selected')})
In the channel now:
Logs by date: