Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-10-2012, 10:00 AM   PM User | #1
DarkDove
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
DarkDove is an unknown quantity at this point
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
DarkDove is offline   Reply With Quote
Old 11-10-2012, 12:16 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
DarkDove (11-13-2012)
Old 11-10-2012, 08:30 PM   PM User | #3
minder
Banned

 
Join Date: Oct 2012
Posts: 81
Thanks: 0
Thanked 4 Times in 4 Posts
minder can only hope to improve
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

Quote:
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..
minder is offline   Reply With Quote
Old 11-10-2012, 08:58 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 11-10-2012, 09:22 PM   PM User | #5
minder
Banned

 
Join Date: Oct 2012
Posts: 81
Thanks: 0
Thanked 4 Times in 4 Posts
minder can only hope to improve
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..
minder is offline   Reply With Quote
Old 11-11-2012, 09:34 AM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 11-13-2012, 09:11 AM   PM User | #7
DarkDove
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
DarkDove is an unknown quantity at this point
Thank you Philip, worked like a charm, much appreciated, I owe you a cold one hehe.

DD
DarkDove is offline   Reply With Quote
Old 11-13-2012, 09:33 AM   PM User | #8
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 11-13-2012, 10:08 AM   PM User | #9
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,453
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 11-13-2012, 11:36 AM   PM User | #10
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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).
__________________

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.

Last edited by Philip M; 11-13-2012 at 11:39 AM..
Philip M is offline   Reply With Quote
Old 11-13-2012, 12:50 PM   PM User | #11
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,453
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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 :
Quote:
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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 11-13-2012, 01:11 PM   PM User | #12
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:58 PM.


Advertisement
Log in to turn off these ads.