wood burning stoves 2.0*
The moose likes Servlets and the fly likes Calling javascript's standard function in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Calling javascript Watch "Calling javascript New topic
Author

Calling javascript's standard function in jsp

kish ape
Greenhorn

Joined: Aug 13, 2001
Posts: 10
Hi,
I want to call javascript's standard function in jsp
Ex.out.println("<select name="sel" onChange=\"list()\">");
Means whenever the item of the select gets changed i want to call the onChange function which is calling function list()
Is it possible ?
If not then whats the alternate way?
I dont want to use only tag<select> without out.println coz its working fine.
Thankx in advance
kshitija
Praveen
Greenhorn

Joined: Apr 21, 2001
Posts: 11
hi,
Yes..It is possible. simply write your fuction as you define in any html page. Just define your javascript function in your jsp something like this:
<head>
<script>
function list() {
...
....
}
</script>
</head>


Software Engineer,<BR>Cybage Software Pvt. Ltd,<BR>Pune
Vishnu Murthy
Ranch Hand

Joined: Jan 04, 2001
Posts: 56
you can the function in <script>function list(){
} </script> tag and call it.
kish ape
Greenhorn

Joined: Aug 13, 2001
Posts: 10
<p>Thankx for the reply.
<p>But my question was different.
<p>I wrote in my query that when i am calling it in only
<select >tag then its working but when i am calling it in jsp's out.println() then the standard function onChange() only is not getting called .<p>I have already written the function list but i want to call it in my jsp file as i written in query so i want to know about that if i can call that onChange function from jsp's out.println ?


Originally posted by Praveen:
hi,
Yes..It is possible. simply write your fuction as you define in any html page. Just define your javascript function in your jsp something like this:
<head>
<script>
function list() {
...
....
}
</script>
</head>

Kaustubh Patil
Ranch Hand

Joined: Aug 13, 2001
Posts: 164
i am giving you a sample code in which a script func. is called from jsp....
----
<html>
<head>
<title>:-)))</title>
<script language="javascript">
function fn()
{
alert(" Hi!! I am function f1 ");
}
</script>
</head>
<body>
<%
out.println("<select name='sel' onchange='javascript:fn()'>");
%>
<option> option1 </option>
<option> option2 </option>
<option> option3 </option>
</select>
</body>
</html>
-------------
its simple and easy .. the problem with your code was that you had not written the select obj's name in double quotes instead of single..so it was taken as a part of jsp and not the part of string ...
i.e in ur orignal code u should have written name='sel' instead of name="sel" while writing it inside the out.println . :-)
Kaustubh.


Kaustubh. Mumbai, India.
kish ape
Greenhorn

Joined: Aug 13, 2001
Posts: 10
Hi ,
Thankx for the reply but it doesnt make any difference in my code
<br><br>
out.println("<select name='State' value=" +State+ "onChange='window.document.frm.elements['CountryCode'].value='Change';window.document.frm.submit();'>" );
<br><br>
This is my sentence calling the the submit function.It doesnt make diff if u write single quote or not & at the place of onChange i tried with
<br><br>
out.println("<select name='State' value=" +State+ "onChange=\"window.document.frm.elements['CountryCode'].value='Change';window.document.frm.submit();\">" );
<br><br>
this also but still it doesnt call the onChange method only.
If u have any solution on this then let me know abt that...
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

"akshitija" / "Praveen"
(maybe no one has ever said this before...sorry I have to
say it but...)
your name doesn't agree with the javaranch guidelines.
please take a moment and re-register after reviewing the
guidelines at http://www.javaranch.com/name.jsp
thanks for your cooperation.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling javascript's standard function in jsp
 
Similar Threads
How to get values from combo box in servlet
Event for option-changes?
Please help me.
Redirect to different frame
onSubmit event on form