473,320 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to convert the value of textbox to number

75 64KB
I want to ask. how do i start codding this ?
i want to convert the value of textbox to number.

example the value of textbox is " box "

and there are the right value per letter.

b = 1
o = 3
x = 2
... and so on.

hmm, can i make it in java script or in php ?
Jul 15 '12 #1
2 4455
Claus Mygind
571 512MB
If you want the conversion to happen when the user is typing the content into the text "box" then you will have to use javaScript. If you want the conversion to happen when the user submits the form to the server you will have to use php

Here is a js script that changes the content with the onChange() event handler. You may be able to make it faster by using regExp. Or you could even have it convert as the user is typing each character by using the onkeypress() event handler.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.     <head>
  4.         <script type="text/javascript">
  5.             function convertTxtBox(obj){
  6.  
  7.                 //capture the id and value of the control element being processed
  8.                 var elm = obj.id;
  9.                 var val = obj.value;
  10.  
  11.                 //create an object with conversion values
  12.                 lookup = {b:1, o:3, x:2};
  13.  
  14.                 //initilize return value
  15.                 var retVal = '';
  16.  
  17.                 //loop through each letter in text box and convert
  18.                 for (var i = 0, l = val.length; i < l; i++) {
  19.  
  20.                     //get the current charcter in the string
  21.                     var re = val[i];
  22.  
  23.                     //replace numeric value found in lookup object or return same character if not found
  24.                     retVal += ( lookup[re] ) ?lookup[re] : re;
  25.                 }
  26.                 //replace the text box value with converted value
  27.                 document.getElementById(elm).value = retVal;
  28.             }
  29.         </script>
  30.     </head>
  31.     <body>
  32.         <input type="text" id="txtBox" onchange="convertTxtBox(this);"/>
  33.     </body>
  34. </html>
  35.  
Jul 15 '12 #2
lyodmichael
75 64KB
thank for help ...........
Jul 16 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sorisio, Chris | last post by:
Ladies and gentlemen, I've imported some data from a MySQL database into a Python dictionary. I'm attempting to tidy up the date fields, but I'm receiving a 'mx.DateTime.Error: cannot convert...
2
by: respect | last post by:
i want to convert real float number to 32-bit IEEE binary format in C++ ? plz help me in finding the codes as fast as u can ] Example for input -6.5, the output should be. 1 10000001...
1
by: yegeswari | last post by:
Hi, How to validate given textbox value is number only. Suppose given text value is other than number mean it should give an alert message. Thanks and regards, Yegeswari
1
by: programmerboy | last post by:
Hi, how do I convert floating point number to a date in ASP? Thanks
7
by: avanthika | last post by:
hi, I am using dropdownlist in webgrid.for loading the combo i am using this source code. Dim vallist As New Infragistics.WebUI.UltraWebGrid.ValueList Dim ds As New DataSet ...
0
by: santoshsri | last post by:
Hello, I have written a Console application in C#, it basically imports data from tab delimited text files and save in SQl Server database. I am converting currency format of Mortgage value into...
1
by: gdavid | last post by:
Hi. I Have started using Visual C++ 2008 a month ago. I Tried to make a GUI calculator but i cannot convert the textbox's text with the atof() function. The function cannot convert String^ type into...
3
by: salzan | last post by:
is there anyway to programatically in VBA code convert a textbox to a combobox (set it's control source) and then later convert it back to a text box? Much appreciated. Salzan
2
by: karanbikash | last post by:
hi , I have a column with datatype as decimal(31,2) . The data is like 123456.67 , 7634578.99 Is it a way to convert the entire number into character . like '1232456.67' . The output...
7
by: Udara chathuranga | last post by:
How can I convert binary float number into a decimal float number ?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.