jvd has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on is there something like onChange action for a selection list ?

Replies are listed 'Best First'.
Re: is there something like onChange action for a selection list ?
by thpfft (Chaplain) on Sep 24, 2001 at 19:29 UTC

    Some confusion here, I think. There is no onChange in perl, nor can there be. Your perl scripts run on the server, in response to requests from browsers. They neither know nor care what is being selected on the page, until the point where you hit the submit button and the selections are passed back to the server.

    To do what you want - ie to change the nature of a form so that it submits when a selection is made, rather than when a button is pushed - you need to change the way the browser behaves, not the server. Which makes it a javascript question and explains the rather terse replies you'll find here.

    This is the sort of question google excels at, by the way. Any one of the 5,810 pages it returns when you search for 'select box onChange' will have something useful to say.

    But since you're here, this is how i would do it:

    <select name="choose" onChange="this.form.submit()"> <option value="mumble"> mumble </option> </select>

    Or for a navigation drop-down, which I expect is what you're doing:

    <select name="choose" onChange="document.location.href=this.options[th +is.selectedIndex].value"> <option value="/path/page.html"> mumble </option> </select>

    Which doesn't even need any perl on the server side. I'd better stop there before I get in any more trouble.

Re: is there something like onChange action for a selection list ?
by cfreak (Chaplain) on Sep 24, 2001 at 18:22 UTC
    You have to do it with a combination of Perl and Javascript. Something like this would do the trick in Javascript:
    function submit_on_change() { document.myform.submit(); }
    You have to change "myform" to match the name in your form element (form name="myform" it can be whatever you want). Then call the Javascript function in your onChange on the select menu:
    onChange="submit_on_change()"
    Hope that helps.
Re: is there something like onChange action for a selection list ?
by Chady (Priest) on Sep 24, 2001 at 16:26 UTC

    nothing to do with perl, it's called JavaScript

    Update: misinterpreted the goal of the mentioned site. disregard the post. Even though... I strongly believe that this isn't a place for discussing JavaScript.

      Oooo... Bad advice. If you wish to provide help in distinguishing between languages and resources for their use, note that JavaJunkies, the site you have referred our innocent friend to, is trying hard to distinguish its subject matter (Java) from JavaScript.