How to store url in database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manu g
    New Member
    • Nov 2010
    • 2

    How to store url in database

    i have to store url in database and retrieve it i am currently using
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function show()
    {
    var s=document.se.key.value;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txt").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","s1.php?q="+s,true);
    xmlhttp.send();
    }
    </script>
    </head>
    <body>
    <form name="se" action="s1.php" method="get">
    <input type="text" name="key" value="" />
    <input type="button" name="query" value="search" onclick="show();" />
    <span id="txt"></span>
    </form>
    </body>
    </html>
    but the url retrieved appears asa text and a hyperlink to the that url.help me out with this.i want the retrieved url to be a hyperlink referring to that url
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    If your url is coming from the database in the format of http://www.example.com then you would want to place it into an anchor tag not a span tag. You would also want to set the href attribute to the url.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function show()
    {
    var s=document.se.key.value;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
    	document.getElementById("txt").innerHTML=xmlhttp.responseText;
    	document.getElementById("txt").href=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","s1.php?q="+s,true);
    xmlhttp.send();
    }
    </script>
    </head>
    <body>
    <form name="se" action="s1.php" method="get">
    <input type="text" name="key" value="" />
    <input type="button" name="query" value="search" onclick="show();" />
    <a id="txt" href=""></a>
    </form>
    </body>
    </html>

    Comment

    • JKing
      Recognized Expert Top Contributor
      • Jun 2007
      • 1206

      #3
      Originally posted by manu g
      but how to store the href attribute,i want the url retrieved from database to be the href attribute.
      Line 20 in the code I just posted sets the href attribute.

      Unless I am misunderstandin g what you want to do.

      Comment

      Working...