SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display contents of a field without symbol

    Hey,

    I am trying to prevent showing a symbol when a user clicks on an edit button.

    I do this like so:

    Code:
    var form = document.forms[1];
    var data = document.getElementsByTagName("td");
    var fixOrPerc = data["Sales-" + intID].innerHTML;
    
    form.SalesFixed.value = fixOrPerc.substring(1, fixOrPerc.length - 1);
    This does work correctly when i have a value like so:

    10.00
    But the problem is that i allow negative numbers like so

    -10.00
    When negative numbers are entered and the edit button is clicked on then it removed the minus sign but keeps the symbol..

    How can i fix this?

    Hope someone can help..

    Many thanks,
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Would you not be better to replace() the character?
    Code:
    form.SalesFixed.value = fixOrPerc.replace("", "");
    (not tested!)
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Spike,

    Hope your well, been a long time

    Ok, i did try what you suggested as it would seem to be the easiest way to do it, a simple replace i thought would do the trick.

    But that didn't seem to work it still populated the input element with the symbol so i tried a length - 1 which only worked for positive numbers.

    I might as well show you the full example. I have 2 fields Sales and Fixed like so:

    Code:
    <input Name="SalesPercent" maxlength="6"> - 
    <input Name="SalesFixed" maxlength="6">
    Above this there is a form selecting all of the fields from a table, each having an Edit button. When the edit button is clicked it fires the following function:

    Code:
        	    function Edit(intID) {
        	        var form = document.forms[1];
        	        var data = document.getElementsByTagName("td");
        	        var valSalesFixed = "";
    
        	        var fixOrPerc = data["Sales-" + intID].innerHTML;
    
        	        if (data["Sales-" + intID].innerHTML.indexOf("%") >= 0) {
        	            form.SalesPercent.value = data["Sales-" + intID].innerHTML.replace("%", "");
        	        } else {
        	            form.SalesFixed.value = fixOrPerc.substring(1, fixOrPerc.length - 1);
        	        }
    
        	    }
    Now i have just tried putting in your code but that doesn't work either
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy

  4. #4
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way, the % is comparing one field which is the first part of the IF, then the ELSE takes into account the field..
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by billy_111 View Post
    Hey Spike,

    Hope your well, been a long time
    Full of a Spring cold at the minute but struggling on!

    It might not recognise the symbol so maybe try the ASCII codes &#163; or &pound;
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

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