URL input box for textarea?

Discussion in 'JavaScript' started by jasondavis, Feb 9, 2008.

  1. #1
    I am looking everywhere for the most basic way to

    take a text area, have a text link that says "Add Link" clcikt he link, a box pops up asking for website url, then you click ok, then it popsup asking for title, you clcik ok, it then creates an html text link, not bbcode but a real html link with this with a class="bluelinkbold' added to the link as well, any help greatly appreciated
     
    jasondavis, Feb 9, 2008 IP
  2. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The most basic method is something like:

    You will need to change the enter the... words, the FORMNAME and fieldname.

    
    <script>
    function CreateLink(){
    var iurl =  prompt("ENTER THE URL OR DIE", "");
    var ititle =  prompt("ENTER THE TITLE OR DIE", "");
    
    document.forms["FORMNAME"].fieldname.value "<a href=\""+iurl+"\" class=\"bluelinkbold\">"+ititle+"</a>";
    
    }
    </script>
    
    <form>
    	<input type="button" value="ADD A LINK" onclick="CreateLink();">
    </form>
    
    Code (markup):
     
    imvain2, Feb 10, 2008 IP
  3. jasondavis

    jasondavis Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply, I tried this code below but it gives errors;



    
    <script>
    function CreateLink(){
    var iurl =  prompt("ENTER THE URL OR DIE", "");
    var ititle =  prompt("ENTER THE TITLE OR DIE", "");
    document.forms["form1"].description.value "<a href=\""+iurl+"\" class=\"bluelinkbold\">"+ititle+"</a>";
    }
    </script>
    
    
    <form name="form1" method="post">
    <input type="button" value="ADD A LINK" onclick="CreateLink();">
    <textarea name="description" cols="80" rows="4" id="description"></textarea>
    </form>
    
    
    PHP:
     
    jasondavis, Feb 10, 2008 IP
  4. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ooopss my fault, thats what I get when I edit the code AFTER I knew it was working.

    You need to change:
    
    document.forms[COLOR=#66CC66][[/COLOR][COLOR=#FF0000]"form1"[/COLOR][COLOR=#66CC66]][/COLOR].description.value [COLOR=#FF0000]"<a href=[COLOR=#000099][B]\"[/B][/COLOR]"[/COLOR]+iurl+[COLOR=#FF0000]"[COLOR=#000099][B]\"[/B][/COLOR] class=[COLOR=#000099][B]\"[/B][/COLOR]bluelinkbold[COLOR=#000099][B]\"[/B][/COLOR]>"[/COLOR]+ititle+[COLOR=#FF0000]"</a>"[/COLOR];
    
    Code (markup):
    to
    
    document.forms[COLOR=#66CC66][[/COLOR][COLOR=#FF0000]"form1"[/COLOR][COLOR=#66CC66]][/COLOR].description.value [COLOR=#FF0000]= "<a href=[COLOR=#000099][B]\"[/B][/COLOR]"[/COLOR]+iurl+[COLOR=#FF0000]"[COLOR=#000099][B]\"[/B][/COLOR] class=[COLOR=#000099][B]\"[/B][/COLOR]bluelinkbold[COLOR=#000099][B]\"[/B][/COLOR]>"[/COLOR]+ititle+[COLOR=#FF0000]"</a>"[/COLOR];
    
    Code (markup):
     
    imvain2, Feb 10, 2008 IP
  5. jasondavis

    jasondavis Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hey thanks, that worked in firefox but didnt seem to work in IE, I found another code that worked in firefox and IE until I changed the bbcode to html, maybe you could change it to use html for me possible, heres the line

    
      function DoLink() {
         var link=prompt("Enter Link","http://");
         if (link!=null) { insertAtCursor('textAREAname','[link=' + link + ']'); }
      }
    
    
    PHP:
    when I change bbcode for link to <a href=" " class="bluelinkbold">text<a/>
    it gives errors
     
    jasondavis, Feb 10, 2008 IP
  6. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I just tested my code in IE and it works fine.
     
    imvain2, Feb 10, 2008 IP
  7. jasondavis

    jasondavis Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I got it working now, thanks for the help =)
     
    jasondavis, Feb 10, 2008 IP