Forum Moderators: open

Message Too Old, No Replies

Positioing a checkbox under an image

Position Checkbox

         

Popdum

2:31 pm on Feb 14, 2008 (gmt 0)

10+ Year Member



Hi,

I have got a form where I need users to click the images they want to delete from a MySQL DB on the server. They choose the images they want to delete by viewing thumbnails of the images.

I would like to position checkboxes under each image, with upto 6 images in one row. How can I do this using javascript?

Thanks for your help

Fotiman

4:29 pm on Feb 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Positioning = Presentation = CSS
You don't want to use JavaScript to accomplish this. Try the CSS forum.

fside

5:58 pm on Feb 14, 2008 (gmt 0)

10+ Year Member



Here's one way to do it. But it's purely javascript. Without the script, absolutely nothing shows. But it may be what you want. It's all the same image. You can use whatever you wish. I include a 'drag' function call, but not the function. It shows how to capture the checkbox click. But I don't know what you wish to do from that point on. And the images are saved as background to same sized DIVs and it might be nice to slide them around.

If this is even close to what you wanted, I would load the style and javascript as external scripts, if you 'deploy'.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>

<STYLE type="text/css"><!--

BODY {
direction: ltr;
margin: 0px;
padding: 0px;
}

.imgBloc {
display: block;
float: left;
margin: 2em 3em 2em 3em;
}

.shoImg {
height: 120px;
width: 120px;
}

#imgBox {
display: block;
margin-left: 10%;
margin-top: 10%;
width: 80%;
}

.chkBox {
text-align: center;
}

// -->
</STYLE>

</head>
<body>

<div id="mainContainer">

<div id="imgBox"></div>

</div>

<script language="JavaScript"><!--

var imgSho2 = { };

(function(){
var someImg = "b3.jpg";

var arImg =[
"1:"+someImg,
"2:"+someImg,
"3:"+someImg,
"4:"+someImg,
"5:"+someImg,
"6:"+someImg,
"7:"+someImg,
"8:"+someImg,
"9:"+someImg,
"10:"+someImg
];

var imgPrefix ="img";
var inputPrefix ="inp";

function $(strID){ return document.getElementById(strID); }

function LPad10(valu,dmax){
/* 100trillion max */
return "000000000000".substr(0, dmax - valu.toString().length) +valu;
}

function addNewImg(numImg){
/* Crude, but avoids IE setAttribute stuff. */
$("imgBox").innerHTML = $("imgBox").innerHTML +"<div class=\"imgBloc\"><div class=\"shoImg\" id=\"" +imgPrefix +numImg +"\"></div><div class=\"chkBox\"></div></div>";
}

imgSho2.init = function(){
var rcrd,rnum,imgLoc,padNum;
var oBloc;

for (var i=0; i <arImg.length; i +=1){
rcrd =arImg[i].split(":");
rnum =rcrd[0];
padNum =LPad10(rnum,2);
imgLoc =rcrd[1];

addNewImg(padNum);
oBloc = $(imgPrefix +padNum );
oBloc.style.background = "url('" +imgLoc +"')";
oBloc.nextSibling.innerHTML = "<input type=\"checkbox\" ondrag\"imgSho2.dragIt(this)\" onclick=\"imgSho2.stayt(this)\"></input>";
oBloc.nextSibling.firstChild.setAttribute("id2",inputPrefix +padNum);
}
}

imgSho2.stayt = function(that){
alert(that.getAttribute("id2"))
}

})();

imgSho2.init();

// -->
</script>

</body>
</html>

Fotiman

7:15 pm on Feb 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I reiterate:
You don't want to use JavaScript to accomplish this. Try the CSS forum.

fside

10:37 pm on Feb 14, 2008 (gmt 0)

10+ Year Member



I reiterate:

It's not clear what 'popdum' wanted. I suggested a way in script to accomplish a display with checkboxes. It's not unlike what you see in M$ live image searches. Sometimes it's not always such a clean separation between ECMAscript and style sheets. Such styles can even be modified using javascript.