Click to See Complete Forum and Search --> : how to bold dynamic text in HTML?


sel129
04-04-2008, 03:24 AM
Hello Everyone,

Can anyone help me with my html problem??

I have a form showing one chunk record at one time. This record is from a table. I want this form to bold certain text from that chunk of record. Since the record is not hardcoded/type inside the form. I want the bold funtion to be dynamic.

Let say,

Record one:
I have an apple.
I want to eat it now.

Record two:
I have a strawberry.
I dun want to eat it now.


First case, I want to bold the whole first line,with the word 'have' in it.. But this line can be anywhere in the page.. It doesn't always have specific position as long as the sentence have the word 'have' in it.

Second case, I want the script to bold the word 'want' every time it finds it.. And only that word!

Can anybody help me on how to do this.. I really dunno how to? :confused:

KDLA
04-04-2008, 07:21 AM
Put the bolding in the database entry.

TheBearMay
04-04-2008, 07:21 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function boldMe(wrd) {
var sStr = "/"+wrd+"/gi";
var rStr = "<span style='font-weight:bold'>"+wrd+"</span>"
var wArea = new String(document.getElementById("iPut").innerHTML);
document.getElementById("oPut").innerHTML = wArea.replace(eval(sStr), rStr);
}
</script>

</head>

<body>
<div id="iPut">
Let's bold all of the word want. It's not like I really have anything I want or need to do to the word... It's just that someone may want too....."
</div>
<button onclick="boldMe('want')">Bold</button>
<div id="oPut"></div>
</body>
</html>

coothead
04-04-2008, 01:51 PM
you can find another solution here...
http://www.htmlforums.com/showpost.php?p=644066&postcount=2