Passing a parameter to a javascript function
I have declared a <jsp:usebean> on my jsp to extract a flag from the request. I want to then pass this String as a parameter to a javascript function called on the body onload. What is the best way of doing this? The javascript function is embedded in the jsp - does this mean I can access the variable directly, without even passing it as a parameter? do I use the <%= > syntax to reference the String on the onload? Do I use the <bean:write> the extract the varible within he javascript. Any help appreciated....
JSP runs first on the server, and generates the HTML page with javascript.
The javascript then runs on the client - it can't call any more JSP code, without submitting a request.
In this case, you will want to use JSP to generate the javascript code that you need to run as a string on the page. You should probably use the <%= %> or the <bean:write tag>
eg
<script>
<!--
function loadForm(){
var userName = "<%= user.getName() %>";
alert("Hello " + userName);
//-->
</script>Note again. The use.getName() function will run on the server and produce static html/javascript like this
var userName = "evnafets";
JSP CODE DOES NOT RUN ON THE CLIENT. You cannot use JSP code to react to button clicks on the form for instance.
Hope this helps,
evnafets
Similar Messages
-
How to passed an xsl parameter to a javascript function inside an xsl styel
Hi:
I am having problem passing an xsl param variable as a parameter to a javascript function inside an
xsl styelsheet.
Here is my xsl stylesheet.
>
<xsl:param name="numberOfRecordsFromDatabase" select="search-result/rec-num" />
<xsl:template name="Body">
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"
onLoad="cloneHeader();window.parent.shrinkIFrame(<xsl:value-of select='$numberOfRecordsFromDatabase'/>);"
onresize="cloneHeaderResize();window.parent.shrinkIFrame(<xsl:value-of select='$numberOfRecordsFromDatabase'/>);">
</body>
</xsl:template>
I am trying to pass a variable called numberOfRecordsFromDatabase to
a javascript function called window.parent.shrinkIFrame(<xsl:value-of select='$numberOfRecordsFromDatabase'/>).
Is this possible?
If not, is there a way to do this.
Any hint would be greatly appreciated.
Yours,
Frustrated.I would do it like this:
Load the "search-result/rec-num" value into a field within an invisible div tag:
<div id="miscproperties" style="visibility:hidden">
<input id="numberOfRecs" type="text">
<xsl:attribute name="value">
<xsl:value-of select="search-result/rec-num"/>
</xsl:attribute>
</input>
</div>Then, your js function can retrieve the value via
var x = document.getElementById("numberOfRecs").valueR. Grimes -
How to pass dynamic parameter to a database function in OBIEE
Hi,
I have a requirement like this. I have to create one report in OBIEE which was in Discoverer. Now in discoverer report there are some calculated item in the worksheet based on database pkg.functions. The parameter which user gives at run time that parameters are then passed to the discoverer calculated items dynamically. But I am not able to do this in OBIEE answers.
Can anyone tell me step by step how I can able to pass the user selected parameter values in OBIEE answer level.
The example:
GET_COMM_VALUE_PTD("AFE Cost & Commitment".Afe Id,:"Period Name(AFE)","AFE Cost & Commitment".Data Sel,"AFE Cost & Commitment".Org Id)
GET_COMM_VALUE_PTD --- Function database
("AFE Cost & Commitment".Afe Id,:"Period Name(AFE)","AFE Cost & Commitment".Data Sel,"AFE Cost & Commitment".Org Id --- Parameters... :"Period Name(AFE)" is the dynamic parameter selected run time by user.
Please help.
Thanks
TitasHi,
I already did that. But the existing discoverer re value report is showing correct value but the OBIEE report with EVALUATE function shows incorrect value.
The requirement is to create a OBIEE Dashboard from a Discoverer existing report. Now in discoverer report theere are several calculated items in worksheet level where database custom function is used and user selected parameter value is passed run time in that function. But when that is created in OBIEE with EVALUATE function in RPD, the report shows incorrect data. Could not understand how to pass the parameter value runtime.
Below is the discoverer 'Show SQL' query and EVALUATE function syntax which has been used.
SELECT APPS.XXBG_PL_PROJ_ANALYSIS_AFE_PKG.GET_COMM_VALUE_PTD(XXBG_PL_PROJ_AFE_V.AFE_ID,
:"Period Name(AFE)",
XXBG_PL_PROJ_AFE_V.DATA_SEL,
XXBG_PL_PROJ_AFE_V.ORG_ID),
XXBG_PL_PROJ_AFE_V.AFE_DESC,
XXBG_PL_PROJ_AFE_V.AFE_NUMBER,
XXBG_PL_PROJ_AFE_V.APPROVED_AFE_AMOUNT
FROM APPS.PA_PERIODS_ALL PA_PERIODS_ALL,
APPS.XXBG_PL_PROJ_AFE_V XXBG_PL_PROJ_AFE_V
WHERE ((XXBG_PL_PROJ_AFE_V.ORG_ID = PA_PERIODS_ALL.ORG_ID))
AND (XXBG_PL_PROJ_AFE_V.DATA_SEL = :"Data Selection(AFE)")
AND (PA_PERIODS_ALL.PERIOD_NAME = :"Period Name(AFE)")
AND (XXBG_PL_PROJ_AFE_V.AFE_NUMBER = :"AFE Number(AFE)")
AND (XXBG_PL_PROJ_AFE_V.OPERATING_UNIT = :"Operating Unit(AFE)")
The EVALUATE function syntax is as below:
EVALUATE('XXBG_PL_PROJ_ANALYSIS_AFE_PKG.GET_COMM_VALUE_PTD(%1,%2,%3,%4)' AS FLOAT , "BG PL Project Analysis Report_1"."AFE Cost & Commitment"."AFE Cost & Commitment.Afe Id", "BG PL Project Analysis Report_1"."Periods 1"."Periods 1.Period Name", "BG PL Project Analysis Report_1"."AFE Cost & Commitment"."AFE Cost & Commitment.Data Sel", "BG PL Project Analysis Report_1"."AFE Cost & Commitment"."AFE Cost & Commitment.Org Id")
The PERIOD needs to be passed at run time which user will select.
Please help to solve the issue. -
Pass more parameter to the packaged function with REMAP_DATA in EXPDP
1) can we pass more than one parameter to the packaged function specified in REMAP_DATA during DATA pump export?
2) if yes to point#1 then, how can we pass rownum & some other columns value in the same record passed into the function?when all else fails, Read The Fine Manual
http://download.oracle.com/docs/cd/E11882_01/server.112/e16536/dp_export.htm#sthref115 -
How to pass Application Item value in Javascript function.
Hi,
I have the following javascript in the HTML Form Element Attributes properties
I am on Page1 and passing P1_DEPT_NO page item value. This is working perferctly fine and I am able to get the exact value of the page item
onchange="javascript:function1($x('P1_DEPT_NO').value);"I am on Page1 and passing Application Item G_DEPT_NO value.
The problem here is, I am not getting the Application item value inside the javascript function.
I tried using alert(); and it's giving me value as undefined
onchange="javascript:function1($x('G_DEPT_NO').value);"Just want to know, how to pass the Application Item value in Javascript.
Thanks,
DeepakDeepak,
I am not an expert at Javascript, but the suggestin I made was because javascript is a case-sensitive language.. and therefore onChange is not the same as onchange.
Not quite sure if that is causing the problem.
Application items are not associated with a page and therefore have no user interface properties.
Therefore, as mentioned in another post, the rendering would not work for application items.
If it is for a single item, used only in this page, you could create a hidden page item and use it fo your purpose
If you still want to look at application items and AJAX, This page contains examples of using AJAX to solve problems like the one you mentioned.
http://www.oracle.com/technology/obe/hol08/apexweb20/ajax_otn.htm#t1b
Thanks,
Rajesh. -
Pass a Java Bean into Javascript function.
Good day. Please help urgent :
I am trying to pass an instance of MyBean class into a javascript function
This code is added to the form.
private String getJavaScriptForLaunchNewComponent()
StringBuffer sb = new StringBuffer();
sb.append("<SCRIPT language='JavaScript'>");
sb.append(" function testFunction(zBean) { ");
sb.append("popAssetWinSpecs = \"left=250,top=250,width=300,height=300,scrollbars=no,toolbar=no,menubar=no,resizable=no,status=no,titlebar=no,location=no\";");
sb.append("htmlfile=\"/irj/servlet/prt/portal/prtroot/com.roche.mss.pdf.comp.PDFLauncher?zBean=\"+zBean;");
sb.append("window.open(htmlfile,\"editWindow\",popAssetWinSpecs);");
sb.append("return false;");
sb.append(" }");
sb.append("</SCRIPT>");
return sb.toString();
This code is set in the create component meth
private Component buildLink(){
GridLayout grid = new GridLayout(1,1);
grid.setCellSpacing(5);
TestBean zBean = new TestBean();
zBean.setValue("Me Now");
Link link = new Link("myLink");
link.addText("Print PDF");
link.setOnClientClick("testFunction("+zBean +")");
grid.addComponent(1,1,link);
return grid;
Is this possible ????
Thanks.solved it. Thanks
-
Passing pl/sql variables to javascript function
hi! in a dynamic page, i've got the javascript:
<html>
function onCall(A,B)
<oracle>
Select aDate, Name from test;
b_rec b_cur%rowtype;
htp.p(</body onload="onCall('||b_rec.aDate||','||b_rec.Name||'";');
</oracle>
how can i pass in as onCall('12-Jun-2002','TestUser'), with the single quotes?
the above pass in as onCall(12-Jun-2002, TestUser) which the javascript will throw an error message.
thx.hi! got it by chance:
htp.p('<body onload="onBirth('''||BDay||''','''||BPerson||''');">');
rgds. -
Passing blank parameter to stored procedures/function
Hi all,
When I pass blank value ('') to a VARCHAR2 parameter in a stored procedures/function it reads the parameter as NULL, I try to use DEFAULT keyword in the parameter declaration, but it does not work. How can I make the sp/func read the paramater as '' ?
Thanks in advance
SetyaThis is a fundamental quirk of Oracle - it treats '' (empty string) as if it were null:
SQL> SELECT case when '' is null then 'EMPTY STRING IS NULL' else 'EMPTY STRING IS NOT NULL' end
2 FROM dual;
CASEWHEN''ISNULLTHEN'EMP
EMPTY STRING IS NULL
SQL> So what is it you want to do that you can do with an empty string but not with a null?
Regards, APC -
How to pass a parameter to a declared function
Hello all
Can anyone help me with the following? I have a function which reads files and then adds the contents to a database. As some of the files are quite big I want to add them one at a time to the database. To do this I am passing a value from another page, if this value matches the filename then only that file will be loaded. I know I cannot use the request object to pass the value, as my function is declared, and I should pass the value as a param. Does anyone have any example code of how I can do this?
Thanks in advance for any help you can give me
elliemayFirst, I would use a servlet instead of a JSP page, then I recommend using the "indexOf" method of the String object when you get the files name Array. If "indexOf(request.getParameter(Branch))" equals "-1", the file cannot be processed. Here is a quick example of a servlet doing the work (based on your code) :
package mypackage1;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ProcessFiles extends HttpServlet
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
File f = null;
PrintWriter out = null;
String sBranch = null;
String sPath = null;
String[] files = null;
response.setContentType("text/html; charset=windows-1252");
out = response.getWriter();
sBranch = request.getParameter("Branch");
// Check here if sBranch is not null
InitDB();
sPath = dbLookup("TEXT","T1_FILE_PATH");
// Check here if sPath is not null
f = new File(sPath);
files = f.list();
for (int i = 0; i < files.length; i++)
// Acting like a filter using the "indexOf" method of the String object on each item
if (files.length() == 15 && files[i].indexOf(sBranch) != -1)
ProcessFile(files[i], sPath);
DeleteFile(files[i]);
out.println("<html>");
out.println("<head><title>ProcessFiles</title></head>");
out.println("<body>");
out.println("<p>Files loaded</p>");
out.println("</body></html>");
out.close();
private void ProcessFile(String sFileName,String sPathPrefix) throws Exception
String record = null;
int RecCtr = 0;
final String EOR_DELIM = "*END*";
String sBranch = sFileName.substring(0,3);
String sRunDate = sFileName.substring(3,11);
final String InitSQL = "Insert into T1 values ('" + sBranch + "',";
String sSQL = InitSQL;
int i;
ExecSQLCmd("Delete from T1 where Branch='" + sBranch + "'");
try
FileReader fr = new FileReader(sPathPrefix + "/" + sFileName);
BufferedReader br = new BufferedReader(fr);
record = new String();
while ((record = br.readLine()) != null)
if (MyStrEquals(record,EOR_DELIM))
sSQL=ChopOff(sSQL,1) + ")";
ExecSQLCmd(sSQL);
RecCtr++;
sSQL = InitSQL;
else
StringTokenizer st = new StringTokenizer(record,"@");
i=0;
while (st.hasMoreTokens())
sSQL += ("'" + Escape(st.nextToken()) + "',");
i++;
catch (IOException e)
System.out.println("IOException error!");
e.printStackTrace();
throw e; -
Passing parameter values to powershell function from batch file
Hello ,
I haven't used powershell for a while and getting back to using it. I have a function and I want to figure out how to pass the parameter values to the function through batch file.
function Check-FileExists($datafile)
write-host "InputFileName : $datafile"
$datafileExists = Test-Path $datafile
if ($datafileExists)
return 0
else
return -100
<#
$datafile = "C:\Dev\eMetric\PreIDWork\PreIDFiles\SampleInputFile_011.txt"
$returncode = Check-FileExists -datafile $datafile
Write-Host "ReturnCode : $returncode"
$datafile = "C:\Dev\eMetric\PreIDWork\PreIDFiles\SampleInputFile_01.txt"
$returncode = Check-FileExists -datafile $datafile
Write-Host "ReturnCode : $returncode"
#>
The above code seems to be work when I call it. But when I try to call that script and try to pass the parameter values, I am doing something wrong but can't figure out what.
powershell.exe -command " &{"C:\Dev\eMetric\PreIDWork\PowerShell\BulkLoad_Functions.ps1" $returncode = Check-FileExists -datafile "C:\Dev\eMetric\PreIDWork\PreIDFiles\SampleInputFile_01.txt"}"
Write-Host "ReturnCode : $returncode"
$file = "C:\Dev\eMetric\PreIDWork\PreIDFiles\SampleInputFile_01.txt"
powershell.exe -file "C:\Dev\eMetric\PreIDWork\PowerShell\BulkLoad_Functions.ps1" $returncode = Check-FileExists -datafile $datafile
Somehow the I can't get the datafile parameter value being passed to the function. Your help would be much appreciated.
I90RunnerI am not sure about calling a function in a script like how you want to. Also I see you are setting the values of the parameters, this is not needed unless you want default values if nothing is passed. The values for the parameters will be passed via the
batch file. So for me the easiest way is as indicated.
param
[string]$DataFile
function Check-FileExists($datafile)
write-host "InputFileName : $datafile"
$datafileExists = Test-Path $datafile
if ($datafileExists)
return 0
else
return -100
Write-Host "Return Code: $(Check-FileExists $DataFile)"
Then you create a batch file that has
start powershell.exe
-ExecutionPolicy
RemoteSigned -Command
"& {<PathToScript>\MyScript.ps1 -DataFile 'C:\Dev\eMetric\PreIDWork\PreIDFiles\SampleInputFile.txt'}"
Double click the batch file, and it should open a powershell console, load your script and pass it the path specified, which then the script runs it and gives you your output
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
Don't Retire Technet -
How to use a Session object in a Javascript function
I have an object that I have set in my session.
On my jsp I want to pull it out of my session and use it as a parameter for a javascript function. But I am not sure how to do that... the function call is below... I want to assign a value to ifFormat (last variable in function) But I am not sure what to use inside javascript.
<script type="text/javascript">
Calendar.setup({inputField:"f_date_dfFirstPmtDate",
button:"f_trigger_dfFirstPmtDate",
singleClick:true,
ifFormat:XXXXX});
</script>Note that javascript runs on the client side, and JSP runs on the server. JSP and the session objects are NOT available to javascript in reaction to the user.
If this function is called only when the page is first created, not when the user interacts with the page, or if you want that value to be constant with respect to the javascript, then you can do this:
<%
String someValue = (String)session.getAttribute("theAttributeName");
%>
<script type="text/javascript">
Calendar.setup({inputField:"f_date_dfFirstPmtDate",
button:"f_trigger_dfFirstPmtDate",
singleClick:true,
ifFormat:<%=someVale%>});
</script> -
How to put a jsp variable into a javascript function?
Please read the following coding. I want to pass the variable ans from jsp to the function check_answer() of javascript. ans is a string got from database. But I cannot put the variable ans into the Javascript function. Can anyone help?
<script language="Javascript">
function check_answer() {
if (testing.result.value==ans ){
window.alert("You have got 10 marks.");
</script>
<body>
<form name="testing"...>
<%
ResultSet rs = stmt.executeQuery("select * from level where...");
while(rs.next())
out.println("<tr>");
out.println("<td>" + rs.getString("question") + "</td>");
ans = rs.getString("answer");
out.println("</tr>");
out.println("<input type='text' name='result'>);
out.println("<input type='button' value='Enter' onclick='check_answer()'>");
%>The following should be able to pass ans.
<script language="Javascript">
function check_answer(ans) {
if (testing.result.value==ans ){
window.alert("You have got 10 marks.");
</script>
<body>
<form name="testing"...>
<%
ResultSet rs = stmt.executeQuery("select * from level where...");
while(rs.next())
out.println("<tr>");
out.println("<td>" + rs.getString("question") + "</td>");
ans = rs.getString("answer");
out.println("</tr>");
out.println("<input type='text' name='result'>);
out.println("<input type='button' value='Enter' onclick='check_answer('<%= ans%>')'>");
%>jag -
Passing java parameter to javascript function in oa framework
hi all,
can anybody tell how to pass parameter to javascript function from java for example
OAMessageTextInputBean txtbean = (OAMessageTextInputBean)webBean.findChildRecursive("BuyerPrice");
String row = "rowid";
txtbean.setOnKeyUp("javascript:checkNumber("+row+")");
checknumber is javascript function defined .Hi,
go through http://forum.java.sun.com/thread.jspa?threadID=174157&messageID=539357
if ur requirement is just to pass a string to a JS function.
Thanks -
Passing fragment parameter with in a javascript function
How can I pass the current node to a function I tried this but it
didn't work.please advice
<script language="javascript">
nvh_mainnavigation_display(g_navNode_Path, Node ,
"<!--$HttpRelativeFragmentsRoot-->AlfarisMainNavigation", false);
</script>
Note:
I'm trying to create a menu that shows the subnodes of the current
section or node that im standing on.Hello,
So that really should work. Are you getting back a blank or seeing <!--$HttpRelativeFragmentsRoot--> in the result?
David -
Passing value from javascript function to servlet
Hello everybody,
i need to pass parameter from javascript function to servlet.
what i wrote is :
function callPopulateServlet(t)
var h =document.NewRequest.services;
var y = t.selectedIndex;
alert(h.options[y].value);
var id=h.options[y].value;
<%session.setAttribute("id",id);%> // am getting error at this point
document.NewRequest.submit();
with this id am quering values from database through servlet.
any body knows plz help me.
thanks,
anil.this is the error am getting
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:435)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:299)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Maybe you are looking for
-
Automatic payment error - no valid payment method found
I created an invoice which i try to clear in f110. the vendor has the appropriate payment methods specified too but still I get this error "No valid payment method found " for that document. kindly assist, if anyone knows where can be the error. this
-
Disabling calendar icon from a date field
Hi The DateField control in UIX creates a text field for entering dates and a button for picking dates from a calendar. Is there a way I could disable the calendar icon selectively, when I do not want my user to pick up a new date? Patrick
-
Adding all users under one subtree to a role
Hi, We have a role call PaymentsGroup under cn=Groups,dc=companyname,dc=com There are sub trees which contains many users which categorised by city, country. Example : cn=michael wood,ou=users,ou=cal,ou=us,ou=dept1,cn=users,dc=companyname,dc=com cn=
-
10.5.3 update not allowing me to open my JMP software - says cannot find ap
Hi, Ever since installing the latest version of leopard I have been unable to open my JMP software application. Also, when trying to print documents in adobe pdf on my hp laser jet 3600 color (i also have a hp laser jet 1320 which has not presented t
-
When clicking on a pdf file it does not open and then it opens hundreds of tabs. The only way to stop it is to shut off the computer.