Droplist calling scriptlet/beans

Discussion in 'Javascript' started by unlikeablePorpoise@gmail.com, Mar 20, 2007.

  1. Guest

    I would like to have an HTML dropdown list where each selection calls
    a method. The following code doesn't work, but it I hope it gives the
    idea of what I'm trying to do:

    <FORM NAME="frm">
    <SELECT NAME="sel"
    onChange="document.frm.sel.options[document.frm.sel.selectedIndex].value">
    <OPTION SELECTED value="">--choose--
    <OPTION VALUE="<% package1.method1; %>">Call Method 1
    <OPTION VALUE="<% package1.method2; %>">Call Method 2
    <OPTION VALUE="<% package1.method3; %>">Call Method 3
    </SELECT>
    </FORM>


    Basically I would like to use the JavaScript 'onChange' to invoke the
    method I select from the list.


    Any help would be appreciated. And if this is off-topic, let me
    know :) ...


    Thanks,
    Sarah
     
    , Mar 20, 2007
    #1
    1. Advertising

  2. Tim Slattery Guest

    wrote:

    >I would like to have an HTML dropdown list where each selection calls
    >a method. The following code doesn't work, but it I hope it gives the
    >idea of what I'm trying to do:
    >
    ><FORM NAME="frm">
    ><SELECT NAME="sel"
    >onChange="document.frm.sel.options[document.frm.sel.selectedIndex].value">
    ><OPTION SELECTED value="">--choose--
    ><OPTION VALUE="<% package1.method1; %>">Call Method 1
    ><OPTION VALUE="<% package1.method2; %>">Call Method 2
    ><OPTION VALUE="<% package1.method3; %>">Call Method 3
    ></SELECT>
    ></FORM>
    >
    >
    >Basically I would like to use the JavaScript 'onChange' to invoke the
    >method I select from the list.


    Make <select.. group look like this:

    <select name="sel" onChange="handleChange(this)">
    <option selected value="">--choose--</option>
    <option value="1">Call Method 1</option >
    <option value="2">Call Method 2</option>
    <options value="3">Call Method 3</option>
    </select>

    Then define the function:

    function handleChange(e)
    {
    val = e.value;
    if (e.value = "1")
    package1.method1();
    else if (e.value="2")
    package1.method2();
    else if (e.value="3")
    package1.method3();
    }

    --
    Tim Slattery

    http://members.cox.net/slatteryt
     
    Tim Slattery, Mar 20, 2007
    #2
    1. Advertising

  3. Tom Cole Guest

    On Mar 20, 9:48 am, wrote:
    > I would like to have an HTML dropdown list where each selection calls
    > a method. The following code doesn't work, but it I hope it gives the
    > idea of what I'm trying to do:
    >
    > <FORM NAME="frm">
    > <SELECT NAME="sel"
    > onChange="document.frm.sel.options[document.frm.sel.selectedIndex].value">
    > <OPTION SELECTED value="">--choose--
    > <OPTION VALUE="<% package1.method1; %>">Call Method 1
    > <OPTION VALUE="<% package1.method2; %>">Call Method 2
    > <OPTION VALUE="<% package1.method3; %>">Call Method 3
    > </SELECT>
    > </FORM>
    >
    > Basically I would like to use the JavaScript 'onChange' to invoke the
    > method I select from the list.
    >
    > Any help would be appreciated. And if this is off-topic, let me
    > know :) ...
    >
    > Thanks,
    > Sarah


    Set this as your onchange hendler:

    onchenge="eval(document.frm.sel.options[document.frm.sel.selectedIndex].value);"
     
    Tom Cole, Mar 20, 2007
    #3
  4. Tom Cole Guest

    On Mar 20, 11:50 am, "Tom Cole" <> wrote:
    > On Mar 20, 9:48 am, wrote:
    >
    >
    >
    >
    >
    > > I would like to have an HTML dropdown list where each selection calls
    > > a method. The following code doesn't work, but it I hope it gives the
    > > idea of what I'm trying to do:

    >
    > > <FORM NAME="frm">
    > > <SELECT NAME="sel"
    > > onChange="document.frm.sel.options[document.frm.sel.selectedIndex].value">
    > > <OPTION SELECTED value="">--choose--
    > > <OPTION VALUE="<% package1.method1; %>">Call Method 1
    > > <OPTION VALUE="<% package1.method2; %>">Call Method 2
    > > <OPTION VALUE="<% package1.method3; %>">Call Method 3
    > > </SELECT>
    > > </FORM>

    >
    > > Basically I would like to use the JavaScript 'onChange' to invoke the
    > > method I select from the list.

    >
    > > Any help would be appreciated. And if this is off-topic, let me
    > > know :) ...

    >
    > > Thanks,
    > > Sarah

    >
    > Set this as your onchange hendler:
    >
    > onchenge="eval(document.frm.sel.options[document.frm.sel.selectedIndex]..val­ue);"- Hide quoted text -
    >
    > - Show quoted text -


    or you could even spell it correctly:

    onchange="eval(document.frm.sel.options[document.frm.sel.selectedIndex].val­
    ue);"
     
    Tom Cole, Mar 20, 2007
    #4
  5. Tom Cole Guest

    On Mar 20, 11:51 am, "Tom Cole" <> wrote:
    > On Mar 20, 11:50 am, "Tom Cole" <> wrote:
    >
    >
    >
    > > On Mar 20, 9:48 am, wrote:

    >
    > > > I would like to have an HTML dropdown list where each selection calls
    > > > a method. The following code doesn't work, but it I hope it gives the
    > > > idea of what I'm trying to do:

    >
    > > > <FORM NAME="frm">
    > > > <SELECT NAME="sel"
    > > > onChange="document.frm.sel.options[document.frm.sel.selectedIndex].value">
    > > > <OPTION SELECTED value="">--choose--
    > > > <OPTION VALUE="<% package1.method1; %>">Call Method 1
    > > > <OPTION VALUE="<% package1.method2; %>">Call Method 2
    > > > <OPTION VALUE="<% package1.method3; %>">Call Method 3
    > > > </SELECT>
    > > > </FORM>

    >
    > > > Basically I would like to use the JavaScript 'onChange' to invoke the
    > > > method I select from the list.

    >
    > > > Any help would be appreciated. And if this is off-topic, let me
    > > > know :) ...

    >
    > > > Thanks,
    > > > Sarah

    >
    > > Set this as your onchange hendler:

    >
    > > onchenge="eval(document.frm.sel.options[document.frm.sel.selectedIndex].val­ue);"- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > or you could even spell it correctly:
    >
    > onchange="eval(document.frm.sel.options[document.frm.sel.selectedIndex]..val­
    > ue);"


    My apologies, I did not completely read your post...

    The example code I gave you will merely call a javascript function, it
    will not call a scriptlet or bean.

    The truth of the matter is that no javascript will call a scriptlet or
    a bean for one simple reason. They don't exist on the client machine.
    Remember that all beans and scriptlets execute on the server to
    generate the response (which is typically an HTML page) and once
    returned, they cease to be part of the processing. It is at this point
    that javascript executes on the client. Therefore you cannot call a
    scriptlet or a bean from javascript.

    What you CAN do is expose the functionality of your scriplet or bean
    as a servlet or some other server side resource, create a javascript
    method that will generate the request (either through XmlHttpRequest
    or by setting the document location) to this server side resource.
    Which route you choose (XmlHttpRequest or rediection) depends entirely
    on what you're trying to do, and this we don't know...

    If you need more specific information, let us know more specifically
    what you're trying to accomplish.

    I hope that explanation made sense to you...

    HTH
     
    Tom Cole, Mar 20, 2007
    #5
  6. Guest

    Thanks for your reply. Your explanation is clear. I have re-evaluated
    my program requirements and all I need to do is to be able to pass a
    string obtained from a drop menu into a method. So my question is: How
    do I cause a drop menu to generate a Java data type (String[],
    boolean, int) that can be passed into a Java class method? Can
    JavaScript variables be used directly in Java programs

    I hope this is clear.


    Thanks,
    Sarah
    >
    > My apologies, I did not completely read your post...
    >
    > The example code I gave you will merely call a javascript function, it
    > will not call a scriptlet or bean.
    >
    > The truth of the matter is that no javascript will call a scriptlet or
    > a bean for one simple reason. They don't exist on the client machine.
    > Remember that all beans and scriptlets execute on the server to
    > generate the response (which is typically an HTML page) and once
    > returned, they cease to be part of the processing. It is at this point
    > that javascript executes on the client. Therefore you cannot call a
    > scriptlet or a bean from javascript.
    >
    > What you CAN do is expose the functionality of your scriplet or bean
    > as a servlet or some other server side resource, create a javascript
    > method that will generate the request (either through XmlHttpRequest
    > or by setting the document location) to this server side resource.
    > Which route you choose (XmlHttpRequest or rediection) depends entirely
    > on what you're trying to do, and this we don't know...
    >
    > If you need more specific information, let us know more specifically
    > what you're trying to accomplish.
    >
    > I hope that explanation made sense to you...
    >
    > HTH- Hide quoted text -
    >
    > - Show quoted text -
     
    , Mar 20, 2007
    #6
  7. Tom Cole Guest

    On Mar 20, 6:51 pm, Randy Webb <> wrote:
    > Tom Cole said the following on 3/20/2007 1:28 PM:
    >
    >
    >
    >
    >
    > > On Mar 20, 11:51 am, "Tom Cole" <> wrote:
    > >> On Mar 20, 11:50 am, "Tom Cole" <> wrote:

    >
    > >>> On Mar 20, 9:48 am, wrote:
    > >>>> I would like to have an HTML dropdown list where each selection calls
    > >>>> a method. The following code doesn't work, but it I hope it gives the
    > >>>> idea of what I'm trying to do:
    > >>>> <FORM NAME="frm">
    > >>>> <SELECT NAME="sel"
    > >>>> onChange="document.frm.sel.options[document.frm.sel.selectedIndex]..value">
    > >>>> <OPTION SELECTED value="">--choose--
    > >>>> <OPTION VALUE="<% package1.method1; %>">Call Method 1
    > >>>> <OPTION VALUE="<% package1.method2; %>">Call Method 2
    > >>>> <OPTION VALUE="<% package1.method3; %>">Call Method 3
    > >>>> </SELECT>
    > >>>> </FORM>
    > >>>> Basically I would like to use the JavaScript 'onChange' to invoke the
    > >>>> method I select from the list.
    > >>>> Any help would be appreciated. And if this is off-topic, let me
    > >>>> know :) ...
    > >>>> Thanks,
    > >>>> Sarah
    > >>> Set this as your onchange hendler:
    > >>> onchenge="eval(document.frm.sel.options[document.frm.sel.selectedIndex].val­­ue);"- Hide quoted text -
    > >>> - Show quoted text -
    > >> or you could even spell it correctly:

    >
    > >> onchange="eval(document.frm.sel.options[document.frm.sel.selectedIndex].val­­
    > >> ue);"

    >
    > > My apologies, I did not completely read your post...

    >
    > > The example code I gave you will merely call a javascript function, it
    > > will not call a scriptlet or bean.

    >
    > And that is a dumb way to call a function. See my other posts.


    Being relatively new to javascript, I'm still wrapping my head around
    the fact that functions are first class "objects" and are therefore
    accessible via window[this.value]. I'll eventually embrace the
    concept...

    >
    > > The truth of the matter is that no javascript will call a scriptlet or
    > > a bean for one simple reason. They don't exist on the client machine.

    >
    > Sure it can, read the FAQ, specifically 4.34.


    Maybe my semantics are off. What I meant was that javascript on a page
    cannot call a bean or scriptlet method that was used to generate that
    particulat response, and I still contend that it cannot. It CAN
    generate a new request, but it cannot use the same request that
    generated the current page to call the method of a bean or scriptlet.

    This is a common issue with ASP and JSP developers. Working with both
    scriptlets and javascript on what appears to be the same "page" they
    tend to forget that the java on the page is not available to the
    javascript, because the javascript IS available to the java (just due
    to the processing sequence).

    >
    > --
    > Randy
    > Chance Favors The Prepared Mind
    > comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
    > Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/- Hide quoted text -
    >
    > - Show quoted text -
     
    Tom Cole, Mar 22, 2007
    #7
  8. Tom Cole wrote:
    <snip>
    > Being relatively new to javascript, I'm still wrapping my head
    > around the fact that functions are first class "objects" and are
    > therefore accessible via window[this.value].

    <snip>

    Javascript's functions being first class objects has no relationship with - window[this.vlaue] -. The
    implications of being a first class object is that they have individual identity (and so may be handled
    as distinct objects (passed around, assigned to properties, etc.)) and (as a result only of their being
    javascript objects) that they may have properties and methods, which may be added/removed/modified at
    runtime.

    The ability to reference (and so call) functions as properties of the global object only follows from
    those functions being declared in a global execution context (so they are created as named properties of
    the global object) or their having been assigned to named properties of the global object. These
    conditions do not apply to all functions (by a very long way).

    Richard.
     
    Richard Cornford, Mar 22, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil Powell
    Replies:
    0
    Views:
    1,673
    Phil Powell
    Nov 21, 2003
  2. Robert Mark Bram

    Share vars between scriptlet and jstl?

    Robert Mark Bram, Mar 20, 2005, in forum: Java
    Replies:
    1
    Views:
    15,429
    Ryan Stewart
    Mar 20, 2005
  3. Torsten Schmeissel
    Replies:
    0
    Views:
    439
    Torsten Schmeissel
    Apr 29, 2005
  4. Hats
    Replies:
    3
    Views:
    477
    Spartanicus
    Jun 20, 2005
  5. Replies:
    1
    Views:
    600
    Wojtek
    Mar 20, 2007
Loading...

Share This Page