HTML Entities
Anybody know any scripts or ways to search all characters like " /\().!@#$%^&*" and replace them with their entity? everytime i try something like str.match("(") or .match ("/50") or so on i get object expected errors saying it needs a ) any ideas?
Put a \ in front of each of those characters if you want it to represent the character rather than hhave its special meaning.
Stephen
I have tried that and i still get ) object expected error can you provide me an example for searching a string for all "(" symbols in it and replacing it with something else
Code:
someString.replace(/\&/g, "&"); // the ampersand should be converted first
someString.replace(/\!/g, "!")
someString.replace(/\(/g, "(");
etc.
EDIT: Ug. The forum is being a pain. The last exclamation mark and parenthese are supposed to be character entities.
Last edited by Jeff Mott; 07-01-2007 at 08:43 PM .
for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
{for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";
It is still not working it seems to weork fine for regular characters but i still get an error saying Expected ')' in regular expression
Can we see what you have?
for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
{for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";
for example paste "hello world(how are you" and then highlight it and select one of the images and you will see the error im getting
Code:
<html>
<head>
<title>Formatter</title>
<script language="JavaScript">
function TrackCount(fieldObj,countFieldName,maxChars)
{
var countField = eval("fieldObj.form."+countFieldName);
var diff = maxChars - fieldObj.value.length;
// Need to check & enforce limit here also in case user pastes data
if (diff < 0)
{
fieldObj.value = fieldObj.value.substring(0,maxChars);
diff = maxChars - fieldObj.value.length;
}
countField.value = diff;
}
function LimitText(fieldObj,maxChars)
{
var result = true;
if (fieldObj.value.length >= maxChars)
result = false;
if (window.event)
window.event.returnValue = result;
return result;
}
</script>
</head>
<body>
<form name="entryForm" action="" method="POST">
<input type="hidden" name="action" value="flash_new">
<table border="0">
<tr>
<td colspan=2 bgcolor=eeeaeb><b>Add a new Flash Article</b></td>
</tr>
<tr>
<tr>
<td>Title:</td>
<td><input type="text" maxlength=100 name="Flash_title"
value="" onkeyup="PreviewWindow()"><font color=999999 size=-1> (Think of this as your subject line)</font></td>
</tr>
<tr style='display:none;'>
<td>Author:</b></td>
<td><input type="text" maxlength=20 name="Flash_author" disabled=true
value=""></td>
</tr>
<tr>
<td>Affected:</b></td>
<td><select name="Flash_markets" value="" onchange="PreviewWindow()">
<Option selected>
<option value="Global">GLOBAL
</select>
</td>
</tr>
<tr>
<td>Potential/Confirmed:</b></td>
<td><input type=radio name="Flash_potconfirm" value="Potential" checked="yes">Potential Issue <input type=radio name="Flash_potconfirm" value="Confirmed">Confirmed Issue
</select>
</td>
</tr>
<tr>
<td>Description:</b></td>
<td><textarea onkeypress="LimitText(this,4000);PreviewWindow()" onkeyup="TrackCount(this,'textcount',4000);PreviewWindow()" rows=4 cols=60 name="Flash_descrip"
value=""></textarea>
<img src='red.bmp' onclick='ChColor("red","","","")' title='Highligt Text and then select a color' style='cursor:pointer'>
<img src='yellow.bmp' onclick='ChColor("yellow","","","")' title='Highligt Text and then select a color' style='cursor:pointer'>
<img src='blue.bmp' onclick='ChColor("#66CCFF","","","")' title='Highligt Text and then select a color' style='cursor:pointer'>
<img src='purple.bmp' onclick='ChColor("purple","","I","U")' title='Highligt Text and then select a color' style='cursor:pointer'>
<img src='magenta.bmp' onclick='ChColor("magenta","B","","U")' title='Highligt Text and then select a color' style='cursor:pointer'>
<img src='orange.bmp' onclick='ChColor("orange","B","I","U")' title='Highligt Text and then select a color' style='cursor:pointer'>
<img src='orange.bmp' onclick='ChColor("orange","B","I","")' title='Highligt Text and then select a color' style='cursor:pointer'>
<img src='orange.bmp' onclick='ChColor("orange","B","","")' title='Highligt Text and then select a color' style='cursor:pointer'>
<font size="2"><i><br>Characters remaining: </i></font>
<input value="4000" size="3" name="textcount" type="text" disabled=true><font color=999999 size=-1> (This is the main body of the issue)</font></td>
</tr>
<tr>
<td>Instructions:</b></td>
<td><textarea onkeypress="LimitText(this,4000);PreviewWindow()" onkeyup="TrackCount(this,'textcount2',4000);PreviewWindow()" rows=4 cols=60 name="Flash_instr"
></textarea><font size="2"><i><br>Characters remaining: </i></font>
<input value="4000" size="3" name="textcount2" type="text" disabled=true><font color=999999 size=-1> (This is where you ask for examples (via comments), state requirements for s, etc.)</font></td>
</tr>
<tr style='display:none;'>
<td>Date/Time:</b></td>
<td><input type="text" maxlength=20 name="Flash_date" disabled=true
value=""></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Submit"> <input type="button" value="preview" onclick='PreviewWindow()'></td>
</tr>
</table>
</form>
<script>
function ChColor(color,stylB,stylI,stylU) {
var selectedHtml=(document.selection.createRange()).htmlText;
var desp=document.entryForm.Flash_descrip;
var inst=document.entryForm.Flash_instr;
if (selectedHtml == '') {
return;
}
else if (desp.value.match(selectedHtml)) {
var eme = desp.value;
var disp = desp;
}
else if (inst.value.match(selectedHtml)) {
var eme = inst.value;
var disp = inst;
}
if (eme == undefined) {
return;
}
else {
selectedHtml=selectedHtml.replace(/\(/g,"999");
if (stylB==''){stylL='';stylR='';}
if (stylB=='B'){stylL='<b>';stylR='</b>';}
if (stylI==''){stylL=stylL+stylL;stylR=stylR+stylR;}
if (stylI=='I'){stylL=stylL+'<i>';stylR=stylR+'</i>';}
if (stylU==''){stylL=stylL+stylL;stylR=stylR+stylR;}
if (stylU=='U'){stylL=stylL+'<u>';stylR=stylR+'</u>';}
eme =(eme.split(selectedHtml));
disp.value=eme[0]+'<span style=background-color:'+color+'>'+ stylL + selectedHtml + stylR +'</span>'+eme[1]+' ';
disp.blur();
PreviewWindow()
}
}
function PreviewWindow()
{
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if (minutes < 10){
minutes = "0" + minutes;}
if(hours > 11){
APwrite="PM";
if(hours >= 13) {
hours = hours - 12;
}
} else {
APwrite="AM";
}
var TitleA = document.all.Flash_title.value;
var MarketA = document.all.Flash_markets.value;
var PotentialA = document.all.Flash_potconfirm.checked;
var DescriptionA = document.entryForm.Flash_descrip.value;
var instructionsA = document.entryForm.Flash_instr.value;
var TimeA = month + '/' + day + '/' + year +' '+ hours + ':' + minutes + ' '+ APwrite;
var xx1 = '<br><br><h4>Insite Article Preview</h4><table border=1 bordercolor=#cccccc width=55% cellpadding=4 cellspacing=0><tr><td colspan=2><B>';
var xx2 = '</b></td><td><font color=Navy><b>Date:</b></font>';
var xx3 = '</td></tr><tr><td><font color=Navy><b>Market:</b></font>';
var xx4 = '</td><td><font color=Navy><b>Status:</b></font>';
var xx5 = '</td><td><font color=Navy><b>Author:</b></font>Preview</td></tr><tr><td colspan=3><font color=Navy><b>Description:</b></font><br>';
var xx6 = '</td></tr><tr><td colspan=3><font color=Navy><b>Instructions:</b></font><br>';
var xx7 ='</td></tr></table>';
preview.innerHTML = xx1 +TitleA+ xx2 + TimeA + xx3 + MarketA + xx4 +PotentialA+ xx5 +DescriptionA+ xx6 +instructionsA + xx7;
}
</script>
<div name=preview id=preview>
</div>
</body>
</html>
Last edited by pentace; 07-01-2007 at 09:11 PM .
The only error I get is regarding "document.selection" and that's because it's an IE-only object, as far as I know anyway.
for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
{for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";
Last edited by pentace; 07-25-2007 at 06:03 PM .
I'm not seeing that. I copied your code into a new page on my computer, but I didn't get that error message. Do you have a copy of the page online?
for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
{for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";
sorry it is an intranet page if you save it as an html it should work fine.. now it is only designed for ie i only use IE6 here so if your using 7 im not sure if its compatable
I found the line causing your error (on the very line number the error message points you to.)
Code:
else if (desp.value.match(selectedHtml)) {
You're taking this string "selectedHtml" which is the user's input, and you're using it as if it were a regular expression pattern. Possibly "indexOf" is the method you want to use? I'm not sure what you're trying to do, so I can't be sure how to fix it for you. But at least now you know the problem.
for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
{for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";
i knew where the problem is i just do not understand why i get it? since it only happens with special characters i try to remove special characters.
the main purpose od this is to be able to select any text in the text field and color it with a click of the button even if it has special characters.. it is for people at my work not able to understand code
I did my best to explain. What you're doing is storing the user's input into the variable "selectedHtml". That's fine. But then you use that variable as if it were a regular expression when it's really just an arbitrary string. Using it as if it were a regexp is why special characters are causing problems, because they're being parsed as regexp meta characters.
for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
{for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";
I understand what you mean I just am not sure how to do so any other way. But thanks for your help
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks