Michael Peters wrote:
I'm not sure I completely understand what you're looking for here, but if you
want an Ajax call to submit back to the same url you're page is coming from,
then window.location will contain that.

The problem does not arise with CGI::AJAX as it is mostly Perl-driven and I can pass the url to the template via the show_javascript() function using CGI.pm url(), like this:

my $pjx = new CGI::Ajax(
  validate_nhsno => url() . '?rm=validate_nhsno'
); # url() works for both mod_cgi & mod_perl

my $ajax_js = $pjx->show_javascript();

$self->tt_params(ajax_js=>$ajax_js);
        
return $self->tt_process('nhs_no.tt2');

whereas for the JQuery version I had to hard-code the url into the javascript like:

<script type="text/javascript">
<!--
  function validate_nhsno(myInput) {
    $('#bad_nhsno').load(
      'check_nhsno.cgi', { # <= no good for mod_perl!!
        rm : '_validate_nhsno',
        "nhs_no": myInput,
      }
    );
 }
-->
</script>

But usually what I do when I want to use the same function on different urls is
make the url an argument to the function, and then in my template, where I call
the function, I pass in the url from the Perl side. Something like this in TT
template:

  <script type="text/javascript">
    do_something_cool('foo', '[% USE url("/some/url", mode="cool") %]');
  </script>

But how would I get the script to pass the url to the j/s function, unless the equivalent of "/some/url" is passed as an interpolated variable eg:

$('#bad_nhsno').load(
  $url, { # <= using TT2 'INTERPOLATE' function
    etc,
  }
);

I think from memory I found template variables are not interpolated within j/s sections, but might be mistaken here. But even if I could do that, I'm sure I couldn't then put all my javascripts into a separate js library and call it once on page-load, and still expect to have variables interpolated - could I? Perhaps this is where window.location comes in?

I wouldn't say it's wrong, but yeah it does seem a little weird to create a new
select box on each change rather than just changing the values in the 2nd select
box.
Right!

I would probably have the server code emit JSON (using the handy C::A::P::JSON
plugin) and then have the client side JS take that JSON and empty out the target
select and add the extra values.

Worth a look - thanks. Something else to try and get my head round :-(
--
Richard Jones
Leeds, UK
mailto:[EMAIL PROTECTED]

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to