/    Sign up×
Community /Pin to ProfileBookmark

Even more Ascii image problems!!

hi everyone,
i am trying to create a page that displays an Ascii image and allows the user to choose what character they would like changed and what they would like it change to. Here is the code so far:

<?xml version=”1.0″ encoding=”iso-8859-1″?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<title>Javascript</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<link href=”Style.css” rel=”stylesheet” type=”text/css” />
<script language=”JavaScript” type=”text/javascript”>

pic = new Array();

function WritePic()
{
var numCol = 8;

pic = [“i”, ““, “/”, ““, “/”, ““, “i”, ” “, “|”, ” “, ” “, ” “, ” “, ” “, “|”, ” “, “|”, ” “, ” “, ” “, ” “, ” “, “|”, ” “, “|”, ” “, “(“, “0”, “)”, “(“, “0”, “)”, “C”, ” “, ” “, ” “, ” “, ” “, “_“, “)”, “|”, ” “, ” “, “‘”, “_“, “_“, “_“, “|”, “|”, ” “, ” “, ” “, ” “, ” “, “/”, ” “, “|”, ” “, ” “, ” “, “/”, ” “, ” “, ” “]

document.write(“<div style=’font-family:monospace’ id=’image’><pre>”);
for(row = 0; row < 8; row++) {
for(col = 0; col < 8; col++) {
document.write(pic[numCol*row+col]);
}
document.write(“<br/>”);
}
document.write(“</pre></div>”);
}

function ChangePic(oldChar,newChar){
var image = document.getElementById(‘image’);
if(image.innerHTML.match(oldChar,’g’)){
image.innerHTML = image.innerHTML.replace(new RegExp(oldChar,’g’),newChar);
} else{alert(‘The character you picked is not present… Please pick again!’)}
}

</script>
</head>
<body>
<form name=”frmPic” id=”frmPic” action = “”>
<script language=”JavaScript” type=”text/javascript”>
WritePic()
</script>
<p>Please insert a character that you would like changed: <br />
<input name=”oldChar” type=”text” id=”txtChangeChar” maxlength=”1″ />
<br />
Please insert the character you would like it changed to:<br />
<input name=”newChar” type=”text” id=”txtNewChar” maxlength=”1″ />
</p>
<p>
<input name=”btnChange” type=”button” id=”btnChange” value=”Change”
onclick=”ChangePic(this.form.oldChar.value,this.form.newChar.value)” />
</p>
<p> </p>
</form>
<p align=”center”><font size=”2″ face=”Arial, Helvetica, sans-serif”><a href=”index.htm”>Back
to main page</a></font></p>
</body>
</html>

this works for some characters but not for |, or )
Can anyone help because im out of ideas!
cheers Shaun

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ExuroOct 17.2004 — The problem lied within the characters not being escaped within the regular expression... This version of the function should work:
[code=php]function ChangePic(oldChar,newChar){
var image = document.getElementById('image');
if (/[\()$^|]/.test(oldChar)) {
oldChar = "\"+oldChar;
}
if(image.innerHTML.match(oldChar,'g')) {
image.innerHTML = image.innerHTML.replace(new RegExp(oldChar,'g'),newChar);
}
else {
alert('The character you picked is not present... Please pick again!')
}
}[/code]
×

Success!

Help @prawn_86 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...