Can anyone help find some code for me?

Status
Not open for further replies.

BJ Dibbins

Right off the assembly line
Hi all,

I'm looking for some code and wondering if anyone can help?

I'd like to be able to extract the first letter of each word that is pasted into an input box on a website.

For example, if someone entered "It was the best of times, it was the worst of times" the program would return "Iwtbotiwtwot"

Any ideas?

Cheers,

Brian
 

rohan

In the zone
Since you said 'website', it is possible you want it mostly in JavaScript. Here's a sample page:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "*www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="*www.w3.org/1997/xhtml" lang="en" xml:lang="en">
  <head>
   <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"/>
   <title>Extract the first letter of each word</title>
   <script type="text/javascript">
	<!--
	var box;
	var output;

	function onLoad() {
		box = document.getElementById('user_word');
		output = document.getElementById('put_string');
	}

	function process() {
		var datum = box.value;
		var out = "";
		var words = new Array();
		words = datum.split(" ");

		for(var i=0; i<words.length; i++) {
			out += words[i].substr(0, 1);
		}

		output.innerHTML = out;
	}
	-->
   </script>
  </head>

 <body onload="javascript:onLoad()">
  <p>
   <input type="text" id="user_word" size="20"/><input type="button" value="Go" onclick="javascript:process()"/><br/>
   <span id="put_string"></span>
  </p>
 </body>
</html>

Hmm.. that's pretty much everything. Hope it helps. -rohan
 
OP
B

BJ Dibbins

Right off the assembly line
Hi guys,

Arun, I'm looking for something I could use primarily from a website, so perhaps javascript would be best?

Rohan, thank you very much for the code - that's pretty much exactly what I was after. I've got a project in mind that would use this function, as well as some further character replacement. If you're interested in developing the code further could you email me so we could discuss it?

Cheers,

Brian
 
Status
Not open for further replies.
Top Bottom