CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Beginner help, script to edit text (http://www.codingforums.com/showthread.php?t=281794)

DarkDove 11-10-2012 10:00 AM

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

Philip M 11-10-2012 12:16 PM

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."

minder 11-10-2012 08:30 PM

Quote:

Originally Posted by Philip M (Post 1290692)
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? :rolleyes: I think not.

It doesn't work in IE9 or FF16 because you have a very obvious syntax error in your code ;)

Philip M 11-10-2012 08:58 PM

Quote:

Originally Posted by minder (Post 1290770)
Your signature says



but did you really test your code? :rolleyes: 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. :cool:

minder 11-10-2012 09:22 PM

Quote:

Originally Posted by Philip M (Post 1290778)
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. :cool:

Normally I don't spoon feed :D - lose the semicolon in

Code:

Attack"; onblur
and it'll work in IE9.

Philip M 11-11-2012 09:34 AM

Quote:

Originally Posted by minder (Post 1290787)
Normally I don't spoon feed :D - 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. :mad:

DarkDove 11-13-2012 09:11 AM

Thank you Philip, worked like a charm, much appreciated, I owe you a cold one hehe.

DD

Philip M 11-13-2012 09:33 AM

Quote:

Originally Posted by DarkDove (Post 1291510)
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. :D

rnd me 11-13-2012 10:08 AM

Quote:

Originally Posted by Philip M (Post 1291512)
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. :D

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.

Philip M 11-13-2012 11:36 AM

Quote:

Originally Posted by rnd me (Post 1291518)
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).

rnd me 11-13-2012 12:50 PM

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.

Philip M 11-13-2012 01:11 PM

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 times are GMT +1. The time now is 03:47 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.