Results 1 to 4 of 4

Thread: simple code need explained

  1. #1
    Join Date
    Nov 2008

    simple code need explained

    Well maybe its not so simple... i dont know...

    Im new to javascript. I can do basic things but I only learned it 1 week ago. So this might sound kinda dumb but is it possible to create a set of codes that can do the following:

    1. Prompt the user to enter a URL

    2. Put the url into a
    <a href=""></a>
    where the url is between the quotes and between the tags
    so that the url you see is where the link will take you.


    repeat step 1. and 2. only this time put a
    <img src>
    inside the tag so that an image will represent the url entered.

    Please dont get confused.... yet!

    Now say this can be done. What I want to do is create a single page that will ask for a url, create the link (image or text), and post the raw code so that I can copy it and quickly post it to another page.

    Now I need another code that will do the following:

    After posting the code to my page and seeing the finished result, I want to be able to copy that result and paste it into oneother javascript box, then enter a new url so that the javascript will do the exact same thing as before with the addition of taking the finished code, breaking it down and reposting everything ino raw html so I can copy it again.

    What im trying to achieve is to be able to copy an unlimited number of hypertext links and let javascript break them down for me and return the raw html. And at the same time accept a new url which i enter and return the raw html for that as well.

    I hope that isn't too confusing. I cant explain it too good because I dont understand it that good.

    I dont expect anyone to code this request for me... I just want to know if it can be done and maybe some tips on how I can create this type of code.

    Thanks alot.

    With your feedback I can understand it and explain it better if you have questions about it.

  2. #2
    Join Date
    Nov 2008
    does anyone even know what im talking about?

  3. #3
    Join Date
    Feb 2008
    Here's half of what you asked for:
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Create Links</title>
    <script type="text/javascript">
    function CreateHTML(url, txt, opt, html, output) {
    	var str;
    	if (str = GetCheckedValue(opt)) {
    		url.value = url.value.trimEnds();
    		url.value = url.value || "some url";
    		txt.value = txt.value.trimEnds();
    		txt.value = txt.value || "some text";
    		if (str == 'LINK') {
    			str = '<a href="' + url.value + '">' + txt.value +'</a>';
    		else {
    			str = '<img src="' + url.value + '" border="0" alt="' + txt.value + '">';
    		html.value = str;
    		output.innerHTML = str;
    	return true;
    function GetCheckedValue(grp) {
    	var x, len = grp.length;
    	for (x=0; x<len; ++x) {
    		if (grp[x].checked) return grp[x].value;
    	return null;
    String.prototype.trimEnds = function ()		// trim white-space off both ends of object string
    	return this.replace(/(^\s+)|(\s+$)/g, ''); // return trimmed string
    <form action="" onsubmit="return false">
      <p>URL: <input type="text" name="url" size="32"> Text:
    	<input type="text" name="text" size="20"></p>
      <p><label for="lbl1">Hyperlink:<input type="radio" name="opt" value="LINK" id="lbl1"></label>
      <label for="lbl2"><input type="radio" name="opt" value="IMAGE" id="lbl2">:Image</label></p>
      <p><input type="button" value="Create HTML"
          onclick="return CreateHTML(url, text, opt, html, document.getElementById('output'))"></p>
      <p>HTML: <input type="text" name="html" size="60"></p>
    <p>Example output:<br>
    <div id="output">&nbsp;</div></p>

  4. #4
    Join Date
    Nov 2008
    Awesome. I can work with this. Thanks a lot man. I still want to figure out how to do the rest but for now i will study this.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center