Greetings ikegami
I tried using your code. Its works fine except for the fact that the last array value is followed by the whole html code in the form.
For eg:- If the array values are A,B,C,D and i add them in the drop down menu then the last option(D) is followed by the whole html code. So I have four options in the drop down box A,B,C,D<htmlcode>
Am i doing something wrong?
See code below.
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]); } } }

In reply to Re^2: copying perl array to javascript array by Rainmaker
in thread copying perl array to javascript array by Rainmaker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.