- <html
- xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>JavaScript to automatically move from one field to another field</title>
- <script type="text/javascript">
- function movetoNext(current, nextFieldID) {
- if (current.value.length >= current.maxLength) {
- document.getElementById(nextFieldID).focus();
- }
- }
- </script>
- </head>
- <body>
- <b>Enter your Text:</b>
- <input type="text" id="first" size="4" onkeyup="movetoNext(this, 'second')" maxlength="3" />
- <input type="text" id="second" size="4" onkeyup="movetoNext(this, 'third')" maxlength="3" />
- <input type="text" id="third" size="5" maxlength="4" />
- </body>
- </html>
10 Aralık 2015 Perşembe
Automatically Move Cursor to Next Field When TextBox is Full
Phone No (xxx-xxx-xxxx ) Validation in JQuery
- < script type = "text/javascript" >
- //==================================
- // xxx-xxx-xxxx Phnoe No Validation
- //==================================
- jQuery(document).ready(function() {
- $("#phone").keydown(function(e) {
- // Allow: backspace, delete, tab, escape, enter and .
- if ($.inArray(e.keyCode, [46, 8, 9, 27, 13]) !== -1 ||
- // Allow: Ctrl+A
- (e.keyCode == 65 && e.ctrlKey === true) ||
- // Allow: home, end, left, right, down, up
- (e.keyCode >= 35 && e.keyCode <= 40)) {
- // let it happen, don't do anything
- return;
- }
- // Ensure that it is a number and stop the keypress
- if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
- e.preventDefault();
- }
- var curchr = this.value.length;
- var curval = $(this).val();
- if (curchr == 3) {
- $("#phone").val(curval + "-");
- } else if (curchr == 7) {
- $("#phone").val(curval + "-");
- }
- });
- }); < /script>
Auto-Complete Input in HTML
- <input id="Input1" autocomplete="off" list="ListCountry" type="text" />
- <datalist id="ListCountry">
- <option value='India'> </option>
- <option value='US'> </option>
- <option value='China'> </option>
- </datalist>
Convert JSON Data into HTML
- <div class="container">
- <p>
- <table id="placar" class="table table-condensed table-bordered">
- <thead>
- <tr>
- <th>#</th>
- <th>Name</th>
- <th>K</th>
- <th>D</th>
- <th>Point</th>
- </tr>
- </thead>
- <tbody></tbody>
- </table>
- </div>
Now as JSON for that Add below code in the JavaScript file:
- var data = [{
- 'order': '1',
- 'name': 'Harshad',
- 'k': '3',
- 'd': '0',
- 'score': '121',
- 'id': '540'
- }, {
- 'order': '2',
- 'name': 'Rajesh',
- 'k': '15',
- 'd': '3',
- 'score': '122',
- 'id': '541'
- }, {
- 'order': '3',
- 'name': 'Bingo',
- 'k': '0',
- 'd': '23',
- 'score': '123',
- 'id': '542'
- }];
- var currentID = 541;
- var transform = {
- tag: 'tr',
- children: [{
- "tag": "td",
- "html": "${order}"
- }, {
- "tag": "td",
- "html": "${name}"
- }, {
- "tag": "td",
- "html": "${k}"
- }, {
- "tag": "td",
- "html": "${d}"
- }, {
- "tag": "td",
- "html": "${score}"
- }]
- };
- $('#placar > tbody ').json2html(data, transform);
If you do the upar thing ur output is below:
JS : JavaScript LocalStorage and SessionStorage
The storage objects enable you to set data that is "remembered" as the user visits all of the pages on your domain. There are two types of storage objects that we can establish, sessionStorage andlocalStorage. sessionStorage data is only available in the tab it was established in, and will expire when the tab is closed. localStorage data is more long term, it is available in all tabs and remains persistent even if the browser software is closed then re-opened.
- //Page1.html
- < script >
- // Establish both types of storage data for a test
- localStorage.setItem("firstname", "Kaushik"); // persistent data
- sessionStorage.setItem("lastname", "S"); // persistent session data
- < /script> < a href = "page2.html" > Go to other page < /a>
Notice how sessionStorage data is not available when you open Page2.html in a new tab, or if the browser is closed. And notice how localStorage data remains persistent even in new browsing tabs and when browser is closed/opened.
- page2.html
- < script > document.write(localStorage.firstname + " " + sessionStorage.lastname); < /script>
Kaydol:
Kayıtlar (Atom)