/    Sign up×
Community /Pin to ProfileBookmark

need to replace code in string

Hi

I have a javascript:
<script language=”JavaScript”>
<!–

mycount=0;

function saySomething(){

mycount++;

myinput=document.forms[‘phpval’][‘ui’].value;

document.forms[‘phpval’][‘ui’].value=”;

document.all(‘ChatPane’).innerHTML += ‘<span id=”a’ + mycount + ‘”><font face=”Verdana, Arial, Helvetica, sans-serif” size=”1″><b><font color=”#006600″>Jij:&nbsp</font></b><font color=”#006600″>’ + myinput + ‘</font></font><BR></span>’;
document.all(‘a’ + mycount).scrollIntoView(true);

jsrsExecute(“../jsrs.php”, myCallback, “replyjs”, Array(myinput));

}

function myCallback( returnstring ){

mycount++;

document.all(‘ChatPane’).innerHTML += ‘<span id=”a’ + mycount + ‘”><font face=”Verdana, Arial, Helvetica, sans-serif” size=”1″><b><font color=”#003366″>Marieke:&nbsp</font></b><font color=”#003366″>’ + returnstring + ‘</font></font><BR></span>’;
document.all(‘a’ + mycount).scrollIntoView(true);

}

// –>

Yes it uses JSRS.
So from an input box a user types his or her message.
Hits “talk” and what was said is placed in the chatpane with the code + myinput +
The contents of myinput is also send to a another page (php) but that is besides the point.

the idea i have is to have “myinput” tested as a string that contains more than one word and or smiley code….
let’s say i have as input: ” Hi i feel 😉 “
the smiley code should be replaced with an image.

Problem is to catch myinput and make it analysed…

Something like:
var ScrnSize = “myinput”;
switch(ScrnSize) {
case “:-)”: document.write(‘<img border=”0″ src=”images_emo/angel.gif”>’);
}

Is useless for the myinput is taken as a whole…

Any one an example?

Thanks!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@scragarDec 13.2004 — in PHP you could add:

$ScrnSize = "myinput";

$ScrnSize = str_replace(":-)","<img src='Smiley1.gif'>",$ScrnSize);

$ScrnSize = str_replace("?","<img src='Smiley1.gif'>",$ScrnSize);

$ScrnSize = str_replace(";-)","<img src='Smiley2.gif'>",$ScrnSize);

$ScrnSize = str_replace(":-(","<img src='Smiley3.gif'>",$ScrnSize);

$ScrnSize = str_replace(":-]","<img src='Smiley4.gif'>",$ScrnSize);


or if your using javascript:

var ScrnSize = "myinput";

ScrnSize = ScrnSize.replace(":-)","<img src='Smiley1.gif'>");

ScrnSize = ScrnSize.replace("?","<img src='Smiley1.gif'>");

ScrnSize = ScrnSize.replace(";-)","<img src='Smiley2.gif'>");

ScrnSize = ScrnSize.replace(":-(","<img src='Smiley4.gif'>");

ScrnSize = ScrnSize.replace(":-]","<img src='Smiley5.gif'>");

Edit: Smilies disabled.
×

Success!

Help @nathanwheeler 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.19,
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,
)...