Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic text to html formater

Status
Not open for further replies.

TheTaoOfBill

Programmer
Mar 14, 2006
1
US
I guess it's been too long since I've brushed up on my Javascript because something that seemed simple became very difficult very fast.

Basically I am trying to create a formater in javascript. I post listings on ebay for a living and part of the job involves copying a few lines of description and pasting it into the ebay description and formating it to be seperated by lines with a dash before it. The original description has things seperated by commas and I want to be able to copy the whole thing and input it into the program and have it come out in html with a dash before it and a line break at the end. This would cut my work time in half. I know it is very possible in Javascript. In fact I did something like this before. But I just can't seem to get it to work this time. This is the code I made.

Code:
	<!-- HIDE FROM INCOMPATIBLE BROWSERS
		function Jumble()
	     {
				var input = document.forms[0].description.value;
				var split = input.split(", ");
				var output = "";
				for(i=0; i < split.length; i++;)
				{
					if( i != 1 - split.length)
						output = output + "-" split[i] + "<br />\n\n";
					else
						output = output + "-" split[i] + "<br />";
				}						
				document.forms[0].description.value = output;
			}
				
	// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
	</script>
</head>

<body>
	
	<form >
		<p>Description Formater<br />
		<textarea name="description" cols="50" rows="30" /></textarea> </p>
		<p><input type="button" value="Format" onclick="return Jumble();" /> </p>
	</form>
Everything looks fine to me but when I run it I get an error in the java console saying the Jumble function is not defined. But as far as I can tell it is defined. I am guessing there is something wrong with the code within the function. But I can't really figure out what I did wrong. I'm just really rusty I guess. Can someone help me out?
 
>for(i=0; i < split.length; i++;)
[tt]for(i=0; i < split.length; i+[highlight]+)[/highlight][/tt]
But you should better device a scheme that leaves the repetitive click return the same result (ie stable) rather than changing each time that would be cause trouble at the end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top