DotDragnet
May 23, 2012, 04:13:34 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: follow us on twitter @dotdragnet
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: jQuery - textual input => image  (Read 696 times)
Charisma Bypass
Hero Member
*****
Posts: 556



View Profile Awards
« on: January 08, 2010, 10:25:45 AM »

Here's one I can't get my head around;

I have a text input in a form.  When the user is typing in that box, I want images to appear as he is typing.

Imagine it's for a tshirt product, where the buyer can make a slogan to be printed on it.  As he is typing his slogan the letters appear on the tshirt as a visual representation.

Any ideas?  TIA
Logged
samhs
Administrator
Hero Member
*****
Posts: 1711



View Profile WWW Awards
« Reply #1 on: January 08, 2010, 10:36:53 AM »

$("input").change(function () {
 $("#display").html("<div></div>"); //reset the contents of #display to be empty other than a <div>
 // look through the contents of the string and load each image accordingly
 tmpstring = $(this).val();
 for (var i=0;i<tmpstring.length;i++) {
   theletter = tmpstring.charAt(i);
   $("#display div").append("<img src='"+theletter+".gif' />");
 }
});

I've not tested this so it may be broken. You need an input and a div with an id of "display", plus a load of images a.gif, b.gif, c.gif etc etc. Not sure how you'd deal with uppercase letters, numbers or punctuation.

Also this isn't very bandwidth friendly - it loads the images again and again each time you change the word - so you change it from burt to burty and it reloads all the burt letters as well as the y. Just so you know.

HTH
Logged

Loose adj a not held together; not fastened or firmly fixed in place
Lose verb to misplace something. To fail to keep or obtain something, especially because of a mistake, carelessness, etc.
---
Blog: www.ohwrite.co.uk
Twitter: www.twitter.com/samhs
Charisma Bypass
Hero Member
*****
Posts: 556



View Profile Awards
« Reply #2 on: January 08, 2010, 10:44:13 AM »

Why DDN is still a beautiful place!  Will test it out imminently.
Thank You Sam.
Logged
samhs
Administrator
Hero Member
*****
Posts: 1711



View Profile WWW Awards
« Reply #3 on: January 08, 2010, 01:19:39 PM »

Hey - no worries. I hope it works for you.
Logged

Loose adj a not held together; not fastened or firmly fixed in place
Lose verb to misplace something. To fail to keep or obtain something, especially because of a mistake, carelessness, etc.
---
Blog: www.ohwrite.co.uk
Twitter: www.twitter.com/samhs
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!