Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9084505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:00:57+00:00 2026-06-16T21:00:57+00:00

i have made a small app using javascript and html. But recently i encountered

  • 0

i have made a small app using javascript and html.

But recently i encountered a problem with my script.

Problem : Input text box are not allowing me to enter (.)dot/periods i.e decimal values. Example: if i enter a decimal value then it is automatically deleting from my input text box.

What could be reason for this.

I am trying to solve this issue from last 3hrs. But could not found the exact problem. Please check my code and help me to solve this problem.

Relevent code:

<table border="0">
    <form name="form_A" onsubmit="return false">
        <tr>
            <td>
                <select name="unit_menu" class="Items" onchange="CalculateUnit(this.form, document.form_B)">
                    <option>
                    ------- Select a Property -------
                                                                    <option>
                    <option>
                    <option>
                    <option>
                    <option>
                </select>

            </td>
            <td>
                <input type="text" id="info" name="unit_input" placeholder="Type to convert" class="textbox" onfocus="CalculateUnit(this.form, document.form_B)" onkeyup="CalculateUnit(this.form, document.form_B)"></td>

        </tr>
    </form>
    <form name="form_B" onsubmit="return false">
        <tr>

            <td>
                <select name="unit_menu" class="Items" onchange="valuefocus()">
                    <option>
                    ------- Select a Property -------
                    <option>
                    <option>
                    <option>
                    <option>
                    <option>
                </select></td>
            <td>
                <input type="text" name="unit_input" size="20" maxlength="20" placeholder="Type to convert" class="textbox" onfocus="CalculateUnit(this.form, document.form_A)" onkeyup="CalculateUnit(this.form, document.form_A)"></td>
            <td></td>
        </tr>
    </form>
</table>

Javascript

         function CalculateUnit(sourceForm, targetForm){
            // A simple wrapper function to validate input before making the conversion
            var sourceValue = sourceForm.unit_input.value;

            // First check if the user has given numbers or anything that can be made to
            // one...
            sourceValue = parseFloat(sourceValue);
            if ( !isNaN(sourceValue) || sourceValue == 0){
                // If we can make a valid floating-point number, put it in the
                // text box and convert!
                sourceForm.unit_input.value = sourceValue;
                ConvertFromTo(sourceForm, targetForm);
            } else {
                 //wrong input
            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:00:58+00:00Added an answer on June 16, 2026 at 9:00 pm

    Your problem is that your conversion function is triggered on keyup, so if the users types 3. it is converted to 3 and put back into the field.

    parseFloat(3.) = 3

    There are several ways to solve this issue.

    The simplest would be to not calculate the value on keyup but when the user hits enter or the field loses focus (blur).

    Other option would be to check the string value of the field if it ends with a . before you parse it and leave it unchanged as long it isn`t a valid number.

    Example:

    function CalculateUnit(sourceForm, targetForm){
    
        // A simple wrapper function to validate input before making the conversion
        var sourceValue = sourceForm.unit_input.value;
    
        // First check if the user has given numbers or anything that can be made to
        // one...
        if (!/\.$/.test(sourceValue)) {
            sourceValue = parseFloat(sourceValue);
            if ( !isNaN(sourceValue) || sourceValue == 0){
                // If we can make a valid floating-point number, put it in the
                // text box and convert!
                sourceForm.unit_input.value = sourceValue;
                ConvertFromTo(sourceForm, targetForm);
            } else {
                 //wrong input
            }
        } else {
            // sourceValue ends with a '.'
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made an update on Google App Engine with a small fix and
Problem: Have made a small mail program which works perfectly on my developer pc
i have made a small opengl program using the d programming language. what i
I have made an app in which i am using Two Tabs , First
I have created a small app in C using WinAPI and I have a
I've made a small app where Form is threaded (using BackgroundWorker ), and in
I have made a small swing application for my personal use. This app connects
I have a small problem but couldn't find solution for that. I have founded
I've made a small web app using web.py that I now want to put
I'm making a webcam app that sends and receives small images. I have made

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.