Droplist calling scriptlet/beans

U

unlikeablePorpoise

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
 
T

Tim Slattery

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();
}
 
T

Tom Cole

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);"
 
T

Tom Cole

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);"
 
T

Tom Cole

On Mar 20, 9:48 am, (e-mail address removed) 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
 
U

unlikeablePorpoise

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
 
T

Tom Cole

Tom Cole said the following on 3/20/2007 1:28 PM:




On Mar 20, 9:48 am, (e-mail address removed) 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...
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).
 
R

Richard Cornford

Tom Cole wrote:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top