Pass a para to javascript function

In a jsp page, a javascript function needs to get a parameter from a variable of the jsp page. How can I do this? Thanks a lot!
---a.jsp---
<SCRIPT language=JavaScript>
function changeR(userID){
alert( userID + " chaged a value " );
</SCRIPT>
<% userID = "user1" %>
<form>
<input type="button" value="bbbb" onclick="changeR(userID)"> <!--it doesn't work this way-->
</form>
How should I write this part?
onclick="changeR(??????)"

<%! String userID=""; %>
<html>
<head>
<script type="text/javascript">
function changeR(userID){
alert( userID + " chaged a value." );     // this line doesn't work.
alert( "alert" );          // even this line doesn't work either.
</script>
</head>
<body>
<% userID = "user1"; %>
<form>
<input type="button" value="<%= userID %>" onclick="changeR(<%= userID %>)"> <!--it doesn't work this way-->
<input type="button" value="userID" onclick="changeR(userID)"> <!--it doesn't work this way-->
</form>
</body>
</html>
This is the sample jsp page. There are two ways tried (two buttons), none of them works. :(
When the first button is pushed, there's no response.
When the second button is pushed, the status bar shows "Script Error!".

Similar Messages

  • 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

  • Pass bound value to Javascript function

    I'm working in JDeveloper 10.1.2. I'm working on an application generating JSPs for the UI. I display an HTML table using a databound control from the data control pallette. The last column in the table is a button for each row. The user should be able to click a row's button and have a popup window display a page showing a table of detailed info on the the record in the html table row selected.
    Basically I want to pass the id/key for the row to a javascript function using the onclick event of the button. Here is my first attempt:
    <input type="button" onclick="popupDetail(<c:out value="${Row['AuditSeqid']}"/>)"/>
    The compiler barfed on the c:out tag. I don't know if it would even perform the subsitution correctly. The compiler seems to think the double quote starting the value attribute is ending the onclick event descriptor. Escaping with \" just brought up different errors.
    Can anyone recommend a way to pass a bound column's value from a rowset into a javascript function as a parameter?
    Thanks for any help you can give. I'm totally new to JDeveloper. This would be easy in simple JSPs, but with the Oracle data binding, I don't know what tags/objects are available from which I can grab the value.

    Found the solution:
    <td>
    <input type="button" name="detailsButton" value="Details" onClick="javascript:popupDetail('<c:out value="${Row['AuditSeqid']}" />');"/>
    </td>

  • How to pass jsp array to javascript function()

    function delete(var arr[][])
    out.print(arr[1][2]);
    <%String [][] arra=new String[1][2];
    %>
    <select name="" onClick="delete(<%=arra%>)">
    <option>fvfvfdfdfddffdd</option>
    </select>

    Thanks again for constant support .Now , here comes my real problem .
    I'm having a listbox . I need to find out how to get the values selected in a JSP variable .
    Like I'm having names of cities in listbox .When , I click on save button , i need the names of selected cities in JSP variable or an array .
    <html>
    <head>
    <script language="JavaScript">
         function show(acl)
              for(var i=0;i<4;i++)
                   if(acl.aclnames.options.selected)
                        // i don't know what to put here
              alert("in show");
    </script>
    </head>
    <body>
    <form name="acl" method="post">
    <select name="aclnames" multiple="true" size="3">
    <option>Ahmedabad</option>
    <option>Baroda</option>
    <option>Surat</option>
    <option>Rajkot</option>
    </select>
    <input type="button" name="save" value="Save" onClick="show(acl)">
    </form>
    </body>
    </html>

  • Setting the value of a java variable in javascript function

    How can i set the value of a java variable in a javascript function?
    <%
    String fName = "";
    %>
    now i want to define a javascript function which can set the value of fName to the value it has been passed.
    <script language="javascript">
    function setJValue(val)
    </script>
    Thanks

    The only way you could simulate this, would be call the same page inside the Javascript function, and send it the parameter that was passed. Then you would have your Java code retrieve this parameter by request.getParameter("value");, and set the variable accordingly.

  • 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)

  • How to pass value to pop up window using javascript function?

    I am not sure how to do this, I want to open new window from existing form,This is Mod/PLsql for consists some javascript functions also. When I am clicking on new window in form then new form should open with results of value entered,but new window form is opening with main page :( , not able to get text box value from parent form. How to call textbox input value in popup window from parent window using javascript?
    currently I'm using following code:
    HTP.p('<script type="text/javascript">
    function pop_up5()
    var l_url=window.opener.document.getElementById("p_single_store_pc").value;
    window.open(l_url, '''', ''fullscreen=no, scrollbars=1'');
    </script>' );
    Edited by: user11970612 on Jun 14, 2012 5:02 AM

    this is probably due to the Javascript code and not a "real link" to another page... I don't know if the null is due to the Javascript...
    But if you really really want to use javascript instead of a ... you can pass the location of the url with JSP (on your main page) as a parameter to the open window... (...) u can put instead of main.jsp <%= request.getServerName()+request.getRequestURI() %>
    the value <%= ... %> will return something like test.com/html/main.jsp
    Hope this helps.

  • How to pass value from Javascript function to a Java class method

    Hi All,
    I want to pass a value, which I catch in a Javascript function to a method in a Java class. I have tried many combinations but it gives me error.
    This is the way I am doing
    function assignBill() {
    proj = projPh.substring(0,indSlash);
    <% myproject.getProj(" project_cd = '" + proj + "'");%>
    proj is the variable which I want to pass to getProj methods.
    If any one has done this, please let me know. Thanks for your help.
    Ritesh Mehta

    The only way to receive something from clients page is to submit it somehow: through a form or link, but the info has to make it back to the server obviously. I dont know how your app works, but you can use the the javascript -location.href- function(i think) to submit the var to the server and process it there.

  • 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 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,
    Deepak

    Deepak,
    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 JSP into JavaScript function

    I have a database table containing a date for the end of an auction, I am able to successfully take the date from the database but I am having problems passing it and casting it to a date object within a javascript function. The purpose of the function is to begin a countdown to the passed in date. Any suggestions? The countdown function i have only works with a hard coded date object.
    <SCRIPT LANGUAGE="JavaScript1.2">
    mDate = new Date("October 18 2004")
    function countdown(){
    var now=new Date()
    var diff=mDate.getTime()-now.getTime()
    document.bid.days.value = Math.round(diff/(24*60*60*1000))
    document.bid.hours.value = Math.round(diff/(60*60*1000))
    document.bid.minutes.value = Math.round(diff/(60*1000))
    document.bid.seconds.value = Math.round(diff/1000)
    document.bid.mseconds.value = diff
    var id=setTimeout("millenium()",1)
    </SCRIPT>
    <body onLoad="countdown()">
    <form name="bid" method="post" action="">
    <p>Timeleft</p>
    <TABLE BORDER=0>
    <TD width="79">Days: </TD>
    <TD width="81">
    <INPUT TYPE="text" NAME="days" SIZE=15></TD> <TR>
    <TD width="79">Hours: </TD>
    <TD width="81">
    <INPUT TYPE="text" NAME="hours" SIZE=15></TD> <TR>
    <TD width="79">Minutes:</TD>
    <TD width="81">
    <INPUT TYPE="text" NAME="minutes" SIZE=15></TD> <TR>
    <TD width="79">Seconds: </TD>
    <TD width="81">
    <INPUT TYPE="text" NAME="seconds" SIZE=15></TD> <TR>
    <TD width="79">Milliseconds:</TD>
    <TD width="81">
    <INPUT TYPE="text" NAME="mseconds" SIZE=15></TD> <TR>
    </TABLE>
    </form>
    I wish to pass it as follows:
    <body onLoad="countdown(<%rsProduct.get........%>)"> and then cast within the function
    .............................................................................JSP.....................................................................................................
    <% Connection dbConn = null;
         try
              Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
              dbConn = DriverManager.getConnection("jdbc:sybase:Tds:compserver:5000/syb3044","syb3044", "syb3044");
              Statement select = dbConn.createStatement();           
              int ID = Integer.parseInt(request.getParameter("carId"));
              ResultSet rsProduct = select.executeQuery("SELECT * FROM car WHERE carID =" + ID);
              if(rsProduct.next()){}
    <%
              rsProduct.close();
    catch (SQLException sqle)
              out.println(sqle.getMessage());     
    catch (ClassNotFoundException cnfe)
              out.println(cnfe.getMessage());
    catch (Exception e)
              out.println(e.getMessage());
    finally
              try
                   if(dbConn != null)
                        dbConn.close();
              catch (SQLException sqle)
                   out.println(sqle.getMessage());
         }%>
    PLEASE NOTE THAT I AM A SECOND YEAR COMPUTER SCIENCE STUDY!
    sorry if code is messy to read.
    Regards

    Looks like everyone's having a countdown problem.....
    The script in this thread is awefully like in this one:http://forum.java.sun.com/thread.jsp?forum=45&thread=514095&tstart=0&trange=15
    Anyway, there're what you can do. Write out the Date object in JSP as a Javascript Date, two ways to achieve that:
    1, mydate.getTimeStamp() is should return a long value, time in millisec, so
    var mDate = new Date(<%= myDate.getTimeStamp()%>);
    2. a lil messy, use DateFormatter to format the sql.Date, this gives you a Date in Strint form. Do remember the exact API for the DataFormater, but something like this.
    var mDate = new Date("<%= DateFormatter.format(myDate) %>");
    I'd prefer the 1st approach, why changing a Date to String then just change to Date again....Also watch out the TimeZone stuff and Daylight saving time....have fun.

  • 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

  • Passing text including special characters to Javascript functions

    I need to call a Javascript function with some text retrieved from the database, which may include carriage returns, line feeds etc. I need to change these to the Javascript escape characters "\r", "\n" etc. I can easily write my own function to do this, but suspect there may be a built-in one somewhere I could be using - but can't find one. Is there one?

    Tony,
    I tried using XMLDB_GEN.CONVERT and it worked for me:
    DECLARE
       v_value_to_save   VARCHAR2 (30);
    BEGIN
       v_value_to_save := DBMS_XMLGEN.CONVERT (:t_sql, 1);
       UPDATE my_table
          SET my_column = v_value_to_save
        WHERE my_key = :my_key_value;
    END;
    DECLARE
       v_value_to_select   VARCHAR2 (30);
    BEGIN
       OWA_UTIL.mime_header ('text/xml', FALSE);
       HTP.p ('Cache-Control: no-cache');
       HTP.p ('Pragma: no-cache');
       OWA_UTIL.http_header_close;
       FOR c IN (SELECT my_value
                   FROM my_table)
       LOOP
          v_value_to_select := DBMS_XMLGEN.CONVERT (c.my_value, 0);
          HTP.prn (v_value_to_select);
       END LOOP;
    END;
    /Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • Set multiple items with javascript function in chart link

    Hi Folks
    I am able to use the javascript $s function to set the value of one item from a chart link. I need to pass values to multiple items.
    Is there a way to use javascript function to pass values for multiple items on a page from a chart link
    Appreciate your responses
    Thanks
    Gopal

    Hi Arnau,
    You need to surround your JavaScript code like this (without the spaces before and after script):
    < script language="Javascript">
      window.open("<%=ABAP_VARIABLE%>").focus();
    </script >
    Regards,
    Patrick.

Maybe you are looking for

  • How can i update to ios 6.1.3 on my model 1219

    i have tried to update my ipad model 1219 to ios 6.1.3 and also 7. with the current ios it will not download many of the apps and other things I'd like to have on it. Is there any other way to download this ios.? I have tried to go thru itunes etc an

  • Poor customer care regarding broadband infinity

    First of I had sky internet which was woefully slow, so I decided to go for unltd standard broadband from BT with a supposed 8meg speed. This worked ok for a couple of months but then I noticed the home hub4 was running slow & kept kicking me off & a

  • Boosting o2 Wifi signal with Airport Express

    Dear all, I had read that one could boost our o2 Wifi signal with the Airport Express. I don't seem to be able to do it! Can anyone help. Detsky

  • HT204266 sync problems

    In my Ipod i cannot even find my App Store Icon. It disapperared somehow... Even if I download my apps from Itunes on my laptop, it wont sync either. Help plz!

  • How Warehouse Activity Monitor LL01 Report is Running in background?

    Hi Gurus, I am Working in IMWM are & giving support. Client is facing problem with this Report, as this report is not running frequently as per scheduled in Configuration settings. for e.g after 4 hrs or after 12 hrs or 1 week etc. Does any body know