?
Solved

How to set focus on next textbox on Dot Key enter

Posted on 2012-09-10
3
Medium Priority
?
741 Views
Last Modified: 2012-09-10
HI I have two textboxes one for dollars and another for cents.....i want javascript validation..dollar textbox shoud accept only numbers and dot operator...if i press "." from my keyboard it should jump to next box(cents) which also accepts only numbers..
0
Comment
Question by:RadhikaVyas
3 Comments
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38382124
Here is some sample code
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
  $('.currency').keypress(function(evt) {
    evt = evt || window.event;
    var charCode = evt.which || evt.keyCode;
    var charTyped = String.fromCharCode(charCode);
    if ($(this).hasClass('dollars') && charTyped == '.') {
      $(this).next().focus();
      return false;
    }
  });
});
</script>
<style type="text/css">
</style>
</head>
<body>
Input here <input type="text" id="dollars" class="currency dollars"/> <input type="text" id="cents" class="currency">
<div id="result">
</div>
</body>
</html>

Open in new window

0
 
LVL 23

Accepted Solution

by:
Roopesh Reddy earned 2000 total points
ID: 38382168
Hi,

Check the below code!

<input type="text" onkeydown="return NumericTextBox(event);" id="currency" />
		 <input type="text" id="cents" />
       </div>
       <script type="text/javascript">
           
           function NumericTextBox(evt) {
               var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
			   
               if (charCode == 8 || //backspace
                    charCode == 46 || //delete
                    charCode == 13)   //enter key
               {
                   return true;
               }
			   else if(charCode == 190) //Check for dot(.)
			   {
			    document.getElementById("cents").focus();
				return false;
			   }
               else if (charCode >= 37 && charCode <= 40) //arrow keys
               {
                   return true;
               }
               else if (charCode >= 48 && charCode <= 57) //0-9 on key pad
               {
                   return true;
               }
               else if (charCode >= 96 && charCode <= 105) //0-9 on num pad
               {
                   return true;
               }
               else
                   return false;
     
           } //end:NumericTextBox function
       </script>

Open in new window


Hope it helps u...
0
 

Author Closing Comment

by:RadhikaVyas
ID: 38382450
Thank You Roopesh...Its working for me...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question