jamesxg1 Posted February 5, 2009 Share Posted February 5, 2009 <html> <head> <title>Smiley Replacement</title> <script type="text/javascript"> var ImgArray = [ '|smile.gif', '|mad.gif', '|biggrin.gif' ]; // Images above available on webdeveloper.com forum function ConvertSmileys() { var match = ''; var tarr = new Array(); var str = document.getElementById('TArea').value; for (i=0; i<ImgArray.length; i++) { tarr = ImgArray[i].split('|'); match = new RegExp(tarr[0],"g"); // How to use variable in RegExp ??? str = str.replace(match,tarr[1]); } document.getElementById('DivArea').innerHTML = str; } function SmileyConvert() { var text = document.getElementById('TArea').value; text = text.replace(/\:\)/g, '<img src="smile.gif" border="0">'); text = text.replace(/\:\(/g, '<img src="mad.gif" border="0">'); text = text.replace(/\:\D/g, '<img src="biggrin.gif" border="0">'); text = text.replace("\n", '<br>'); // How to globally replace this character ??? document.getElementById('DivArea').innerHTML = text; } </script> </head> <body> <h1>Smiley Replacements</h1> <textarea id="TArea" rows="5" cols="40"> Hello Are you having a bad day or a great day ? </textarea> <br> <button onclick="ConvertSmileys()">Convert to Smileys : NOGO</button> <button onclick="SmileyConvert()">Convert to Smileys : Good</button> <p> <div id="DivArea" style="border:1px solid blue;height:100px;width:500px"></div> </body> </html> How do i make this global so i dont have to use a textarea ?, basically put the <script> at the top of the page and any smiley prefixes e.g will be converted automatically ? Quote Link to comment Share on other sites More sharing options...
webster08 Posted February 5, 2009 Share Posted February 5, 2009 text = text.replace("\n", '<br>'); // How to globally replace this character ??? do it like so: text = text.replace(/\n/g, "<br>"); Quote Link to comment Share on other sites More sharing options...
jamesxg1 Posted February 5, 2009 Author Share Posted February 5, 2009 didnt work heres the page i need it working in <?php session_start(); require("../db/db.php"); //include database file require("../db/config.php"); //include configuration file require("../db/util.php"); require("../db/settings.php"); isloggedin(); accessneeded("C"); ?> <?php $id = mysql_real_escape_string($_GET['id']); $username = mysql_real_escape_string($_GET['username']); $sql = "SELECT * FROM `users` WHERE `id`='$id' OR `username`='$username' LIMIT 1"; $query = mysql_query($sql); if(mysql_num_rows($query) > 0){ //display content while ($row = mysql_fetch_assoc($query)) { $id = $row['id']; $photo = $row['photo']; $gender = $row['gender']; $email = $row['email']; $firstn = $row['firstname']; $lastn = $row['lastname']; $dobd = $row['dobDay']; $dobm = $row['dobMonth']; $doby = $row['dobYear']; $username = $row['username']; $music = $row['music']; $movies = $row ['movies']; $scaredof = $row['scaredof']; $field1 = $row['field1']; $field2 = $row['field2']; $field3 = $row['field3']; $field4 = $row['field4']; $field5 = $row['field5']; $fieldb1 = $row['fieldb1']; $fieldb2 = $row['fieldb2']; $tagline = $row['tagline']; } }else{ header('Location: ../main/profileerror.php'); } ?> <html> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title><?php print $title ?> - <?php print $firstn ?> <?php print $lastn ?>'s Profile</title> <!-- Insert your commenting javascript code here --> </head> <script type="text/javascript" src="../main/inc/ajax_framework.js"></script> <link rel="stylesheet" type="text/css" href="../main/inc/jqueryslidemenu.css" /> <!--[if lte IE 7]> <style type="text/css"> html .jqueryslidemenu{height: 1%;} /*Holly Hack for IE7 and below*/ </style> <![endif]--> <script type="text/javascript" src="../main/inc/jquery.min.js"></script> <script type="text/javascript" src="../main/inc/jqueryslidemenu.js"></script> <style type="text/css" media="all"> body { margin: 0px; font-family: tahoma, sans-serif; padding-bottom: 20px; background: #FFFFFF; font-size: 12px; color: #333333;} #Granny { width: 900px; font-size: 0.88em; } a { text-decoration: none; color: #0000FF; } a img { border-width: 0px; } #HeaderCont { clear: both; width: 100%; margin-top: 30px; background: #CCC; border: 1px solid #333; } #HeaderInn { margin-bottom: 4px; padding: 5px 0px; text-align: left; font-family: Tahoma, sans-serif, sans-serif; } #HeaderTitle { font-size: 3em; color: #000000; padding: 0px 40px; direction: ltr; text-align: left; } .TitleItemLink { color: #000000; } #MainAndSides { clear: both; width: 100%; margin-top: 15px; } #MainCol { width: 73%; background: #F6F6F6; float: right; } #MainColInner { padding: 10px 20px; border: 1px solid #000000; } .OnePost { border: 1px solid #000000; font-family: Tahoma, sans-serif, sans-serif; direction: ltr; background: #EEE; } .OnePost .TopPost { border-bottom: 1px solid #666; padding: 0px 20px 3px 20px; background: #CCC; } .OnePost .MidPost { padding: 15px 25px; } .OnePost .BotPost { border-top: 1px solid #666; padding: 3px 20px; background: #CCC; } .OnePost .FullWidth { width: 100%; } .DateHeaderPost { font-size: 1em; color: #000000; padding-top: 3px; text-align: right; width: 48%; float: right; } .TitleHeaderPost { font-size: 1em; font-weight: bold; color: #000000; padding-top: 3px; text-align: left; direction: ltr; width: 48%; float: left; } .TitleHeaderPost a { color: #000000; } .PostTextBody { font-size: 1em; color: #000000; text-align: left; line-height: 150%; } .CmntFooterPost { visibility: visible; font-size: 1em; color: #333; width: 48%; float: right; text-align: right; } .CmntFooterPost a { color: #333; } .PermFooterPost { font-size: 1em; font-style: italic; color: #333; width: 48%; float: left; text-align: left; } .PermFooterPost a { color: #333; } .Clearer { clear: both; width: 100%; font-size: 0px; height: 0px; } .PostSep { height: 20px; font-size: 1px } .PostSepS { height: 10px; margin-bottom: 10px; border-bottom: 1px solid #000000; font-size: 1px } .SideBar { background: #999; } .SideBarInner { padding: 15px 15px; border: 1px solid #000000; } .SideBarInner img { margin-top: 2px; } #SideLCol { width: 25%; float: left; margin-right: 1.5%; } #SideLCol .Box { background: #CCC; border: 1px solid #666; font-family: Tahoma, sans-serif, sans-serif; } #SideLCol .Sep { height: 30px; } #SideLCol .SepS { height: 14.5px; margin-bottom: 14.5px; border-bottom: 1px solid #000000; font-size: 1px } #SideLCol .Title { font-size: 1em; color: #000000; font-weight: bold; border-bottom: 1px solid #333; margin-bottom: 3px; } #SideLCol .Inner { text-align: center; font-size: 1em; color: #333; padding: 5px 15px 8px 15px; line-height: 150%; } #commentInline { margin: 10px 20px; text-align: left; } .commentHead { margin: 0px 10px 20px 10px; padding-top: 5px; color: #333; } .comments-block { line-height: 150%; padding: 0px 30px; } .comment-poster { padding-bottom: 10px; } .comment-body { margin: 0px; padding-bottom: 10px; padding-left: 20px; } .innerCmntBody { margin: 5px 0px; } .comment-timestamp { margin: 5px 0px; padding: 0px 0px 8px 20px; color: #999; } .comment-timestamp a { color: #666; } .deleted-comment { font-style: italic; color: gray; } #ColClose { clear: both; width: 100%; font-size: 1px; height: 1px; margin-bottom: 20px; } #CopyRight { width: 60%; border-top: 1px solid gray; padding-top: 10px; line-height: 150%; } /* This template generated by PsycHo [http://psyc.horm.org] on 1/26/2009. */ </style> <div id="myslidemenu" class="jqueryslidemenu"> <!-- CSS --> <link rel="stylesheet" href="../template/lightbox.css" media="screen,projection" type="text/css" /> <!-- JavaScript --> <script type="text/javascript" src="../inc/gen/prototype.js"></script> <script type="text/javascript" src="../inc/gen/lightbox.js"></script> <script type="text/javascript"> var ImgArray = [ '|smile.gif', '|mad.gif', '|biggrin.gif' ]; // Images above available on webdeveloper.com forum function ConvertSmileys() { var match = ''; var tarr = new Array(); var str = document.getElementById('TArea').value; for (i=0; i<ImgArray.length; i++) { tarr = ImgArray[i].split('|'); match = new RegExp(tarr[0],"g"); // How to use variable in RegExp ??? str = str.replace(match,tarr[1]); } document.getElementById('DivArea').innerHTML = str; } function SmileyConvert() { var text = document.getElementById('TArea').value; text = text.replace(/\:\)/g, '<img src="smile.gif" border="0">'); text = text.replace(/\:\(/g, '<img src="mad.gif" border="0">'); text = text.replace(/\:\D/g, '<img src="biggrin.gif" border="0">'); text = text.replace(/\n/g, "<br>"); document.getElementById('DivArea').innerHTML = text; } </script> </head> <ul> <li><a href="../main/index.php">Home</a></li> <li><a href="../messages/inbox.php">Mail <?php $sql = mysql_query ("SELECT pm_count FROM users WHERE username = '{$_SESSION['username']}'"); $row = mysql_fetch_array ($sql); $pm_count = $row['pm_count']; ?>(<?php print "$pm_count" ?>)</a></li> <li><a href="#">Profile</a> <ul> <li><a href="">View Profile</a></li> <li><a href="../main/editprofile.php">Edit Profile</a></li> <li><a href="../main/profilephotoupload.php">Profile Photo</a></li> <li><a href="#">Privacy Settings</a></li> </ul> </li> <li><a href="#">Items</a></li> <li><a href="../friends/friends.php">Friends</a> <ul> <li><a href="#">Friend Requests</a></li> <li><a href="#">Invitation</a> </li> <li><a href="#">Invite Friends</a></li> </ul> </li> <li><a href="../login/logout.php">Sign Out</a></li> <li><?php print ("<img src='../main/images/$photo' width='28' height='30'>"); ?></li> </ul> <br style="clear: left" /> </div> <body><center> <div id="Granny"> <div id="HeaderCont"><div id="HeaderInn"> <div class="Clearer"></div> <div id="HeaderTitle"> <center><?php print $tagline ?><center> </div> <div class="Clearer"></div> </div></div> <div id="MainAndSides"> <!-- ==================== Main Column ==================== --> <div id="MainCol"> <div id="MainColInner"> <Blogger> <div class="OnePost"> <a name=""></a> <div class="TopPost"><div class="FullWidth"> <div class="DateHeaderPost"> </div> <div class="TitleHeaderPost"> Information: </div> <div class="Clearer"></div> </div></div> <div class="MidPost"><div class="FullWidth"> <div class="PostTextBody"> <?php print("<P ALIGN=CENTER><strong>$field1</strong><br>$music<br><strong>$field2</strong><br>$movies<br><strong>$field3</strong><br>$scaredof<br><strong>$field4</strong><br>$fieldb1<br><strong>$field5</strong><br>$fieldb2</p>"); ?> </div> </div></div> <div class="BotPost"><div class="FullWidth"> <div class="PermFooterPost"> <strong>Profile Comments:</strong> </div> <div class="CmntFooterPost"> <!-- Insert your external commenting service scripts here and remove the line below --> </div> <div class="Clearer"></div> </div></div> </div> <ItemPage> <div id="commentInline"> <div class="commentHead"></div> </span> <div id="insert_response" align=center></div> <P ALIGN=CENTER> <form action="javascript:insert()" method="post"> <input type="hidden" name="comto" value="<? echo $username ?>" id="comto"> <input type="hidden" name="comfrom" value="<? echo($_SESSION['username']); ?>" id="$comfrom"> Comment: <br><textarea name="commen" cols="45" rows="5" wrap="VIRTUAL" id="$commen"></textarea> <br> <input type="submit" name="submit" value="Send"> </form></P> <?php $sql = "SELECT * FROM `comments` WHERE comto = '$username'"; $query = mysql_query($sql); while ($row = mysql_fetch_assoc($query)) { $from = $row['comfrom']; $message = $row['commen']; $too = $row['comto']; $comid = $row['id']; echo "<br/>\n"; print("<P ALIGN=CENTER><strong>$from</strong><br>$message</P>"); if($_SESSION['username'] == $too) { print("<br><P ALIGN=RIGHT><a href='../main/DeleteComment.php?id=$comid'>Delete Comment</a></P>"); } } ?> <br> </div> </ItemPage> <div class="PostSep"><div class="PostSepS"></div></div> </div> </div> <!-- =================== Side L Column =================== --> <div id="SideLCol" class="SideBar"> <div class="SideBarInner"> <div class="Box"> <div class="Inner"> <div class="Title">Profile Image</div> <?php print ("<img src='../main/images/$photo' width='150'>"); ?> <br /> </div> <a href='../main/editprofile.php'>Edit Profile</a> | <a href='../main/profilephotoupload.php'>Profile Photo</a> </div> <div class="Clearer"></div> </div> <div class="Clearer"></div> <div class="Clearer"></div> <div class="SideBarInner"> <div class="Box"> <div class="Inner"> <div class="Title">Contact <?php print $firstn ?></div> <a href="../messages/compose.php?username=<?php print $username ?>" class="lbOn">Send Message</a> || <a href="../friends/add.php">Add As Firend</a><br> <a href="../main/blockfriend.php">Block User</a> || <a href="../main/reportusr.php">Report User</a> <br /> </div> </div> </div> </div> </div> <div id="ColClose"></div> <div id="CopyRight"> <br /> <br /> </div> </div> </center></body> </html> Quote Link to comment Share on other sites More sharing options...
webster08 Posted February 5, 2009 Share Posted February 5, 2009 not sure why it did not work; the "g" represent a global search - so it should work fine. there maybe a issue with the rest of your code; i haven't looked that closely at it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.