Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Beginner help, script to edit text

    Hi all,

    I am new to this forum, and a novice at javascripting, I wanted to ask if one of you all could help me create a simple script for me.

    I need a text box where I can paste a copy like this:

    Uncommon Trophy of Rage +0 Faction: druid Quality: Uncommon Type: trophy Level: 0 Might: 320 -2.00% Attack Debuff 15.00% Horsed Load 12.00% Troop Training Speed 24.00% Troop Training Speed 15.00% Attack

    A second text box below that then changes the pasted text into this:

    Uncommon Trophy of Rage +0 Faction: druid Quality: Uncommon Type: trophy Level: 0 Might: 320 / -2.00% Attack Debuff / 15.00% Horsed Load / 12.00% Troop Training Speed / 24.00% Troop Training Speed / 15.00% Attack

    Basically it should just add those 5 forward slashes before each stat on the "item".

    I am thinking something like regex, but I have never used that, so please a novice explanation, or if I can even ask for that, create the script for me.

    Thank you,

    DD

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Code:
    <input type= "text" id = "box1" size = "240" value = "Uncommon Trophy of Rage +0 Faction: druid Quality: Uncommon Type: trophy Level: 0 Might: 320 -2.00% Attack Debuff 15.00% Horsed Load 12.00% Troop Training Speed 24.00% Troop Training Speed 15.00% Attack"; onblur = "addslashes()">
    <br>
    <input type = "text" id = "box2" size = "240">
    
    <script type = "text/javascript">
    function addslashes() {
    var str = document.getElementById("box1").value;
    str = str.replace(/(\-?\d+\.\d+%)/gi, "/ $1");
    document.getElementById("box2").value = str;
    }
    </script>
    "Good judgment comes from experience and experience comes from bad judgment."

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    DarkDove (11-13-2012)

  • #3
    Banned
    Join Date
    Oct 2012
    Posts
    81
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by Philip M View Post
    Code:
    <input type= "text" id = "box1" size = "240" value = "Uncommon Trophy of Rage +0 Faction: druid Quality: Uncommon Type: trophy Level: 0 Might: 320 -2.00% Attack Debuff 15.00% Horsed Load 12.00% Troop Training Speed 24.00% Troop Training Speed 15.00% Attack"; onblur = "addslashes()">
    <br>
    <input type = "text" id = "box2" size = "240">
    
    <script type = "text/javascript">
    function addslashes() {
    var str = document.getElementById("box1").value;
    str = str.replace(/(\-?\d+\.\d+%)/gi, "/ $1");
    document.getElementById("box2").value = str;
    }
    </script>
    Your signature says

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration
    but did you really test your code? I think not.

    It doesn't work in IE9 or FF16 because you have a very obvious syntax error in your code
    Last edited by minder; 11-11-2012 at 06:23 AM.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by minder View Post
    Your signature says



    but did you really test your code? I think not.

    It doesn't work in IE10 or FF16 because you have a very obvious syntax error in your code
    Really? It works just fine for me in IE9 and Chrome.

    You tell me the very obvious syntax error! It is not obvious to me.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Banned
    Join Date
    Oct 2012
    Posts
    81
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by Philip M View Post
    Really? It works just fine for me in IE9 and Chrome.

    You tell me the very obvious syntax error! It is not obvious to me.
    Normally I don't spoon feed - lose the semicolon in

    Code:
    Attack"; onblur
    and it'll work in IE9.
    Last edited by minder; 11-11-2012 at 06:24 AM.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by minder View Post
    Normally I don't spoon feed - lose the semicolon in

    Code:
    Attack"; onblur
    and it'll work in IE9.
    As I have said, it works in IE9 and Chrome and that is not a syntax error.

    I have the awful feeling that we are back with bullant and his many doppelgangers.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you Philip, worked like a charm, much appreciated, I owe you a cold one hehe.

    DD

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by DarkDove View Post
    Thank you Philip, worked like a charm, much appreciated, I owe you a cold one hehe.

    DD
    Well, it worked for me and I am happy worked for you, but for some reason it did not work for Minder (aka bullant, webdev1958, Mishu, iBall and other pseuodonyms under which he has been banned from this forum previously). He should continue taking the tablets.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #9
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,292
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Quote Originally Posted by Philip M View Post
    Well, it worked for me and I am happy worked for you, but for some reason it did not work for Minder (aka bullant, webdev1958, Mishu, iBall and other pseuodonyms under which he has been banned from this forum previously). He should continue taking the tablets.
    i haven't noticed Minder around, so let's not shoot the messenger just yet.
    While the disconnected double direct quote is questionable netiquette, you DID have a typo in your posted code, whether it quirked out or not.


    The "good samaritan act" of offering volunteer help relieves any liability stemming from accidents, which are bound to happen.


    it's not impossible or even unlikely that the code was both tested and got messed up during the posting; i know i sometimes rework whitespace and comments in the reply box and have been known to delete or add a semi-colon erroneously before. i think it's both understandable and forgivable.


    zingers can be fun, but you're a landmark here, a coder i look up to.
    imho, you need not resort to ad-hominem backlashes against noobs.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by rnd me View Post
    While the disconnected double direct quote is questionable netiquette, you DID have a typo in your posted code, whether it quirked out or not.

    Might I ask you to kindly indicate exactly what the typo was? Stupidly I have been unable to identify it myself.

    I don't think that Minder (formerly bullant etc.) qualifies for the appellation "noob". A mod intended to ban him (already) but by mistake ticked the wrong box and awarded him an infraction only. Only two more and we will see the end of him (for a while).
    Last edited by Philip M; 11-13-2012 at 11:39 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #11
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,292
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Code:
    <input type= "text" id = "box1" size = "240" value = "Uncommon Trophy of Rage +0 Faction: druid Quality: Uncommon Type: trophy Level: 0 Might: 320 -2.00% Attack Debuff 15.00% Horsed Load 12.00% Troop Training Speed 24.00% Troop Training Speed 15.00% Attack"; onblur = "addslashes()">
    at http://validator.w3.org/#validate_by_input says :
    Line 1, Column 258: character ";" not allowed in attribute specification list
    …ning Speed 24.00% Troop Training Speed 15.00% Attack"; onblur = "addslashes()">
    i was giving you the benefit of the doubt that it was a typo.
    if you did it on purpose, well, that's a different problem for another forum.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #12
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    The ; is redundant, I accept, and it was indeed a typo. But it does not affect the working of the script, which I tested before posting.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    LinkBacks (?)

    1. 02-24-2014, 04:33 PM

    Posting Permissions

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