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

Similar Messages

  • How can I access JSP variables from a JavaScript function in a JSP page?

    Respected sir
    How can I access JSP variables from a JavaScript function in a JSP page?
    Thanx

    You may be get some help from the code below.
    <%
        String str="str";
    %>
    <script>
        function accessVar(){
           var varStr='<%=str%>';
           alert(varStr);// here will diplay 'str'
    </script>

  • How to pass a jsp variable into javascript??

    <p><%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
    <p><%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
    <p><html>
    <p><c:set var="binrmapi" value="http://localhost/paas-api/bingorooms.action;jsessionid=XXXXXX?userId=TEST2&sessionId=1&key=1" />
    <p><c:import var="testbinrm" url="${fn:replace(binrmapi, 'XXXXXX', jsessionid)}"/>
    <p><c:set var="tuples" value="${fn:split(testbinrm, '><')}" />
    <p>Time until next game
    <p><c:forEach var="tuple" items="${tuples}">
    <p><c:if test="${fn:contains(tuple, 'row ')}">
    <p> <p><code>
    <p> <c:set var="values" value="${fn:split(tuple, '=\"')}" />
    <p> <font color="blue">
    <p> <c:out value="${values[17]}" />
    <p><c:set var="remainingtime" value="${values[17]}" />
    <p> </font>
    <p> </code>
    <p></c:if>
    <p></c:forEach>
    <p><form name="counter"><input type="text" size="8" name="d2"></form>
    <p><script>
    <p>var milisec=0
    <p>var seconds=eval("document.myForm.remaining").value;
    <p>function display(){
    <p> if (milisec<=0){
    <p> milisec=9
    <p> seconds-=1
    <p>}
    <p>if (seconds<=-1){
    <p> milisec=0
    <p> seconds+=1
    <p> }
    <br>else
    <p> milisec-=1
    <p> document.counter.d2.value=seconds+"."+milisec
    setTimeout("display()",100)
    <p>}
    <p>display()
    <p></script>
    <p></body>
    <p></html>
    <p>This is my code that i was working on, in the jsp part of the script, i get a api call and save a value of time in the variable remainingtime.. and in the javascript, i try to have a countdown clock counting down the remaining time.. but i guess it doesnt work.. how can i get that working? thanks alot
    Message was edited by:
    hamham3001
    Message was edited by:
    hamham3001
    Message was edited by:
    hamham3001
    Message was edited by:
    hamham3001

    Re: How to pass a jsp variable into javascript??Here is the sameple one, hope it will solves your problem.
    <html>
    <body>
    <form name=f>
    <%!
    String str = "A String"
    %>
    <script>
    var avariable = <%=str%>
    <script>
    </form>
    </body>
    </html>
    Let me know if you face any problem

  • How to put the alv output into the spool request?

    Hi guys,
    How to put the alv output into the spool request?
    Thanks!

    Hi
    Sending an ALV List screen output to SPOOL
    Convert ALV list to PDF and send mails to respective persons
    Regards
    Pavan

  • How do I enter a variable into an equation?

    How do I enter a variable into an equation?

    Jacob,
    Spreadsheets don't use equations, so the usual nomenclature can be confusing.
    When you enter something into a spreadsheet cell, it is either a Literal Value (Constant), or an Expression, preceded by an equal sign, that tells the spreadsheet to display something. Every Cell Reference in the Expression is a Variable. The equal sign in this case does not signify an equality, it just signals the spreadsheet that you want it to do something, defined by the expression that follows.
    Here's an equation: A1 = B1 + C1 + 10, where B1 and C1 are variables and 10 is a constant.
    To figure out what the value of A1 is, you write an expression in cell A1. That Expression would be: =B1 + C1 + 10. The operation that is performed by the spreadsheet is that it looks at B1 and C1, adds whatever it sees there and then adds the constant 10, and displays the result in A1.
    It can get very complex. Expressions can contain Functions that catch the Time or generate a random number, or round a value, etc. Just remember that anything you see in a cell can be changed, so that content, that cell address, is a variable
    Jerry

  • How to put IPOD Shuffle I into Disk Mode ?

    How to put Ipod Shuffle I into diskmode ?

    When connected, in iTunes click on shuffle icon in Devices, then click on Settings tab. Scroll down and click the square in front of "Enable disk use", the adjust slider for amount of flash memory to reserve for data. Click Apply, and you're done!
    When you use iPod shuffle as a disk, the status light on the front of iPod shuffle blinks orange continuously, and the iPod shuffle disk icon appears on the desktop on the Mac, or as the next available drive letter in Windows Explorer on a Windows PC. Drag files to and from iPod shuffle to copy them.
    Ejecting iPod shuffle Important: If the iPod shuffle status light is blinking orange, you must eject iPod shuffle before disconnecting it from your computer. If you don’t eject iPod shuffle before disconnecting it, you could damage files on iPod shuffle.
    To eject iPod shuffle:
    Click the Eject (C ) button next to iPod shuffle in the iTunes Source list. If you’re using a Mac, you can also eject iPod shuffle by dragging the iPod shuffle icon on the desktop to the Trash.
    If you’re using a Windows PC, you can eject iPod shuffle by clicking the Safely Remove Hardware icon in the Windows system tray and selecting your iPod shuffle.

  • I loaded my ipad photos from camera and all the pictures sorted by date.  Next, I did a sync with my computer and the photos were all reorganized into IMPRT folders an out of date sequence.  Any idea how to put the photos back into date files?

    I loaded my ipad photos from camera and all the pictures sorted by date.  I later sync my ipad with my computer and the photos were all reorganized into IMPRT folders an out of date sequence.  Any idea how to put the photos back into date files other than reloading all of them from camera?

    What version of iPhoto?
    Select one and rotate it. Then rotate it back. Does that make it appear? 
    A much better work flow is the keep the photos after importing.  Check the success the import, wait for at least one successful backup cycle then use you camera's format command to reformat the card
    LN

  • How to convert an int variable into String type

    hi everybody
    i want to know how to convert an interger variable into string variable
    i have to implement a code which goes like this
    Chioce ch;
    for(int i=0;i<32;i++)
    // here i need a code to convert the int variable i into a string variable
    ch.add(String variable);
    how do i convert that int variable i into a String type variable??
    can anyone help me?

    Different methods:
    int a;
    string s=a+"";or
    String.valueOf(int) is the better option because Int.toString() generated an intermediate object to get the endresult
    Ema

  • Parsing JSP variable into JavaScript

    Hi,
    I am trying to parse a JSP variable into a pice of JavaScript code:
    <%
    some jsp code .....
    String table_name=cols[0].toString();
    %>
    <script language="javascript">
    var jsTemp = <%=table_name%>
    alert ('jsTemp')
    </script>
    <%some more JSP....
    This does not create an alert, any ideas why? Am I missing a quote/semi-colon somewhere?

    Sure this is being executed,
    when trying to run, this does not work:
    String table="TEST";%>
    <script language="javascript">var jsTemp = <%=table%> alert ('jsTemp');</script>
    <%more JSP...
    when trying to similarly run, I get the popup 'HELLO':
    String table="TEST"; //not used anymore%>
    <script language="javascript">var jsTemp = "HELLO"; alert ('jsTemp');</script>
    <%more JSP...
    Is there supposed to be a semi-colon after <%=table%> ? Or is there another issue with this bit of code?

  • How to import existing jsp project into jdeveloper

    can someone help me how to import existing jsp project into jdeveloper?
    can give me step by step to import..cause i am new for jdeveloper..
    thank you very much

    Well there are two options - if you have a WAR file with the code in it, then you can use the file->import WAR.
    Or you can use the new->Project from source code.
    Note that you'll probably need to do some library settings and some directory setting after that.
    Have a look at this demo for basic steps:
    http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/NBtoJDevProject/NBtoJDevProject.html

  • How do I look up how to put Cafe townsend  tutorial into dreamweaver

    How do I ask how to put Cafe Townsend Tutorial into dreamweaver. I have a mac. The tutorial notes say follow this line
    (Mac OS X) Macintosh HD/Users/your_user_name/Documents/local_site. I don't understand what each section means. If someone called explain it that would be great as I ended up with an empty folder in dreamweaver with the name 'Cafe Townsend' on it. Thank you

    Right.  It's an empty local site folder until you put something into it. 
    Go to step 2.  Download and unzip the Check_Magazine.Zip files
    http://download.macromedia.com/pub/developer/check_magazine.zip
    Go to step 3. Copy the check_magazine folder into your local_sites folder (Cafe Townsend).
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    www.alt-web.com/
    www.twitter.com/altweb
    www.alt-web.com/blogspot.com

  • Accessing JSP variables in Included Javascript

    Hey All,
    I want to hide my javascript to be viewed on the client browser.
    I know we can do that with the javascript include ,But i am using JSP variables in
    Included javascript.I can't access those variables any more.
    Does anybody know any workarround.
    Thanx
    Vijay

    Hi Vijay,
    I am also facing the same problem of hiding javascript in the client browser. My javascript variables are getting initialised on the fly using JSP. Since JSP is compiled on the server side, one can't compile .js file on the client side.
    What u can do is to divide your page into frames with
    <frameset rows="100%,0%">. Now put your form hidden fields or the .js file in frame 2 which is not visible to the user and then assign your jsp variables in the frame2 html/jsp page. Now access your variables from frame2 in frame1 using
    var i = parent.frames[1].document.forms[0].elements[0].value
    Assuming that there is 1 form and 1 hidden field in frame2 html/jsp page.
    I hope u get the logic rite....
    I had done it for application but problem is that our users are real MORONS and they keep doing ctrl+F5 which takes them to the Indexpage.
    If you get some other solution then please mail it to my email address
    [email protected]
    Regards
    Vimlesh

  • How to pass a JSP var to a Script function called in a netui:checkbox

    How to pass a JSP variable to a Java Script function called in a netui:checkbox onSelect?
    I have a requirement where based on the checkBox selected or deselected in a repeater tag I would have to select or deselect other checkboxes in a netui:form. I am trying to pass the index or unique name of the checkbox to the JavaScript function. When I try this code I am getting a Syntax Error!! and getting a " item undefined" in the javascript. This works when I use just the html form tag but when I use the <netui:form> tag I am facing this issue. Any help would be highly appreciated.
    function selectACheckBoxOnClick(name) {
    alert ("called selectACheckBoxOnClick ");
    alert ("called name "+name);
    <netui-data:repeater dataSource="{pageFlow.unregisteredContractAssetsDTOArr}">
    <netui-data:repeaterItem>
    <% String checkboxName = "selectACheckBox_"+i;
    String serialNum = "serialNum_"+i;
    String hidenboxName = "hiddenACheckBox_"+i;
    String loopNo = new Integer(i).toString();
    System.out.println("Loop String :"+ loopNo);
    System.out.println("CheckBox Name:"+ checkboxName);
    System.out.println("serialNum :"+serialNum); %>
    <tr bgcolor="#ffffff">
    <td align="center">
    <netui:checkBox dataSource="{container.item.selectedAssetFlag}" onSelect="selectACheckBoxOnClick(<%=checkboxName%>);" tagId="<%=checkboxName%>"/>
    </td>
              <td class="small"><netui:label value="{container.item.model}"/></td>
              <td class="small">
    <netui:hidden dataSource="{container.item.splitAssetNo}" tagId="<%=serialNum%>"/>
    <netui:label value="{container.item.serial}"></netui:label></td>
              <td class="small"><netui:label value="{container.item.equpimentId}"/></td>
              <td class="small">
    <netui-data:getData resultId="siteId" value="{container.item.siteNo}" />
    <%String siteId = (String) pageContext.getAttribute("siteId");%>
    <netui:anchor action="getSiteLevelAssets" formSubmit="true">
    <netui:parameter value="{container.item.siteNo}" name="siteNo" />
    <netui:label value="{container.item.siteNo}" />
    </netui:anchor>
    </td>     </tr>
    <%i++;%>
    </netui-data:repeaterItem>
    </netui-data:repeater>
    This code works within a form:
                   <td align=center>
                        <input type=image name="unassign" onclick="javascript:unassignReplacement(<%=replacementSupply.getPMSupplyId()%>)" src="<%=request.getContextPath()%>/images/bt_sm_x.gif" border=0 alt="Unassign">
                        </td>
    Thanks,
    Salome

    hi
    i did not go thru your code completly
    but u can use the following for your problem
    the checkbox in the repeater must have unique TagID
    counter = 0; (initialize)
    <netui-data:repeaterItem>
    <netui:checkBox dataSource="" tagId='<%="count"+String.valueOf(counter)%>' onClick="some function()" />
    <%counter++;%>
    </netui-data:repeaterItem>
    here if u have 3 checkbox
    They will have Tagid's as count1 , count2 and count3
    now in the javascript somefunction()
    use the following line
    for(j=0;j<<%=counter%>;j++)
    document.forms(0)[getNetuiTagName"count"+j)].checked=false;     
    }

  • How to store serval char variables into a string variable?

    I have serval char variables, but i don't know how to put them together (without using arrays). I am thinking to store these char variables into a string variable but i don't know how to do it. For example,
    char letter1 = 'a', letter2 = 'b', letter3 = 'c';
    String letters;
    then how can i do to make letters = "abc" from using letter1,2,3?
    I am just a beginner of Java, if anyone can help me, i will appreciate that very much!!!

    String letters=""+leter1+letter2+letter3;is fine and dandy. What it actually compiles to is
    String letters = new StringBuffer().append(letter1).append(letter2).append(letter3).toString();Which ofcourse is much more code to write, but still good to know.
    So do see the API for java.lang.StringBuffer.
    Heikki

  • How to deploy a JSP page into my APEX application?

    hi all,
    i am using a JSP to upload multiple spreadsheets into the db. i want to deploy it on the APEX and use it as part of my APEX application's uploading feature.
    i already have the JSP file with me. can somebody please tell me how to put that onto the APEX?
    Thanks,
    Basavaraj

    One way using JSP portal is, creating Portal project with JSP Dynpage applications
    You can use NWDS tool to create JSP Dynpage based Portal components.
    Procedure to create and deploy Portal  components,
    1. Open Enterprise Portal Perspective in NWDS
    2. Create -> new Portal Project -> Give the valid name
    3. Right click on the project -> Choose Portal Object -> JSP Dynpage -> Give all the information including JSP name. -> Finish
    4. Right Click on the project structure -> Properties -> Java Build Path -> All the following jars
            htmlb, com.sap.portal.html_api.jar, servlet
    5. Navigate to your JSP page located under the folder PORTAL-INF, Write logic
    6. Right click on the portal projet-> Refresh -> Re-Build
    7. Right Click on the portal project -> Export -> Give the Valid  Portal serverdetails, Admin user name and password
    8. You can create iView (iView from PAR) in content admin for the developed portal component
    Ram

Maybe you are looking for

  • Video podcasts in playlists

    I have a smart playlist on my iPod with one rule: Video Kind is Movie When I play videos from this list I hear the audio, but the video is frozen on a frame. All videos work fine when played from the main Videos menu. Is anybody able to play video po

  • Upon clicking Firefox icon-Firefox page does not open

    Without any apparent reason, upon clicking Firefox icons, Firefox does not open. Appears the sign asking to wait on the screen, and the graphics for the icon being "pressed" but the page does not appear. Thanks!

  • Display alll Tax types in PLD

    How to display all the tax types for an item in PLD.....?

  • H.264-Audio but no video

    I recently updated my Quicktime Pro with the new H.264 update, but when I watch a movie, I get audio but no video. Any ideas?

  • Upgrading to Mac OS X Leopard

    So I want to upgrade to Leopard but my PowerBook runs on OS X 10.3.9 and it says I need at least 10.4 to upgrade? Does this mean I have to upgrade to Tiger first?? Is there an update I can download to get to 10.4 so that I can upgrade to Leopard? Tha