473,394 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Droplist calling scriptlet/beans

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 '07 #1
9 5635
un****************@gmail.com 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
Sl********@bls.gov
http://members.cox.net/slatteryt
Mar 20 '07 #2
On Mar 20, 9:48 am, unlikeablePorpo...@gmail.com 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);"

Mar 20 '07 #3
On Mar 20, 11:50 am, "Tom Cole" <tco...@gmail.comwrote:
On Mar 20, 9:48 am, unlikeablePorpo...@gmail.com 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);"

Mar 20 '07 #4
On Mar 20, 11:51 am, "Tom Cole" <tco...@gmail.comwrote:
On Mar 20, 11:50 am, "Tom Cole" <tco...@gmail.comwrote:
On Mar 20, 9:48 am, unlikeablePorpo...@gmail.com 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

Mar 20 '07 #5
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 '07 #6
un****************@gmail.com said the following on 3/20/2007 10:48 AM:
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.
A "method" on the webpage or a "method" on the server? If it is a
function in the webpage, then you call it:

onchange="window[this.value]()"

If it is a "method" on the server then it depends on what you want to do
after calling the "method". If there is no return value from the server
then you can simply set an Image() src to the value.
<URL: http://jibbering.com/faq/index.html#FAQ4_34>

onchange="someFunction(this.value)"

function someFunction(valToUse){
var dummyImage = new Image();
dummyImage.src = "scriptURL.jsp?method=" + valToUse;
}

And then have the server side page call the method it needs to call.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 20 '07 #7
Tom Cole said the following on 3/20/2007 1:28 PM:
On Mar 20, 11:51 am, "Tom Cole" <tco...@gmail.comwrote:
>On Mar 20, 11:50 am, "Tom Cole" <tco...@gmail.comwrote:
>>On Mar 20, 9:48 am, unlikeablePorpo...@gmail.com 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.
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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 20 '07 #8
On Mar 20, 6:51 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Tom Cole said the following on 3/20/2007 1:28 PM:


On Mar 20, 11:51 am, "Tom Cole" <tco...@gmail.comwrote:
On Mar 20, 11:50 am, "Tom Cole" <tco...@gmail.comwrote:
>On Mar 20, 9:48 am, unlikeablePorpo...@gmail.com 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 -

Mar 22 '07 #9
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.

Mar 22 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hats | last post by:
Hi, I've a site with no php, but ssi and scriptlets do work. I tried these tags. ++++++++++++++++++++++++++++++++++++++++++++++++++ <object type="text/x-scriptlet"...
3
by: eddie | last post by:
Hi, my colleague wrote a scriptlet to get server wide environment variables from ASP. However, my web application is written by C#, and I try to write a program to access that COM but I always get...
2
by: TJS | last post by:
need help with trying to set selected value on a droplist. -- tried vCaptainID as integer and string , no luck -- tried it in pre render and also after droplist is created , no luck =========...
8
by: Marc | last post by:
Hi! I'm calling a web service using C# and a wrapper class generated by wsdl tool. The web service specification contains some nillable parameters which types are Value Types in .NET (long, int,...
7
by: Christian Wilhelm | last post by:
Hi! I'm trying to call a Java WebService out of a .net Client. There are two Methods, one Method requires one Parameter of type Parameter, the other Method requires one Parameter of type...
0
by: yuchang | last post by:
Hi, I try to use a droplist control to show a list value from Database table "A", and the droplist control is an item of a formview control, its data from Database table "B". My problem is how...
2
by: ze colmeia | last post by:
Hi all... i'm having trouble trying to pass a field value from a Data Access Page to a Scriptlet. Om my DAP i have: Function returnId() Dim pId pId = formName.Id.value returnId = pId
8
by: abctech | last post by:
Hi All, I have a dynamic table in my web page which I'm creating in a jsp-scriptlet - <html> <body> <% out.write("<table>") ; // code to add rows dynamically to the table from my...
2
by: freedom9ner | last post by:
Hello, I'm investigating how HTML can be componentized and reusable. Remember Microsoft's SCRIPTLET object (TYPE="text/x-scriptlet")? I thought this was a great invention. But other browsers do not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.