"melvynadam" <me*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
If I open a new page with very little text on it such as
a bugmenot
results page is there a way to select some of the text there and
assign it to variables?
Selecting all and copying to the clipboard can be done with:
document.execCommand("SelectAll");
document.execCommand("Copy");
but I'm looking for something a little more refined.
The page contains seven lines of text and I'd like a simple way to say:
var username = [contents of line 4]
var password = [contents of line 5]
Can anyone point me in the right direction?
Will this help? Watch for word-wrap.
<html>
<head>
<title>bugmenot.htm</title>
<script type="text/javascript">
function bugmenot() {
var sWWW =
http://www.bugmenot.com/view.php?url=;
var sURL = document.getElementById("URL").value;
var oXML = new ActiveXObject("Microsoft.XMLHTTP");
oXML.Open("GET",sWWW+sURL,false);
oXML.send();
try {
var sXML = oXML.ResponseText;
var iDD1 = sXML.indexOf("<dd>");
var iDD2 = sXML.indexOf("</dd>");
var sVAL = sXML.substr(iDD1+4,iDD2-iDD1-4);
var sUSR = sVAL.substr(0,sVAL.indexOf("<"));
var sPWD = sVAL.substr(sVAL.indexOf(">")+1);
document.getElementById("USR").value = sUSR;
document.getElementById("PWD").value = sPWD;
document.all.i.src = sWWW+sURL;
} catch(e) {
alert(sWWW + sURL + " Failed!");
}
}
</script>
</head>
<body>
<center>
<form>
<table border="0" width="600">
<td align="center">
<b>Enter a URL: </b>
<input type="text" name="URL" id="URL" size="30"
value="www.nytimes.com">
<input type="button" value="Bug Me Not!" onclick="bugmenot()">
</td>
<tr>
</tr>
<td align="center">
<b>Username: </b>
<input type="text" name="USR" id="USR" readonly>
<b>Password: </b>
<input type="text" name="PWD" id="PWD" readonly>
</td>
</tr>
</table>
</form>
<iframe name="i" align="center"
frameborder="1" scrolling="no"
marginwidth="0" marginheight="0"
style="width:600; height: 380"></iframe>
</body>
</html>