Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 13th, 2005, 06:32 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert HTML at certain point in string.

Hi,

Further to my post about counting tables I also want to allow smilies to be entered into the posts. the way I thought to do it would be to us IndexOf() again and search for a string such as ":)". Then when that string is encountered to insert a html string like this: "<img src =\"grin.gif\">". I have tried this approach though and can't get it to work. Here is my script:

<html>
<head>
<title>
Smilie Test</title>
</head>

<body>
<div id ="div1"></div>
<form name ="form1">
<input type ="text" name = "smilebox">
<input type ="button" name ="but1" onclick ="addsmile()" value ="click">
</form>
<script language ="javascript">
function addsmile(){
var SmileStr = document.form1.smilebox.value
var thestr = ":\)"

var found = 0;
var smilecount = 0;


    while (found != -1){

    found = SmileStr.indexOf(thestr, SmileStr)
        if (found !=-1){
        addHTML ="<img src =\"grin.gif\">"
        smilecount++
        found++
        }
    }

div1.innerHTML = div1.innerHTML + addHTML
}
</script>
</body>
</html>

This just adds the string no matter what is in the input field. Help!

Thanks
interrupt

__________________
\'sync\' &lt;cr&gt;
The name specified is not recognized as an internal or external command, operable program or batch file.
  #2 (permalink)  
Old June 13th, 2005, 07:21 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Its ok I sorted it using the replace function.


cheers
interrupt



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using INSERT INTO with a string Variable Suspect Access VBA 2 January 6th, 2015 11:25 AM
Remove orphaned html elements from html string pauliehaha C# 2008 aka C# 3.0 2 June 30th, 2008 09:40 AM
how to insert these string into database SpringSummer SQL Language 3 September 22nd, 2007 07:05 AM
Insert Table using office interop Power Point yuenli C# 2005 0 September 2nd, 2007 04:55 AM
String to DateTIme for Insert plymnet Classic ASP Databases 1 August 21st, 2005 11:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.