How to pass the key pressed in javascript

I'm asking this question here as I could not find the needed help elsewhere .
I don't know how to pass the key pressed in the function on OnKeyPress event .
I'm trying the following :
<input type="text" name="a" onKeyPress="check();">
I want to pass the key presses in the check function .
How to collect the key pressed in the function check ?
Thanks.

As I said above, that won't work in Mozilla.
In fact IMO Netscape/Mozilla javascript event handling has been behind IE since version 4.
Be that as it may: here is a workaround (for Mozilla): It seems you have to assign the onkeypress event for it rather than declaring it as part of the textfield.
Of the two textfields on this form, both work in IE, and only the first one will work properly in Mozilla. I left it in just to demonstrate the difference.
And a couple of links for ya
javascript forum: http://forums.webdeveloper.com/forumdisplay.php?s=&forumid=3
Keypress events: http://www.din.or.jp/~hagi3/JavaScript/JSTips/Mozilla/Samples/KeyEvent.htm
<html>
<head>
<script language="javascript" >
<!--
function check(evnt){
  alert("A key was pressed!");
  // IE handling
  if (window.event){
    evnt = window.event;
    alert(evnt.keyCode);
  // netscape/mozilla handling 
  else{
    alert(evnt.which);
//-->
</script>
</head>
<body >
<form name="myform" method="post">
Test <input type="text" name="myTest"><BR>
Test <input type="text" name="myTest2" onKeyPress="check();"><BR>
<script> document.myform.myTest.onkeypress = check; </script>
</form>
</body>
</html>

Similar Messages

  • How to get the key press

    Hi,
    One more question, how do you get the keypress in the main
    movie? I've tried on onClipEvent (keyDown) key.getCode etc but that
    requires to be in a movie.

    there are a couple of ways to handle this. If you are looking
    for a sepcific Key you can set up a Listener. or more like what
    your trying here, but as in:

  • How to pass the property value to getter function

    In jsp, I have a select box,like this:
    <html:select property="chooseType" styleId="chooseType" onchange="javascript:checkType()">
    <html:option value="Type1">Type1</html:option>
    <html:option value="Type2">Type2</html:option>
    <html:option value="Type3">Type3</html:option>
    </html:select>
    javascript, I use document.getElementById("chooseType").value="Type3";
    however, i form.java file, using getChooseType(), I could not get the value "Type3". If I do not set the value by javascript, I just select "Type3" from GUI, value "Type3" is passed properly to the getter.
    How to pass the value,set in javascript to getter?
    Edited by: [email protected] on Nov 17, 2009 4:23 PM

    I just found it is caused by the following code.
    javascript, I use document.getElementById("chooseType").disabled=true;
    So if I disable the select box, the value can not be passed to form. How to disable the select box but still pass the value to form?
    Edited by: [email protected] on Nov 17, 2009 11:56 PM

  • HT4211 I just updated my iPad 2 to iOS 7 and whenever I try to type on the keyboard screen, it takes several seconds to acknowledge the key press. It really is slow.How can I fix this?

    I just updated my iPad 2 to iOS 7 and whenever I try to type on the keyboard screen, it takes several seconds to acknowledge the key press. It really is slow.How can I fix this?

    Settings>General>Reset>Reset All Settings

  • How can we trape the Keys Pressed on the Keyboard and do action depending on the keys

    I want to know how we can capture the keys pressed on the keyboard by the user and do necessary action depending on the key pressed by the user....
    For example.... If user press Alt+q the form should go in the Enter Query Mode.
    Can anyone tell me how i can do this in Form 6i....
    Please Help me out from this problem...
    Thanks in Advance
    Shan

    Can somebody point me to what I need to use to
    intercept all the 'keys' for an application.
    At the moment I have set Focus to parts of the
    application when the Mouse is over it, and then get
    the Keys with a KeyListener.
    Is there a way to get the keys, as long as the Java
    app is active.
    - Its an image display program, and I want to use keys
    for - next image , zooom etc etc.
    If soemone could just point me to the right part of
    the API to look in?java.awt.Toolkit.addAWTEventListener()
    then use the mask defined in AWTEvent.KEY_EVENT_MASK to listen to all the events.
    Steve

  • 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 pass the value within the page using jsp?

    How to passing the textbox value within the jsp page without using javascript or reload the page.
    I have a scenario like this:
    I have a textbox named as "accno" which allow user to key in the accno. After key in the accno, this accno value will used to do a query from database using jstl.
    here is part of my code
    <input name="accno" type="text" onChange="checkLC()"/>
    <sql:query var="results" dataSource="${db}">
    select accno,name from account where accno = '<%=value get from accno textbox%>'          
    </sql:query>
    <c:out value="${result.rows[0].name}"/>
    note that onChange() is the javascript when user key in accno then automatically go to check database then only show out the name. So how can i get the '<%=value get from accno textbox%>' from accno textbox.

    How to passing the textbox value within the jsp page
    without using javascript or reload the page.No, jsp executes on the remoter server, the text box is on a client machine, you need to send information to the server over the network, http does this with a request, which will reload the page.....................

  • How to pass the java object into the spring controller

    Hi Friends
    When I hit the url at the first time my call goes to the spring controller and sets the userDetails objects in the modelAndView.addObject("userDetails", userDetails.getUserDetails()) and returns the userDetails.html page. if I click any link in the same page i want to pass same (userDetails) object thru javascript or jquery and calls the another(controller) method and returns the same (userDetails.html) page.
    It means how can i pass the java object thru javascript or jquery and calls the controller. if i get the same object in my controller i can avoid calling the db again. please help me out to resolve this issue. i am tired of fixing this issue.
    Regards
    Sherin Pooja

    If you want to avoid calling the database again then cache the data.
    However before you do that make sure that calling the database, in the context of YOUR system, is going to be an actual problem.
    For example there is absolutely no point in caching a  User object when only one user an hour is actually using the system.

  • How to pass the value to "Assignment" when submit the program RFITEMGL?

    Hello friends,
    I want to submit program RFITEMGL  (t-code FBL3N) with some screen fields, some fields are OK to fill such as u201COpen at key dateu201D, u201CG/L accountu201D and u201CCompany codeu201D。 But for the field "Assignment" (It will appear after cilck Dynamic Selection), I don't know how to pass value to it.
    Could you help me about how to pass the value to "Assignment" when submit the program RFITEMGL  (t-code FBL3N) ?
    Thanks a lot!

    Hi,
    Well you can create a small BDC.
    Regards,
    Harsh Bansal

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

  • What are the key presses like on the Enhanced Performance keyboard?

    Hi guys,
    I've been thinking about buying this keyboard:
    http://shop.lenovo.com/SEUILibrary/controller/e/gbweb/LenovoPortal/en_GB/catalog.workflow:item.detai...
    I was wondering how the key presses feel?   I'm quite particular about it.   I like the press to have a definite 'soft click' (like a cross between a microswitch and a diaphragm).    A lot of keys these days are like pressing a spring with no tactile response as to when a key press has actually been registered if that makes any sense.
    Can anyone with this keyboard describe how the keys are to press?   I can't find and videos or any real life examples to test.
    Thanks,
    Leo

    if you are looking for tactility in a keyboard, than this keyboard is not the best. Maybe you should get a Filco keyboard instead.
    Microsoft and Dell's keyboard (the one with oversized spacebar) are both slightly better than these Lenovo keyboard. Alternatively get the Space Saver II keyboard. 
    Regards,
    Jin Li
    May this year, be the year of 'DO'!
    I am a volunteer, and not a paid staff of Lenovo or Microsoft

  • How to binding a key press event of "Esc" to "cancle" button

    I create a class extended JComponent. Than I add a button named "cancle " to it.
    Than I add the class's instance to a JDialog object.
    I try to get the key press event through add a keyListener to the class instance, but no works.
    I try to add a keymap and action map to the dialog 's getRootPane() also no works.
    Who can tell me how can I do?

    Thats the way I did it:
        // map escape key
        ActionListener escapeActionListener = new ActionListener()
          public void actionPerformed(ActionEvent e)
            cancelPressed();
        this.registerKeyboardAction( escapeActionListener,
                                     KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false),
                                     JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );

  • How to pass the data from a input table to RFC data service?

    Hi,
    I am doing a prototype with VC, I'm wondering how VC pass the data from a table view to a backend data service? For example, I have one RFC in the backend system with a tabel type importing parameter, now I want to pass all the data from an input table view to the RFC, I guess it's possible but I don't know how to do it.
    I try to create some events between the input table and data service, but seems there is no a system event can export the whole table to the backend data service.
    Thanks for your answer.

    Thanks for your answer, I tried the solution 2, I create "Submit" button, and ser the mapping scope to  be "All data rows", it only works when I select at least one row, otherwise the data would not be passed.
    Another question is I have serveral imported table parameter, for each table I have one "submit" event, I want these tables to be submitted at the same time, but if I click the submit button in one table toolbar, I can only submit the table data which has a submit button clicked, for other tables, the data is not passed, how can I achieve it?
    Thanks.

  • How to get the value from a JavaScript and send the same to Java file?

    Hi.
    How to get the value from a JavaScript (this JS is called when an action invoked) and send the value from the JS to a Java file?
    Thanks and regards,
    Leslie V

    Yes, I am trying with web application.
    In the below code, a variable 'message' carries the needed info. I would like to send this 'message' variable with the 'request'.
    How to send this 'message' with and to the 'request'?
    Thanks for the help :-)
    The actual JS code is:
    function productdeselection()
    var i=0;
    var j=0;
    var deselectedproduct = new Array(5);
    var message = "Are you sure to delete Product ";
    mvi=document.forms[0].MVI;
    mei=document.forms[0].MEI;
    lpi=document.forms[0].LPI;
    if(null != mvi)
    ++i;
    if(null != mei )
    ++i;
    if(null != lpi)
    ++i;
    if(null != mvi && mvi.checked)
    deselectedproduct[++j]="MVI?";
    if(null != mei && mei.checked)
    deselectedproduct[++j]="GAP?";
    if(null != lpi && lpi.checked)
    deselectedproduct[++j]="LPI?";
    if( 0!=j)
    if(i!=j)
    for (x=0; x<deselectedproduct.length; x++)
    if(null != deselectedproduct[x])
    message =message+ "-" +deselectedproduct[x];
    alert(message);
    else
    //alert(" You cannot remove all products!");
    return false;
    return true;
    }

  • How to pass the parameter of a stored procedure to iReport

    Hi... i don't know how to pass the parameter of the stored procedure to the iReport.
    In the Report Query, i tried
    1. sp_storedprocedure ' value'
    2. sp_storedprocedure +''''+$P{parameter}+''''+
    3. sp_storedprocedure +$V+$P{parameter}++$F($F is a variable having a value of ' (a single quote))may you enlighten us please? thank you

    For M$ SQL server I find that it only works when U use the fully qualified name...
    e.g. catalod.dbo.my_procedure_name 'variable'
    My full query in the Report Query window is something like this:
    EXEC arc.dbo.jasper_Invoice 1000
    Note that you may find that selecting from VIEWS / TABLES fails for no apparent reason and iReport will prompt you with the usual very unhelpful (we have what we "pay" for) prompt, stating that "The document is empty".
    To work around this issue, where a statement like "SELECT * FROM arc.dbo.acc_invoices WHERE Invoice_id=1000" does not work, simply create a PROC, something like:
    CREATE PROC jasper_MyProc (@my_rec_id integer) AS
    SELECT * FROM arc.dbo.acc_invoices WHERE Invoice_id= @my_rec_id integer
    ...to wrap your SELECT statement, then call the PROC
    Edited by: Sylinsr on Apr 22, 2008 4:23 PM

Maybe you are looking for

  • Edit in Photoshop issue

    I just upgraded to LR4 and CS6 on a MAC running 10.7.  When I edit the image in LR and click Edit in Photoshop, Photoshop opens but never actually opens the image.  Please help. 

  • Capture video on iphone applicationand play it on website

    Hi, I capture movies with my iphone application. I think the only format the iphone creates is .mov - does it? Anyway, later, I save the video file on Amazon server (AWS) and I want to be able to view the video again both on iphone devices and on my

  • Linux file name into ODI variable

    Hello All, I have a situation where we have files in one directory in linux ,I want to import the file name into a ODI variable. Ex : A_B_C_2014_01_20.zip (inside this zip file are the flat files with data) is the file name in /u02/source_files locat

  • InDesign CS6 crashes everytime I try to export to PDF

    This happens now regardless of what type of file I have open. Even if I create a new document add just a rectangle coloured box, when I go to export it crashes everytime. This is a nightmare as I have a tight dealine!!! Everyone I speak to recently i

  • Xcelsius Connectivity with BI

    Hi Gurus, I have few questions about connecting Xcelsius directly to BW. 1] Is there any downside of directly creating connection between Xcelsius and SAP? 2] For how long QaaWS would be available? 3] If given an option which way we should go QaaWS o