473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

insertCell problems

Trying to modify some code from :
http://www.faqts.com/knowledge_base/view.phtml/aid/2357
But having some problems. Cant work out how/why its not adding rows in
the right place. seems strange to me. Im trying to get the NS code
working first since that appears to be a bit harder to figure out..
heres my code..
http://www.sourceymonkey.com/tmp/upload.html

I was guessing it was something to do with var f but playing around
with that seems to make things worse.

Any help much appreciated. I have a might headache and now need some
chocolate to compensate. :)
Jul 20 '05 #1
4 5109
DU
will wrote:
Trying to modify some code from :
http://www.faqts.com/knowledge_base/view.phtml/aid/2357
But having some problems. Cant work out how/why its not adding rows in
the right place. seems strange to me. Im trying to get the NS code
working first since that appears to be a bit harder to figure out..
heres my code..
http://www.sourceymonkey.com/tmp/upload.html

I was guessing it was something to do with var f but playing around
with that seems to make things worse.

Any help much appreciated. I have a might headache and now need some
chocolate to compensate. :)


I have not tested the code but I am able to make the following
comments/recommendations:

1- You can remove language="Javascript1.1" since language is deprecated
and has been superseded by type

2- var row = table.insertRow(++f);
Here the new f value is incremented and is now, say, 1 (was 0 before the
incrementation).
var row2 = table.insertRow(f+2);

It looks like you're giving the instruction to insert a row at index 3.
Is that intended?
When I try your file, the Image Caption numbers as output by
input.value = 'Image Caption'+f;
do not follow accordingly,.. so this is most likely the source of your
logical bug in your script.

3- input.setAttribute('type', 'file');
"General rule: don't use setAttribute() when a better way of setting the
attribute is available"
http://www.xs4all.nl/~ppk/js/w3c_core.html#attributes
HTMLInputElement.type
type of type DOMString, modified in DOM Level 2
The type of control created (all lower case).
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-62883744

So,
input.type = "file";
input.type = "text";
and
input.type = "button";
seem more appropriate

4- input.size = '24';
size of type unsigned long, modified in DOM Level 2
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-79659438
So
input.size = 24;
seems more appropriate

5- Regarding browser support detection, the script has logical problems
and could be more precise. MSIE 5.x and MSIE 6 will execute the
cell.innerHTML = ...; instruction when it should be only for MSIE 4.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #2
Thanks for all that DU. Its been a while since Ive had to delve into
Javascript so the help is appreciated.

DU <dr*******@hotREMOVEmail.com> wrote in message news:<bh**********@news.eusc.inter.net>...
2- var row = table.insertRow(++f);
Here the new f value is incremented and is now, say, 1 (was 0 before the
incrementation).
var row2 = table.insertRow(f+2);

It looks like you're giving the instruction to insert a row at index 3.
Is that intended?
When I try your file, the Image Caption numbers as output by
input.value = 'Image Caption'+f;
do not follow accordingly,.. so this is most likely the source of your
logical bug in your script.


Yeah I thought this may be my problem. How do I plus one without
plusing one? if you see what I mean. Just temporarily.. so kind of
like:
var n = f (+1);
so f stays the same and the resulting number is used.

Cheers

W
Jul 20 '05 #3
DU
will wrote:
Thanks for all that DU. Its been a while since Ive had to delve into
Javascript so the help is appreciated.

DU <dr*******@hotREMOVEmail.com> wrote in message news:<bh**********@news.eusc.inter.net>...
2- var row = table.insertRow(++f);
Here the new f value is incremented and is now, say, 1 (was 0 before the
incrementation).
var row2 = table.insertRow(f+2);

It looks like you're giving the instruction to insert a row at index 3.
Is that intended?
When I try your file, the Image Caption numbers as output by
input.value = 'Image Caption'+f;
do not follow accordingly,.. so this is most likely the source of your
logical bug in your script.

Yeah I thought this may be my problem. How do I plus one without
plusing one? if you see what I mean. Just temporarily.. so kind of
like:
var n = f (+1);
so f stays the same and the resulting number is used.

Cheers

W

Avoid adding more variables and code into your script. First try to
understand the logical bug in your script. Your problem has nothing to
do with an insertCell difficulty. So do not add more variables.

init() is called twice: as the document loads and as the user clicks the
button: that's a logical bug here.

If "f" is going to be a row iterator, then use it as a global variable
and don't query the table.rows.length at all. So, IMO, the init()
function is useless, not necessary, just makes the code more complex.

When facing logical bugs, you should try to simplify your
program/functions/scripts, not make it more complex.
Use Venkman javascript debugger to monitor watches and local variable
values, otherwise use alert to output values.
So, here, you can safely delete
document.formDisplay.nnum.value = n;
document.formDisplay.fnum.value = f;
and its related html code.

If "f" is going to be a very important variable in your code, then give
it a meaningful, intuitive, self-explanatory identifier. Others
reviewing your code, helping out, or yourself in 3 months from now will
save time trying to figure out the script. I assure you that such simple
basic and sane coding practices save a lot of time and frustrations in
the long run. Tutorials, Netscape DevEdge, MSDN columns all say the same
on this issue and on debugging.

Always make sure your whole html markup is valid and validated in the
first place; use a full doctype declaration. You make your page
compliant, interoperable and you avoid problems of all kinds later. You
eliminate possible sources of differential rendering when you write/test
your script functions.

var input = document.createElement('INPUT');
input.setAttribute('type', 'file');
input.name = 'imageup' + f;
input.onchange = function () { addInput(); };

This above code will create another line when just choosing a file,
while the other code will do the same if clicking the "Select another
file" button: so, you have here a logical bug, a duplication. The
input.onchange = function () { addInput(); };
should be removed entirely.

Drop entirely the setAttribute call in your code: you don't need that
and there is a much better, more reliable way to assign a type to a
input DOM node:
input.setAttribute('type', 'file');
should be
input.type = "file";

I think you can safely drop the entire block testing document.all as I
would be very much surprised if MSIE 4 can embed new additional and
functioning form elements into a form. Since MSIE 5+ supports DOM-1
methods, then you can safely drop the whole block of
if(document.all). Anyway, you should first try to support MSIE 6, NS
7.x, Opera 7.x

action="whatever" is not valid; action="" is ok though.

You should not try to remove the "old" buttons for usability reasons.
The user might want to change his mind.

I did your valid webpage and it works perfectly, impeccably, flawlessly
on Opera 7.11, MSIE 6 for Windows and Mozilla 1.4 and I think it has a
better design than in your original page (it has only 1 "Select another
file" button). I will upload it later.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #4
DU
DU wrote:
will wrote:
Thanks for all that DU. Its been a while since Ive had to delve into
Javascript so the help is appreciated.

[snipped]

I did your valid webpage and it works perfectly, impeccably, flawlessly
on Opera 7.11, MSIE 6 for Windows and Mozilla 1.4 and I think it has a
better design than in your original page (it has only 1 "Select another
file" button). I will upload it later.


Sorry. Kinda forgot about it. Here it is:

http://www10.brinkster.com/doctorunc...nsertCell.html
DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are...
1
by: 3f | last post by:
Hello; We have made a web application that people can download from our web site and installed on: Windows XP Windows 2000 Professional Windows 2003 Server Windows 2000 Server
1
by: putty | last post by:
I found a few posts of people asking about insertCell()/insertRow() not working in IE6 SP2, and a few others about getting "null is null or not an object" errors, but no one posted a solution...
2
by: Howard Jess | last post by:
CLJ -- I've searched the newsgroup and FAQ for info on insertRow(), but didn't see this reported. It seems that Internet Explorer doesn't respond correctly to either insertRow() or...
5
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) -...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
0
by: Sergistm | last post by:
Hello World, :D I have a problem that it is making me crazy, I hope you can help me. I'm trying to execute a .exe file with the Procces.Start, and there is no problem when the file is on my...
1
by: raju78.k | last post by:
Hi, I have a problem with FireFox. I have written a function to Add rows without submiting the form. This function works fine in IE, but not in FireFox. The function is : function...
3
by: manolopm | last post by:
Hi: I've a problem with cells generated by insertCell, I need to add "onclick" event something like this html+='\t<td class='+ClassSelection+' id='+i+'-'+j +'...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.