View Full Version : Input and Highlight Code

10-11-2003, 07:03 PM

Hopefully someone can point me to a tutorial...

I can find tutorials on how to highlight a block of text, but what I need to do is have code inserted around a text block so that the entire thing (code and text) can be highlighted for cut and paste.

For example, I would like someone who is not familiar with html to be able to enter a url and descriptive name, hit enter, then then appropriate codes <a href="...etc) would surround the url and link name. That person could subsequently highlight the entire block and copy and paste the resultant code into a web page builder.

Is there a tutorial that would show how to have the code surround the user input? I've tried searching Google, this forum, and a Javascript tutorial site, but nothing appropriate comes up with my search terms (highlight javascript tutorial and similar terms).

Any help would be very much appreciated.


10-11-2003, 07:09 PM
<script type="text/javascript">
function createLink(url,text) {
var htmlStr = "<a href=\"" + url + "\">" + text + "</a>";
document.forms[0].linkCode.value = htmlStr;
URL: <input type="text" name="url"/><br/>
Text: <input type="text" name="text"/>
<input type="button" onclick="createLink(this.form.url.value,this.form.text.value);" value="Create Code"/>
<textarea name="linkCode"></textarea>

Hope that helps!

Happy coding! :)

10-12-2003, 12:28 AM
Hi nolachrymose,

Thanks!!! It works great! I've studied the code so that I understand what is happening, but I never would have gotten that on my own...

I appreciate your help,

12-26-2007, 02:16 PM
Can you give me please some tutorials for creating highlighted code inside html code for example? Thancks PS. I want to be written in javascript. I have to make an editor of html