Thursday, February 26, 2009

ASP RSS Retrieval

Grabs a feed and displays it.

'::::::::::::::::::::::::::::::::::::::::::::::::::
':::: rss.asp ::::::::::::::::::::::::::::::::::
'::::::::::::::::::::::::::::::::::::::::::::::::::

<%
Call getRSS(10)
Sub getRSS(howManyResults)
myRSSfile = "http://rss.news.yahoo.com/rss/tech"
Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP.4.0")
xmlHttp.Open "Get", myRSSfile, false
xmlHttp.Send()
myXML = xmlHttp.ResponseText

Set xmlResponse = Server.CreateObject("MSXML2.DomDocument.4.0")
xmlResponse.async = false
xmlResponse.LoadXml(myXML)
Set xmlHttp = Nothing

Set objLst = xmlResponse.getElementsByTagName("item")
Set xmlResponse = Nothing
intNoOfHeadlines = objLst.length -1
For i = 0 To (intNoOfHeadlines)
Set objHdl = objLst.item(i)
for each child in objHdl.childNodes
Select case lcase(child.nodeName)

case "title"
title = child.text
case "link"
link = child.text
case "description"
description = child.text
'You can also use the following: author,category,comments,enclosure,guid,pubDate,source

End Select

next
kk = kk+1
if kk < howManyresults+1 then
Response.Write "<br /><a href=""" & link & """>" & title & "</a> <br /> " & description & "<br>"
end if
Next

End Sub

%>

'::::::::::::::::::::::::::::::::::::::::::::::::::
'::::::::::::::::::::::::::::::::::::::::::::::::::


Javascript - Selecting a text box on page Load

If you want to have a text input box on your page highlighted on first load, you can use the following java script.

insert into the section of your HTML document:

<script language="javascript" type="text/javascript">
function selectThis() {
var selectval = document.getElementById("textboxid");
selectval.select(); }
</script>

insert into the head tag:
<body onload="selectThis();">

This will select a text box on page load, eg.:
<input type="text" id="textboxid" value="foo">

Also if you would like to have the text highligted as soon as the box is clicked, you can use the tag:
onclick:this.select();

full link:
<input type="text" id="textboxid" value="foo" onclick="this.select();">