in reply to Calling Perl function from HTML code - using SAJAX

Problem #1: SELECT objects have an add method, so it's getting called instead of your add function.

Problem #2: You call add with no arguments, yet you specified it requires ones.

Here's the fix, and I cleaned it up to adhere to convention.

Perl ---- use Sajax; sub populate { return 'Hey'; } Sajax::rs_init(); Sajax::rs_register("populate", \&populate); ... JS outputed by Perl ------------------- function do_populate() { x_populate(do_populate_cb); } function do_populate_cb(N1) { document.write(N1); document.write('I\'ts Me'); } HTML outputed by Perl --------------------- ... <SELECT NAME="selectCourseDept" onChange="do_populate(); return false; +"> ...

Passing the selected course around:

Perl ---- use Sajax; sub populate { my ($course) = @_; return "You selected $course"; } Sajax::rs_init(); Sajax::rs_register("populate", \&populate); ... JS outputed by Perl ------------------- function do_populate() { x_populate(selectCourseDept.value, do_populate_cb); } function do_populate_cb(feedback) { feedback_field.innerText = feedback; } HTML outputed by Perl --------------------- ... <p> <SELECT NAME="selectCourseDept" onChange="do_populate(); return false; +"> ... </SELECT> </p> <p>You selected: <span id="feedback_field"></span></p> ...

Untested.

Replies are listed 'Best First'.
Re^2: Calling Perl function from HTML code - using SAJAX
by Rainmaker (Acolyte) on Jul 29, 2005 at 20:32 UTC
    Thanks a ton ikegami. Yeah the code ran without any problems. I'll get back to you if i face any other problem. Thanks a lot again. Gaurav.