dcsimg
www.webdeveloper.com
Results 1 to 12 of 12

Thread: Allowing Special Characters

  1. #1
    Join Date
    May 2003
    Posts
    9

    Allowing Special Characters

    First Time User!

    I have a web application that allows a user to update data in input boxes. Some of these fields are currency fields, which the user may enter a comma ($30,000). I get an error in IE stating "Error converting data type varchar to numeric".

    How can I allow special characters when updating a text field?

    Thanks

  2. #2
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Please post the part of the script you're having trouble with; otherwise, we can only guess what you've got.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  3. #3
    Join Date
    May 2003
    Posts
    9

    Allowing Special Characters

    <input type="text" name="Cost" size="18" maxlength="80" value = #Cost#>

    UPDATE CostData
    SET Cost = '#Cost#'
    WHERE ID = '#ID#'

    The Cost variable is set up as a decimal.

    Is there a JavaScript function that will allow a comma?

  4. #4
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    That's the serverside part. I need to see your JavaScript.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  5. #5
    Join Date
    May 2003
    Posts
    9
    I realize that. The code doesn't contain JavaScript. I am wondering if that is what I need to solve this problem?

    Apologies for the confusion!

  6. #6
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    I see. So you want to just put a comma every 3 characters?

    <script>
    var set = setInterval("setCommas()", 4000);

    function setCommas(){
    var box = document.formName.Cost.value;
    var end = box.indexOf(".");
    box=box.substring(1, end);
    alert(box);
    clearInterval(set);
    }
    </script>

    This will alert the number every 4 seconds without the $ sign or the decimal... It's a start, but I, unfortunately, don't have the time to finish working on it... Sorry
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  7. #7
    Join Date
    May 2003
    Posts
    9
    I appreciate your help! Thanks!

  8. #8
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="Content-Script-Type" content="text/javascript">
    <title>Example</title>
    <form action="">
    <div>
    <input type="text" onchange="this.value = Number(this.value.replace(/[$,]/g, ''))">
    </div>
    </form>


    Just keep in mid that this will not work for the one in ten users who do not have JavaScript, so you'll need to do something similar on the server side.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  9. #9
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Hit me in the head. I forgot all about that, Charles! LOL... Sorry, Jules.

    BTW, Charles, what does Undermensch mean?
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  10. #10
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    We can make that a little better by adding a touch of class. Put the following in the document's head.

    <script type="text/javascript">
    <!--
    String.prototype.reverse = function () {return this.split('').reverse().join('')};

    function Dollars (d) {if (isNaN(d)) {this.num = Number(d.replace(/[$,]/g, ''))} else {this.num = d}};

    Dollars.prototype.valueOf = function () {return this.num};

    Dollars.prototype.toString = function () {
    var s = this.num < 0 ? '-' : '';
    var l = Math.floor(Math.abs(this.num)).toString();
    var r = Math.round((Math.abs(this.num) % 1) * 100).toString();
    if (l.length > 4) l = l.reverse().match(/\d{1,3}/g).join(',').reverse();
    if (r < 10) r = '0' + r;
    return '$' + s + [l,r].join('.');
    }
    // -->
    </script>


    Then you can create Dollars objects that will behave like numbers when you use them like numbers but will look like US Currency when you use them like strings.

    <input type="text" onchange="this.value = new Dollars(this.value)">

    <input type="text" onchange="this.value = new Dollars(new Dollars(this.value) * 10)">
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  11. #11
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    Originally posted by Jona
    Hit me in the head. I forgot all about that, Charles! LOL... Sorry, Jules.

    BTW, Charles, what does Undermensch mean?
    Nitezsche wrote of the &Uuml;bermensch, the over man, man perfected.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  12. #12
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Oh... LOL.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles