Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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.
Reply With Quote
  #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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:58 AM.


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