• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing parameters in XSL to JavaScript

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to incorporate a JavaScript function that I found into my JSP and XSL files. The JavaScript basically takes one or more values from a list box and places them to another list box.
I tried placing the JavaScript code in both my JSP and my XSL. Right now I have it in both and I'm not sure where it has to be. In anycase, that doesn't matter right now cause it isn't working anyway.
When I click on the first button, just to copy whatever is selected in the first list box... nothing happens and a 'Error on Page' message appears in the status bar of my browser.
I'm including my code for you to have a look at.... any help would be very appreciated. Thanks.
XSL Stylesheet (Dropdown.xsl)______________________________________
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<script language="JavaScript">
<![CDATA[
function deleteOption(object,index) {
object.options[index] = null;
}
function addOption(object,text,value) {
var defaultSelected = true;
var selected = true;
var optionName = new Option(text, value, defaultSelected, selected)
object.options[object.length] = optionName;
}
function copySelected(fromObject,toObject) {

for (var i=0, l=fromObject.options.length;i<l;i++) {
if (fromObject.options[i].selected)
addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
}
for (var i=fromObject.options.length-1;i>-1;i--) {
if (fromObject.options[i].selected)
deleteOption(fromObject,i);
}
}
function copyAll(fromObject,toObject) {
for (var i=0, l=fromObject.options.length;i<l;i++) {
addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
}
for (var i=fromObject.options.length-1;i>-1;i--) {
deleteOption(fromObject,i);
}
}
]]>
</script>
<html>
<body>
<table border = "0" width ="50%" cellpadding = "0" cellspacing = "0">
<tr align="left">Choose a telephone number</tr>
<td align="left"></td>
<tr align="left"></tr>
<td><select name="select1" multiple="true" size="8" >
<xsl:for-each select="Results/CustomerView">
<option><xsl:value-of select= "Phone"/></option>
</xsl:for-each>
</select>
</td>
<td>
<input type="button">
<xsl:attribute name="onclick">
<xsl:text>javascript:copySelected('<xsl:value-of select="@Phone"/>')</xsl:text>
</xsl:attribute>
</input>
<p align="left"></p>
<input type="button" value=" remove one " onClick="if (document.images) copySelected(this.form.select2,this.form.select1)"></input>
<p align="left"></p>
<input type="button" value="move all" onClick="if (document.images) copyAll(this.form.select1,this.form.select2)"></input>
<p align="left"></p>
<input type="button" value="remove all" onClick="if (document.images) copyAll(this.form.select2,this.form.select1)"></input>
</td>
<td>
<select name="select2" multiple="true" size="8">
</select>
</td>
</table>
</body>
</html>
</xsl:template>
<xsl:apply_templates/>
</xsl:stylesheet>

JSP__________________________________________________________________
<?xml version = "1.0"?>
<%@ page contentType="text/html;charset=WINDOWS-1252"%>
<script language="JavaScript"><!--
function deleteOption(object,index) {
object.options[index] = null;
}
function addOption(object,text,value) {
var defaultSelected = true;
var selected = true;
var optionName = new Option(text, value, defaultSelected, selected)
object.options[object.length] = optionName;
}
function copySelected(fromObject,toObject) {
for (var i=0, l=fromObject.options.length;i<l;i++) {
if (fromObject.options[i].selected)
addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
}
document.write("Here I am");
for (var i=fromObject.options.length-1;i>-1;i--) {
if (fromObject.options[i].selected)
deleteOption(fromObject,i);
}
}
function copyAll(fromObject,toObject) {
for (var i=0, l=fromObject.options.length;i<l;i++) {
addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
}
for (var i=fromObject.options.length-1;i>-1;i--) {
deleteOption(fromObject,i);
}
}
--></script>
<jsp:useBean class="oracle.jbo.html.databeans.XmlData" id="custQuery" scope="request" >
<%
custQuery.setStylesheet("Dropdown.xsl");
custQuery.setReleaseApplicationResources(false);
custQuery.setDisplayAttributes("Custid,Name");
custQuery.initialize(pageContext,"BC4JTest_BC4JTest_BC4JTestModule.CustomerView");
custQuery.render();
%>
</jsp:useBean>
I've tried several things with the first button (explains why it is different from the other four)... I will take any suggestions or references to examples of code,. etc...
As you can see I'm new to this.. .thanks again.,
Jolene Dicks
Programmer/Analyst
iNet Development, HRDC
(709) 772-0908
jolene.dicks@hrdc-drhc.gc.ca
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Offhand, I'd say you're confused about what does what and whether it should be done on the client or server. XSL is a transformation language. It runs as a batch process, so buttons don't apply. It's most often used to take an XML file, such as query results, and convert it to HTML. This doesn't happen by magic - you have to pass the XML and XSL to a translator program.
Similarly, JSP runs only on the server, so IT can't handle JavaScript button logic either. If you can break down your task into what you're being provided, how you want it displayed, and what you want to happen after the user sees the display, it might be easier to say what you need.
 
reply
    Bookmark Topic Watch Topic
  • New Topic