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 8108739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:12:19+00:00 2026-06-06T01:12:19+00:00

I tried to make my textbox type in currency format. I did it, but

  • 0

I tried to make my textbox type in currency format. I did it, but when I insert the value it into my database the value changes. When I type 10000, it changes 10,000. (So far so good.) But when I insert that value into database the value changes to 10. I’m really confused.

Here is my script. I used php, mysql, and the field type is float

    <?php include('header.php'); ?>
<?php
    if(isset($_POST['simpan']))
    {
        $nama           = htmlentities(addslashes($_POST['nama']));
        $sim_wajib      = $_POST['sim_wajib'];
        $sim_pokok      = $_POST['sim_pokok'];
        $sim_sukarela   = $_POST['sim_sukarela'];
        $sim_wpinjam    = $_POST['sim_wpinjam'];
        $shu            = $_POST['shu'];
        $total          = $sim_wpinjam + $shu;

        if($nama != '' && $sim_wajib != '' && $sim_pokok != '' && $sim_sukarela != '' && $sim_wpinjam != '' && $shu != '' )
        {
            $sql     = "INSERT INTO simpanan_tbl";
            $sql    .= "(nama, sim_wajib, sim_pokok, sim_sukarela, sim_wajibpinjam, shu, jumlah)";
            $sql    .= "VALUES('$nama','$sim_wajib','$sim_pokok','$sim_sukarela','$sim_wpinjam','$shu','$total')";
            $query   = mysql_query($sql) or die(mysql_error());
            echo '<script type="text/javascript">alert("Data telah masuk!");document.location="manage_simpanan.php";</script>';
        }
        else
        {
            echo '<script type="text/javascript">alert("Kolom tidak boleh ada yang kosong!");</script>';
        }
    }
?>
<div id="rounded_add">
    <script type="text/javascript">
        function numberFormat(nr)
        {
            //remove the existing
            var regex = /,/g;
            nr        = nr.replace(regex,'');

            //split it into 2 parts
            var x   = nr.split(',');
            var p1  = x[0];
            var p2  = x.length > 1 ? ',' + x[1] : '';
            //match group of 3 numbers (0-9) and add ',' between them
            regex   = /(\d+)(\d{3})/;
            while(regex.test(p1))
            {
                p1 = p1.replace(regex, '$1' + ',' + '$2');
            }
            //join the 2 parts and return the formatted number
            return p1 + p2;
        }
    </script>
    <form method="post" name="form1">
        <table id="add_simpan" class="add">
            <tr>
                <td>No Anggota</td>
            </tr>
            <tr>
                <td><input type="text" id="" name="" class="textbox"></td>
            </tr>
            <tr>
                <td>Nama</td>
            </tr>
            <tr>
                <td><input type="text" id="nama" name="nama" class="textbox_left"></td>
            </tr>
            <tr>
                <td>Simpanan Wajib</td>
            </tr>
            <tr>
                <td><input type="text" id="sim_wajib" name="sim_wajib" class="textbox"></td>
            </tr>
            <tr>
                <td>Simpanan Pokok</td>
            </tr>
            <tr>
                <td><input type="text" id="sim_pokok" name="sim_pokok" class="textbox"></td>
            </tr>
            <tr>
                <td>Simpanan Suka Rela</td>
            </tr>
            <tr>
                <td><input type="text" id="sim_sukarela" name="sim_sukarela" class="textbox"></td>
            </tr>
            <tr>
                <td>Simpanan Wajib Pinjam</td>
            </tr>
            <tr>
                <td><input type="text" id="sim_wpinjam" name="sim_wpinjam" class="textbox" onkeyup="this.value = numberFormat(this.value);"></td>
            </tr>
            <tr>
                <td>SHU</td>
            </tr>
            <tr>
                <td><input type="text" id="shu" name="shu" class="textbox" onkeyup="this.value = numberFormat(this.value);"></td>
            </tr>
            <tr>
                <td><input type="submit" value="Simpan" id="simpan" name="simpan" class="button blues"></td>
            </tr>
        </table>
    </form>
</div><!-- END OF ROUNDED_ADD -->
<?php include('footer.php'); ?>
  • 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-06T01:12:21+00:00Added an answer on June 6, 2026 at 1:12 am

    If you have to have accounting style formatting within your text boxes, I would suggest having a hidden field with the raw numeric value alongside each textbox. You could easily add a few lines to the js function right after the “nr = nr.replace(regex,”);” section to copy the now stripped value to the hidden field. To do this, you would have to name each textbox and pass the name to the numberFormat function so that it saves it to the correct hidden input. Then, when the form is submitted, save the values from the hidden fields, not the open textboxes.

    Alternately, have your Submit button trigger a function to sweep through all your text fields and remove any formatting, then submit the form as part of the function.

    By the way, inserting 10,000 as ten thousand into a float field will trim it to 10. Unless you are using a comma as a decimal point (which I think the French do?) you are saving incorrect data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to make empty textbox checking for android. i tried try catch but
I tried to make a click counter in MySQL, but it dose not seem
I tried to make a new bare git repository but I get this error:
I tried to make admin panel and I am using sessions , but have
I tried using make defconfig to compile the kernel, but as expected, it failed
We tried several ways to make a textbox to accept the enter, newline, etc..
Tried to make a little old school ajax (iframe-javascript) script. A bit of mootools
I tried to make an alert popup with A with: var a = \u0041;
I tried to make a layout look like it It looks like kinda button
I tried to make an asynchronous UDP client using boost::asio I get some code

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.