postitlord
11-16-2004, 05:22 PM
1. I want to press escape anywhere on the page, and have the content of the text box be selected. Regardless of whichever element on the page has the focus. Is this possible?
1b. I also want to prevent the native behavior of escape deleting the contents of the text box. It seems to happen only at first.
2. When you put in 2300023, I want the image that appears to link to http://www.radioshack.ca/estore/Product.aspx?product=2300023 via a pop-up window. At the moment when you type a number and press enter, simply the image will appear.
I understand very little of DIVs, and have no clue how to attach a link to this. I've marked red where I think it should be made a link.
Live version: http://hosting.mixcat.com/nastajus/display.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Display Picture - DDV DSC SWG too!</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<style type="text/css">
/*<![CDATA[*/
div {
width:300px;
background:#fff;
border:solid 1px #000;
float:left;
margin:1px;
}
/*//]]>*/
</style>
<script type="text/javascript">
//<![CDATA[
var url="http://www.radioshack.ca/images/RadioShack/";
function displayPic() {
var pattern=document.forms[0][1].value;
pattern = pattern.replace(".","-");
pattern=trim(pattern); ///delete
var len=pattern.length;
var dash=pattern.indexOf("-");
var gen=0;
var spe=0;
//dash used
if (dash!=-1) {
gen=pattern.substr(0, dash);
spe=pattern.substr(dash+1, len-dash);
if (gen<10){gen=gen*100};
if (gen<100){gen=gen*10};
}
//dash not used
else {
gen=pattern.substr(0, 3);
spe=pattern.substr(3, len);
}
spe=pad(spe,4);
var dir = pattern.substr(0, 2)+"/";
elemD=document.createElement("div");
elemP=document.createElement("p");
elemP.appendChild(document.createTextNode(gen+"-"+spe));
elemI=document.createElement("img");
elemI.setAttribute("src",url+dir+gen+spe+"l.jpg");
elemD.appendChild(elemP);
elemD.appendChild(elemI);
document.body.appendChild(elemD);
//Attempt to link to: http://www.radioshack.ca/estore/Product.aspx?product=2300023
selecttext();
}
function pad(number,length) {
var str = '' + number;
while (str.length < length)
str = '0' + str;
return str;
}
function trim(str) {
return str.replace(/^\s*|\s*$/g,"");
}
function checkKey(e){
if(e && e.which){
e = e;
characterCode = e.which;
}
else{
e = event;
characterCode = e.keyCode;
}
//enter pressed
if(characterCode == 13){
displayPic();
return false;
}
//escape pressed
else if(characterCode == 27){
document.forms[0][1].select()
return false;
}
else{
return true;
}
}
function selecttext() {
document.forms[0][1].select();
}
function hide() {
if(document.body.appendChild(elemD)) {
document.body.removeChild(elemD); /*removes current div only*/
}
}
//]]>
</script>
</head>
<body onload="document.forms[0][1].focus()">
<form action="" onSubmit="return false;">
<fieldset>
<input type="text" onKeyPress="checkKey(event)" />
<input type="button" value="display image" onclick="displayPic()" />
<input type="button" value="hide image" onclick="hide()"/>
</fieldset>
</form>
</body>
</html>Original thread (http://htmlforums.com/showthread.php?s=&threadid=47222) regarding this page's inception.
1b. I also want to prevent the native behavior of escape deleting the contents of the text box. It seems to happen only at first.
2. When you put in 2300023, I want the image that appears to link to http://www.radioshack.ca/estore/Product.aspx?product=2300023 via a pop-up window. At the moment when you type a number and press enter, simply the image will appear.
I understand very little of DIVs, and have no clue how to attach a link to this. I've marked red where I think it should be made a link.
Live version: http://hosting.mixcat.com/nastajus/display.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Display Picture - DDV DSC SWG too!</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<style type="text/css">
/*<![CDATA[*/
div {
width:300px;
background:#fff;
border:solid 1px #000;
float:left;
margin:1px;
}
/*//]]>*/
</style>
<script type="text/javascript">
//<![CDATA[
var url="http://www.radioshack.ca/images/RadioShack/";
function displayPic() {
var pattern=document.forms[0][1].value;
pattern = pattern.replace(".","-");
pattern=trim(pattern); ///delete
var len=pattern.length;
var dash=pattern.indexOf("-");
var gen=0;
var spe=0;
//dash used
if (dash!=-1) {
gen=pattern.substr(0, dash);
spe=pattern.substr(dash+1, len-dash);
if (gen<10){gen=gen*100};
if (gen<100){gen=gen*10};
}
//dash not used
else {
gen=pattern.substr(0, 3);
spe=pattern.substr(3, len);
}
spe=pad(spe,4);
var dir = pattern.substr(0, 2)+"/";
elemD=document.createElement("div");
elemP=document.createElement("p");
elemP.appendChild(document.createTextNode(gen+"-"+spe));
elemI=document.createElement("img");
elemI.setAttribute("src",url+dir+gen+spe+"l.jpg");
elemD.appendChild(elemP);
elemD.appendChild(elemI);
document.body.appendChild(elemD);
//Attempt to link to: http://www.radioshack.ca/estore/Product.aspx?product=2300023
selecttext();
}
function pad(number,length) {
var str = '' + number;
while (str.length < length)
str = '0' + str;
return str;
}
function trim(str) {
return str.replace(/^\s*|\s*$/g,"");
}
function checkKey(e){
if(e && e.which){
e = e;
characterCode = e.which;
}
else{
e = event;
characterCode = e.keyCode;
}
//enter pressed
if(characterCode == 13){
displayPic();
return false;
}
//escape pressed
else if(characterCode == 27){
document.forms[0][1].select()
return false;
}
else{
return true;
}
}
function selecttext() {
document.forms[0][1].select();
}
function hide() {
if(document.body.appendChild(elemD)) {
document.body.removeChild(elemD); /*removes current div only*/
}
}
//]]>
</script>
</head>
<body onload="document.forms[0][1].focus()">
<form action="" onSubmit="return false;">
<fieldset>
<input type="text" onKeyPress="checkKey(event)" />
<input type="button" value="display image" onclick="displayPic()" />
<input type="button" value="hide image" onclick="hide()"/>
</fieldset>
</form>
</body>
</html>Original thread (http://htmlforums.com/showthread.php?s=&threadid=47222) regarding this page's inception.