Could someone please explain why the following works in IE5, but not FF3?
Thanks in advance! -
function meRelease(id){
-
endnum = document.getElementById(id).value;
-
alert(endnum);
-
}
-
-
<td width="30%" id="1.1" value="1" onmouseover="checkHighlight(this.id)" onmousedown="meClick(this.id)" onmouseup="meRelease(this.id)"><div align="center">1</div></td>
-
15 7680
there is no value property in HTMLTableCellElement (even if you define a value attribute)
PS: check out the HTML Validation service
Also note that IDs cannot (or should not) start with a number - see link.
@acoder
browsers are quite forgiving*. though, of course, the document will be invalid then.
* tested it myself
Thanks for the replies. I'm adopting a script I found at the following URL http://forums.devshed.com/javascript...e-87376-2.html
My version works by using onmousedown to select any cell in a table, and with onmouseover and onmouseup, select a rectangular range of cells. I'd like to put the selected cell IDs (or VALUES) in an array (for PHP later on). Here's my current script.... -
function checkHighlight (id)
-
{
-
var idmarker = id.split( '.' );
-
var column;
-
var row;
-
-
for ( row = startrow; row <= tableRows; row++ )
-
{
-
for ( column = startcol; column <= tableColumns; column++ )
-
{
-
document.getElementById( column + '.' + row ).style.backgroundColor = '#FFFFFF';
-
}
-
}
-
counter=0;
-
myCells=new Array();
-
for ( row = startrow; row <= idmarker[1]; row++ )
-
{
-
for ( column = startcol; column <= idmarker[0]; column++ )
-
{
-
document.getElementById( column + '.' + row ).style.backgroundColor = highlightColor;
-
counter++;
-
myCells[counter]=document.getElementById(id).innerHTML;
-
}
-
}
-
// document.getElementById( 'tableSize' ).innerHTML = idmarker[1] + 'x' + idmarker[0];
-
// document.getElementById( 'tableSize' ).innerHTML = myCells[0]+','+myCells[1]+','+myCells[2];
-
}
-
Unfortunately this just fills the array with duplicates of the last cell selected. Any sugesstions to fill the array with all the cells selected?
Thanks in advance!
Hi again,
I have attached a tidied-up version which should be easier to follow. Any help in putting the selected cells in an array is greatly appreciated! -
function checkHighlight (id)
-
{
-
var idmarker = id.split( '.' );
-
var column;
-
var row;
-
var string = "";
-
-
for ( row = startrow; row <= tableRows; row++ )
-
{
-
for ( column = startcol; column <= tableColumns; column++ )
-
{
-
document.getElementById( column + '.' + row ).style.backgroundColor = '#FFFFFF';
-
}
-
}
-
counter=0;
-
myCells=new Array();
-
for ( row = startrow; row <= idmarker[1]; row++ )
-
{
-
for ( column = startcol; column <= idmarker[0]; column++ )
-
{
-
document.getElementById( column + '.' + row ).style.backgroundColor = highlightColor;
-
myCells[counter]=document.getElementById(id).innerHTML;
-
counter++;
-
}
-
}
-
// document.getElementById( 'tableSize' ).innerHTML = idmarker[1] + 'x' + idmarker[0];
-
for ( arraycnt = 0; arraycnt < counter; arraycnt++ )
-
{
-
if (string==""){
-
string = myCells[arraycnt]
-
} else {
-
string = string + ',' + myCells[arraycnt]
-
}
-
}
-
document.getElementById( 'selectedCells' ).innerHTML = 'SELECTED CELLS:'+string;
-
}
-
Thanks for any help!
Perhaps it might help if you give the values of startcol/row, etc. that are not defined within the function and the HTML of the table so that we're not second-guessing what you're using.
Thanks for the reply.
Below is all the code... as you can see the array just duplicates the bottom right-most cell selected.
Any help gratefully appreciated!
Line 34 should be: - myCells[counter]=document.getElementById(column + '.' + row).innerHTML;
Note that if you mouse over without having first clicked, you will get an error because startcol/row won't have been set. Another problem is that when you click on another cell, you need to reset the background colours.
Doh! Thanks for the correction!
Yeah, I'm trying to set things up so that cells are selected by click-drag-and-release. I only want "onmouseover" activated while "onmousedown" is active. I'm guessing I need to embed the myHighlight function when myClick is engaged. Any ideas on how I might do this?
Thanks!
You may want to look into the onmousemove event.
Okay... I've figured out how to enable and disable "onmousemove", depending on whether a mouse button event is flagged down or up, but could someone explain to my why the "id" of the selected cell now isn't being passed to the function: -
window.onload = function() {
-
//monitor mouseclicks over "mytable"
-
document.getElementById("mytable").onmousedown = mouseDownHandler
-
document.getElementById("mytable").onmouseup = mouseUpHandler
-
}
-
-
function mouseDownHandler() {
-
startnum = document.getElementById(this.id).id;
-
alert(startnum);
-
}
-
-
</script>
-
</head>
-
<body>
-
<table id="mytable" style="text-align: left; width: 400px;" border="2"
-
cellpadding="2" cellspacing="2">
-
<tbody>
-
<tr>
-
<td>A</td>
-
<td id="1.1">1</td>
-
<td id="2.1">2</td>
-
<td id="3.1">3</td>
-
<td id="4.1">4</td>
-
</tr>
-
Thanks!
line 8 seems strange, wouldn't be startnum = this.id; be more reasonable?
Thanks for the reply!
I now get an alert (i.e., startnum is assigned), but "this.id" is always assigned "mytable" rather than the id of the cell I just clicked.
Yeah, I've a lot to learn regarding DOMs.
Thanks in advance for any further help!
Figured it out... -
function mouseDownHandler(e) {
-
startnum = e.target.id;
-
alert(startnum);
-
}
-
Just a quick not to say the above is NOT compatible with IE5. Instead use: -
document.onmouseover = function(e){
-
e = e || window.event;
-
targ = e.target || e.srcElement;
-
currcoords = targ.id;
-
alert(currcoords);
-
}
-
Thanks!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Federico Bari |
last post by:
Good morning all from italy,
i have probably a compatibility problem with a html/javascript page.
The aim of the code of the file test.htm you find here following (copy the
3 files in the...
|
by: michael |
last post by:
I guess this is partly a javascript questions, but is there a way to check
if a CSS id or class exists anywhere on a page.
For example, if the id "bla" exists, it should return true only if the...
|
by: michael |
last post by:
Is there a way for Javascript to check if a document CSS id exist anywhere
on a page, for example, if "bla" exists?
<a href="asf" id="bla">
|
by: JJA |
last post by:
I'm trying to use document.getElementByID inside a function where the
ID is passed as an argument. I get the same error ("Element has no
properties") on the same statement inside the commonCheck...
|
by: Ghyslaine Crespe |
last post by:
Hello,
In my script, the line
document.getElementById(id).style.background-position = "-200px -500px";
fails !
So, how can I change the background-position value ?
|
by: summer00 |
last post by:
Hi everyone,
I found that the value of a variable(string type for example) is lost
after the aspx page postback.
E.G:
private void Page_Load(object sender, System.EventArgs e)
{
|
by: Katie |
last post by:
Hi
I have a function which uses the document.getElementById('id') to
change attributes of form objects etc. Is there any way i can find out
if the element is a checkbox, textbox, radio button...
|
by: vps |
last post by:
Please help me get the value of a textarea field:
--------------------- The script ---------------------
<html>
<head>
<script type="text/javascript">
|
by: raknin |
last post by:
Hi
I have a carousel script. I want to load the carousel with a new set of pictures every time I press a button. The problem that I have that the script append the new pictures to the olds one...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |