/    Sign up×
Community /Pin to ProfileBookmark

how to have values in the grid???

i have done lot of work and created a grid but i have struck in inserting values in that grid can any one help me out in this problem????
heres the code i tried

<html>
<head>
<title>JavaScript Grid</title>
<style type=”text/css”>
/** Floorplan DIV Style */
#floorplan {
background-image: url();
width:1000px;
height:1000px;
border: 1px solid;
}

/** Grid Square Style */
.coordinate
{
border: 2px solid #bbbbbb;
position: absolute;
left: 0px;
top: 0px;
width:35px;
height:25px;
font-size:1px;
font-family:verdana;
color:#000;
padding:0px;
content: ‘5 squares = 140 px’;
}
</style>
<script type=”text/javascript” language=”javascript”>

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

function addLoadEvent(func){
var oldonload = window.onload;
if (typeof window.onload != ‘function’) {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

//Array of Coordinates Set by the User
var setCoords = new Array();
//var s;
//Sets a coordinate and highlights coords on mouseover/out.
function setCoordinate(centerTile, toggle) {
coordSet = -1;

//Because false and 0 evaluate the same.
//TODO: Find a faster way to do this, maybe a string and instr()
s=centerTile;
for (var i = 0; i < setCoords.length; i++) {
if (setCoords[i] == centerTile) {
coordSet = i;
break;
}
}

if (toggle == “on”) {
centerTile.style.backgroundColor = “red”;
} else if (toggle == “off”) {
if (coordSet < 0) {
centerTile.style.backgroundColor = “transparent”;
}
} else if (toggle == “set”) {
if (coordSet > -1) {
setCoords[coordSet] = null;
centerTile.style.backgroundColor = “transparent”;
} else {
setCoords.push(centerTile);
centerTile.style.backgroundColor = “red”;
}
}
}

//Generates a grid square on the page.
function createGridSpace(leftOffset, topOffset)
{
var divTag = document.createElement(“div”);
divTag.id = “coord” + x + “-” + y;
divTag.setAttribute(“align”,”center”);
divTag.style.left = leftOffset + “px”;
divTag.style.top = topOffset+7+ “px”;
divTag.className =”coordinate”;

//divTag.innerHTML = “<p>” + x + “-” + y + “</p>”;

divTag.onmouseover = function() {
setCoordinate(this, “on”);
<?php
echo “1”;
?>
};
divTag.onmouseout = function() {
setCoordinate(this, “off”);
};
divTag.onclick = function () {
setCoordinate(this, “set”);
document.pointform.x.value = divTag.style.left;
document.pointform.y.value = divTag.style.top;
//document.forms[“pointform”].submit();
};

document.body.appendChild(divTag);
//point_it(event)
}
//Creates a grid board of given number of squares.
function createGridBoard(height,width) {
for (y=0; y<height; y++) {
baseTopOffset = (y * 32);
for (x=0; x<width; x++) {
leftOffset = (x *
40) + 7 ;
topOffset = baseTopOffset +7;
createGridSpace(leftOffset,topOffset);

}

}
point_it(event)
}

addLoadEvent(
function() {
createGridBoard(10,11);
}

);

</script>
</head>
<body >
<div id=”pointer_div” onClick=”point_it(event)” style = “background-image:url(‘sun.png’);width:505px;
height:337px;”>
</div>
<form name=”pointform” method=”post” action=”testdb.php”>
<br/>LEFT VALUE = <input type=”text” name=”x” size=”4″ />
<br>TOP VALUE= <input type=”text” name=”y” size=”4″ /><br/>
<input type=”submit” value=”submit”><br/>

</form>
<form name=”point” method=”post” action=”destroy.php”>

<input type=”submit” value=”RESET” name=”RESET”>
</form>
</body>
</html>

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERDec 28.2011 — What do you mean by "insert values into the grid"?

What values? What kind of values?

Where in grid? At current highlighted cell?

Can you explain your problem or desire a bit better? ?
Copy linkTweet thisAlerts:
@ravitejagettamauthorDec 28.2011 — any integer value in the middle of the cell such that it should look like a grid of buttons
Copy linkTweet thisAlerts:
@ravitejagettamauthorDec 28.2011 — integer values..

no in all the cells

my problem is that i need to have a grid with integer values such that it should appear like a grid of buttons.

when i click one cell i need to know the value in that cell....
Copy linkTweet thisAlerts:
@JMRKERDec 29.2011 — Your requirements are still not very well specified, so this remains a SWAG.
<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;JavaScript Grid&lt;/title&gt;
&lt;style type="text/css"&gt;
/** Floorplan DIV Style */
#floorplan {
background-image: url();
width:1000px;
height:1000px;
border: 1px solid;
}

/** Grid Square Style */
.coordinate {
border: 2px solid #bbbbbb;
position: absolute;
left: 0px;
top: 0px;
width:35px;
height:25px;
font-size:0.75em;
font-family:verdana;
color:#000;
padding:0px;
content: '5 squares = 140 px';
}
&lt;/style&gt;
&lt;script type="text/javascript" language="javascript"&gt;
// From: http://www.webdeveloper.com/forum/showthread.php?t=255115

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

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) { oldonload(); }
func();
}
}
}

//Array of Coordinates Set by the User
var setCoords = new Array();
//var s;
//Sets a coordinate and highlights coords on mouseover/out.
function setCoordinate(centerTile, toggle) {
coordSet = -1;

//Because false and 0 evaluate the same.
//TODO: Find a faster way to do this, maybe a string and instr()
s=centerTile;
for (var i = 0; i &lt; setCoords.length; i++) {
if (setCoords[i] == centerTile) {
coordSet = i;
break;
}
}

if (toggle == "on") {
centerTile.style.backgroundColor = "red";
} else if (toggle == "off") {
if (coordSet &lt; 0) {
centerTile.style.backgroundColor = "transparent";
}
} else if (toggle == "set") {
if (coordSet &gt; -1) {
setCoords[coordSet] = null;
centerTile.style.backgroundColor = "transparent";
} else {
setCoords.push(centerTile);
centerTile.style.backgroundColor = "red";
}
}
}

//Generates a grid square on the page.
function createGridSpace(col, row) { // ,row,col) {
leftOffset = col * 40 + 7;
topOffset = row * 32 + 7;
var divTag = document.createElement("div");
divTag.id = row + ":" + col;
divTag.setAttribute("align","center");
divTag.style.left = leftOffset + "px";
divTag.style.top = topOffset+7+ "px";
divTag.className ="coordinate";
// divTag.setAttribute('value',row+':'+col); // testing

divTag.innerHTML = row+':'+col;

divTag.onmouseover = function() {
setCoordinate(this, "on");
&lt;?php echo "1"; ?&gt;
};
divTag.onmouseout = function() {
setCoordinate(this, "off");
};
divTag.onclick = function () {
setCoordinate(this, "set");
document.pointform.rc.value = this.id;
document.pointform.x.value = divTag.style.left;
document.pointform.y.value = divTag.style.top;
};

document.body.appendChild(divTag);
//point_it(event)
}
//Creates a grid board of given number of squares.
function createGridBoard(height,width) {
for (y=0; y&lt;height; y++) {
baseTopOffset = (y * 32);
for (x=0; x&lt;width; x++) {
createGridSpace(x,y);
}
}
// point_it(event); // function is not defined
}

addLoadEvent( function() { createGridBoard(10,10); }

);

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;!-- div id="pointer_div" onClick="point_it(event)" // function is not defined --&gt;
&lt;div id="pointer_div" style = "background-image:url('sun.png');width:505px;height:337px;"&gt;
&lt;/div&gt;
&lt;form name="pointform" method="post" onsubmit="return false"&gt;
&lt;!-- action file not supplied --&gt; &lt;!-- action="testdb.php" --&gt;

&lt;br/&gt;LEFT VALUE = &lt;input type="text" name="x" size="4" /&gt;
TOP VALUE = &lt;input type="text" name="y" size="4" /&gt;
Row:Col = &lt;input type="text" name="rc" size="4" /&gt;
&lt;br /&gt;&lt;input type="submit" value="submit"&gt;&lt;br/&gt;
&lt;/form&gt;

&lt;!-- action file not supplied
&lt;form name="point" method="post" action="destroy.php"&gt;
&lt;input type="submit" value="RESET" name="RESET"&gt;
&lt;/form&gt;
--&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @ravitejagettam spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...