in reply to Re: copying perl array to javascript array
in thread copying perl array to javascript array
sub serialize_string_list { return join('|', map { (defined($_) ? do { local $_=$_; s/\^/^1/g; s/\|/^2/g; $_ } : '^0' ) } @_ ); } sub populate{ @n=(); my $dt; my $row; #course contains the values fetched from the database foreach $row (@$course) { ($dt) = @$row; push(@n,$dt); } return serialize_string_list @n; }; //deserializes the array function deserialize_string_list(s) { var fields = s.split("|") var i; for (i=0; i<fields.length; i++) { if (fields[i] == "^0") { fields[i] = null; } else { var re; re = /\^2/g; fields[i] = fields[i].replace(re, "|"); re = /\^1/g; fields[i] = fields[i].replace(re, "^"); } } return fields; } //calling Sajax wrapper function from a javascript function function do_populate() { x_populate(do_populate_cb); } function do_populate_cb(s) { var arr = deserialize_string_list(s); var i; for (i=0; i<arr.length; i++) { with(document.doc1.selCourseNm) { options[i]=new Option(arr[i],arr[i]); } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: copying perl array to javascript array
by ikegami (Patriarch) on Aug 02, 2005 at 19:36 UTC | |
by Rainmaker (Acolyte) on Aug 05, 2005 at 21:07 UTC | |
by Joost (Canon) on Aug 09, 2005 at 22:23 UTC |