JavaScript - Alloving Only Numbers Plus Two Letters In A Textbox
hi everybody, i'm using this function to allow only numbers to be written in a textbox, however i want to allow lowercase "a" and "b" also with the numbers.. is it possible with this function?
Code: <script type="text/javascript"> function rakamkontrol2(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } </script> </head> <body> <input type='text' id='gostergesayfa' size="3" onkeypress="return rakamkontrol2(event)"/> Similar TutorialsHi, I have an array which is populated by a count of instances from another array, so its ends up with data like: msg = [2 x this event, 5 x that event, 17 x another event, 22 x something else] I need to sort this by the number before the 'x'. At present, a .sort() would put 1 - 9 before anything greater than 10, obviously not what I'm after. How can I make it put this array into the correct order (e.g 22 x something else, 17 x another event, 5 x that event, 2 x this event) Thanks! Ic. Hi, I'm very new to javascript, and I'm working on a simple script that will allow me to take a string of numbers, and convert it to a word. For example: I type 00010203 into a box, and it would return abcd. I've got the above to work, however..I'd like to add a couple special characters so that when the user types in a string that contains "32" it will return a ' ' (space). For example: 000102033200010203 would return 'abcd abcd' Here's my code, as of now: Code: <script type="text/javascript"> function show_prompt() { var s = prompt("Please enter a string of numbers"); for (i = 0; i <=s.length; i = i+2) { var t = s.slice(i,i+2) var n = parseInt(t,10) + 97 document.write (String.fromCharCode(n)) } } </script> Below is the script and form fields I am working with. What I want to do is sum the two textbox fields and have the result show in the total textbox. The code works fine and the total textbox is updated with the value of form1.basic. The problem occurs when I add the "+ parseInt(document.form2.supporter.value)" code in the script section. What am I doing wrong? Thank you for your time and help. Code: <script type="text/javascript"><!-- function updatesum() { document.frmtotal.total.value = parseInt(document.form1.basic.value) + parseInt(document.form2.supporter.value)} //--></script> <tr> <td width="111"><form id="form1" name="form1" method="post" action=""> <label for="basic">$</label> <input name="basic" type="text" id="basic" size="7" maxlength="7" onchange="updatesum(this.form)" /> </form></td> </tr> <tr> <td><form id="form2" name="supporter" method="post" action=""> <label for="supporter">$</label> <input name="supporter" type="text" id="supporter" size="7" maxlength="7" onchange="updatesum(this.form)" /> </form> Hi.. I have form and i want to input data using barcode and it will display on textbox and after input on the first textbox the focus will go to next textbox untill it will go on the last textbox and on the last textbox it will automatically save the data's on the database. How is it possible? here is my sample code: Code: <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); ?> <html> <head> <script type="text/javascript"> function ini() { // Retrieve the code var code =document.getElementById ("code_read_box1").value; var code =document.getElementById ("code_read_box2").value; var code =document.getElementById ("code_read_box3").value; var code =document.getElementById ("code_read_box4").value; var code =document.getElementById ("code_read_box5").value; var code =document.getElementById ("code_read_box6").value; // Return false to prevent the form to submit return false; } </script> </head> <body onLoad="document.barcode.code_read_box1.focus()"> <form name=barcode onsubmit = "return ini()"> <input type="text" id="code_read_box1" value="" /><br/> <input type="text" id="code_read_box2" value="" /><br/> <input type="text" id="code_read_box3" value="" /><br/> <input type="text" id="code_read_box4" value="" /><br/> <input type="text" id="code_read_box5" value="" /><br/> <input type="text" id="code_read_box6" value="" /><br/> </form> </body> </html> Hello. I've been teaching myself HTML and CSS for a while, and now I've moved into the world of Javascript (but I'm still very much a beginner). For practice, I've been building a sample sign up form for a mock website, and I'm having problems with the birthdate section. The idea I had was to have MM, DD, and YYYY be the default values of my 3 textboxes (as an example for users), then set the value to nothing when the box gained focus. That all works fine, but I ran into problems when I tried to write an if statement to set the value back to MM, DD, or YYYY if the value was still nothing when the user clicked away. As it is now it just replaces the text inputted into the textbox (which of course is not good). Any ideas for what the problem might be? Code: <form name="signup" action="javascript:void(0);" method="post"> <table> <tr> <td>Date Of Birth:</td> <td> <input name="DOBmonth" type="text" value="MM" size="2" style="color: #555555;" onFocus="clearDOBmonth()" onBlur="restoreDOBmonth()" /> <input name="DOBday" type="text" value="DD" size="2" style="color: #555555;" onFocus="clearDOBday()" /> <input name="DOByear" type="text" value="YYYY" size="4" style="color: #555555;" onFocus="clearDOByear()" /></td> </tr> <tr> <td></td> <td><button name="Submit" type="submit" style="font-size: 1em;">Sign Up</button></td> </tr> </table> </form> <script type="text/javascript" language="javascript"> <!-- document.signup.DOBmonth.value="MM"; document.signup.DOBday.value="DD"; document.signup.DOByear.value="YYYY"; function clearDOBmonth() { document.signup.DOBmonth.value="";} function clearDOBday() { document.signup.DOBday.value="";} function clearDOByear() { document.signup.DOByear.value="";} function restoreDOBmonth() { if ('document.signup.DOBmonth.value = ""') { document.signup.DOBmonth.value = "MM"; // alert(document.signup.DOBmonth.value); } } //--> </script> Another side question, if I set a variable equal to the value of a textbox, then change the value of the variable, does that also change the value of the textbox? or is the variable no longer associated with the textbox. Example: Code: var a = document.form.textbox.value; a = blue; does document.form.textbox.value = blue? or is var a now completely independent of the textbox value? Thanks! Hi all, I'm trying to change our shopping cart code by making a small modification. When editing a product, there is a dimensions box which currently only allows numbers. We want it to allow numbers and letters (don't ask why). The code we have is the following which we think is related to why our shopping cart won't allow letters in the box. Could someone please edit the following code to allow letters? Thank you. Code: if(isNaN(dimensionsFormat(prodWidth.value)) && prodWidth.value != "" && !sellingDP) { ShowTab(0); alert("%%LNG_EnterWidth%%"); prodWidth.focus(); prodWidth.select(); return false; } if(isNaN(dimensionsFormat(prodHeight.value)) && prodHeight.value != "" && !sellingDP) { ShowTab(0); alert("%%LNG_EnterHeight%%"); prodHeight.focus(); prodHeight.select(); return false; } if(isNaN(dimensionsFormat(prodDepth.value)) && prodDepth.value != "" && !sellingDP) { ShowTab(0); alert("%%LNG_EnterDepth%%"); prodDepth.focus(); prodDepth.select(); return false; } Hey everyone Okay so... I'm working on a site, which will include a registration form for users that wish to register. In this registration form I would like it to have an AJAX based effect, such that when the user types each letter out for his username in the field, his username will appear (letter upon letter) itself below, at the end of their unique url. To explain further:- Say I type my username to be Owen Below the field I would like it to display: http://www.mydomain.com/Owen http://Owen.mydomain.com/ As I type it. Is this possible? I've done my research, but had little luck. I'm sure it is possible as I've seen it before in a slightly different manner. Hope you can or are willing to help Thank you Owen Ayres I have a document list of several hundred drug names where some are lower case and some are all caps. I want to bold only the lower case drug names but don't want to do it manually. Is there a java script that I can apply where it automatically does that for me?
I am trying to make a JavaScript chat-bot I was using this to answer a month questions and it worked fine for what is the month after DatesA=new Array("january,February","february,March","march,April","april,May","may,June","june,July","july,Aug ust","august,September","september,October","october,November","november,December","december,January "); if (input.search("what is the next month after")!= -1) {document.result.result.value = "Sorry, I don't know."; for (i=0; i<DatesA.length; i++) { Date=DatesA[i].split('='); if (input.search(Date[0]) != -1) { document.result.result.value = Date[1];} } return true;} What is the month after May answer: June however it didn't with letters. Is there a way to write this to prevent the wrong single letter and small words from triggering Letterbefore=newArray("b=a","c=b","d=c","e=d","f=e","g=f","h=g","i=h","j=i","k=j","l=k","m=l","n=m", "o=n","p=o","q=p","r=q","s=r","t=s","u=t","v=u","w=v","x=w","y=x","z=y"); Then use this: if (input.search("what is the letter before")!= -1 || input.search("what letter comes before")!= -1) {document.result.result.value = "Sorry."; for (i=0; i<Letterbefore.length; i++) { Letter=Letterbefore[i].split('='); if (input.search(Letter[0]) != -1) { document.result.result.value = Letter[1];} } return true;} . The bot correctly answers for x y and z . It then answers V for all other letters, digits and short words What is the letter before cow answer: V Thank you for your time I'm working on a script to check password strength "onkeyup",so when the user enters a password after every character i call a function to check the passwords strength.I'm almost ready,but i stucked with one thing: I want to check the same characters in the password,so i can deduct some point from the score if there are identical characters. Here is my code: PHP Code: var multis = 0; for(var x = 1; x < passLength; x++) { actChar = new RegExp(password.charAt(x),"g"); multis += password.match(actChar).length; } I know it seems an easy task,but i've spent at least 6 hours with it,(the first pitfall was that i didn't know the RegExp function and took my variables into the match() function,i think you can imagine the results)and i just can't figure this out,i always get crazy results,i've tried a few more versions as well without any luck. Thx in advance for anybody who can help me! Hi wise javascript gurus, I am working on a small form that on the click of a button, it calls a function to validate a string that consists of 3 portions delimited with a dash("-") in the following format XXX-NNNN-XXX where X are letters only where N are numbers only I have to use regular expressions to validate the first portion and verify that its exactly 3 characters long that are letters only if the first portion or "plant code" is larger then 3 characters long an alert gets display also if the first portion contains alphanumeric or numeric characters an alert gets displayed, the first portion has to be in letters only. down below is my code that is not functional at the time because I know for sure the way I check for regular expressions is a bet washy but thats the only thing I was able to come up with, any help will be appreciated. thanks for making time to read my thread Code: <html> <head> <script type="text/javascript"> function validateit() { var number = document.myform.product_number.value; var charnum = number.length; if (number =="") alert("you must enter a product number, field cannot be empty"); else if (charnum < 12 || charnum > 12) alert("the product numbre has to be exactly 12 characters long"); else validate_number(number); } function validate_number(num) { var objRegEx = /^[a-z]+$/; split=num.split("-",3); if (split[0].length!=3) alert("the Plant Code portion of the Product Number has to be only three charactes long") if!(objRegEx.test(split[0]) alert("the Plant Code portion of the Product Number has to be letters only") } </script> <title>waldo's</title> <style type="text/css"> .heading{font-weigth:bold;text-align:center; font-family:"comic sans MS"} </style> </head> <body><form name="myform"> <table align="center" border="1" width="55%"> <caption style="font-family:'comic sans MS';font-size:26pt"> Waldos's WareHouse</caption> <tr class="heading"><td>Product Number</td><td>Plant Code</td><td>Production Run</td><td>Shift Number</td></tr> <tr><td><input type="text" name="product_number"></td><td><input type="text" name="plant_code" readonly></td><td><input type="text" name="production_run" readonly></td><td><input type="text" name="shift" readonly></td></tr> <tr><td><input type="button" value="Check Validity" onclick="validateit()"/></td><td align="right">Validation Date:</td><td colspan="2"><input type"text" size="47" readonly></td></tr> </table></form> </body> </html> Hi all, Forgive my ignorance, I'm quite new to Javascript... I'm looking to do two things: the first is to move elements of an array to the next index using a function. I have managed to do this like so: Code: var letters = ['h','i','j','k']; function moveElements(anArray){ var newArray = anArray; newArray.unshift(newArray[newArray.length-1]); newArray.pop(); } moveElements(letters); (this may or not be great, but it seemed to work) ... but I want the original array to reset to its original state if the function is called again (thus producing the same answer as opposed to shifting the elements again). Secondly, and this is the bit I'm really struggling with: I want to compare each letter of a string to elements within an array and display the indices. For instance: Code: var myArray = ['a', 'b', 'c', 'd', 'e', 'f']; var text = 'dead'; Hence I want the result '3,4,0,3'. I know the answer will use for and if statements but I can't wrap my head around it at all. Help would be appreciated, thank you. Hey I'm trying to make a script which will check if the string which the user sent from a form contains ONLY letters. The problem is if the user entered something like this "25 years old" it allow that to be submitted. It only blocks submissions of the form if the user submits NO letters like this "12345". I want it to block submissions if at least one character isn't a letter. Here's my code: Code: var message = document.myform.formtest.value; var allowed = /[A-z+]/; if(!allowed.test(message)) { alert("The field only allows letters (a-z)."); return false; } Hi, can anyone tell me how to detect any word (a-z only, surrounded by whitespace) less than 5 letters long? Edit - this is what I have currently: Code: var RE=/\s([a-z]{1,4})\s/gi; var string="some words"; //should be turned to "words" string=string.replace(RE, ""); This is taking 4 letter chunks from the end of words. Cheers, Gus Edit - fixed (replaced \s with \b) Hay! I have a silly question, I have a row of numbers, 1 to 250. The numbers are all in one horizantal line. But I want to use a <br> after every 10 numbers. I tried: if(i % 10) { document.write("<br>"); } This is how I wanted to be: 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, Does any one know how can I achieve this I'm still a noob. I have written below code to except only number in a textbox. This is working fine. However, When I'm copying and pasting, then it is taking non-numbers. Code: <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <SCRIPT type="text/javascript"> function isNumberKey1(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode = 46 && charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } </SCRIPT> </head> <body> Phone number : <input type="text" id="phonenumber" onkeypress="return isNumberKey1(event)" maxlength="10" size="15" > <br /> <br /> Alternative number: <input type="text" onkeypress="return isNumberKey1(event)" id="alt" maxlength="10" size="15"> <input type="button" value="Submit"> </body> </html> say cutcost2 is 10 and qty is 25 Code: document.profile_quote.cuttotal.value = eval(document.profile_quote.cutcost2.value + document.profile_quote.qty.value) .toFixed(2) the output i get is 1025 rather than 35. what have i got wrong? thanks I'm trying to teach myself Javascript to prepare for it next term. I asked earlier how to add together the numbers 1-10 in a loop. Now I'm wondering how can I change the 10 to be a valuable I input. Basically I want to be able to enter a number on the page or in a message box then I want the code to add all the numbers from 1- the number I enter. The code I got from my previous thread is he Code: <html> <head> <script type="text/javascript"> var varX = user input; function sum() { var varX = user input; for(varY = 1; varY<=10; varY++) { varX = varX + varY; } return varX; } var resultat = sum(); alert(resultat); // show message box with result </script> </head> <body> </body> </html> Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> </head> <script type = "text/javascript"> var strCurrency = new Array(6); strCurrency[0]="Pound"; strCurrency[1]="Marc"; strCurrency[2]="Franc"; strCurrency[3]="Dollar"; strCurrency[4]="Nordic"; strCurrency[5]="Fivesmon"; var dblExchangeRate = new Array(6); dblExchangeRate[0]="1"; dblExchangeRate[1]="74"; dblExchangeRate[2]="8.54"; dblExchangeRate[3]="6.25"; dblExchangeRate[4]="98.1"; dblExchangeRate[5]="1.32"; function convertNumbers { } </SCRIPT> I want to see what the function would look like to be able to convert into different currencies by using arrays. I know that this would be a useless way to do it as they are updated every day, but it's for personal education purposes. (Note: The website contained a textbox in which to enter the amount in pounds, a drop-down box allowing the user to select currency, a button to click to convert, and another text box showing amount of money after converting.) Any help is greatly appreciated. |