insertCell problems

W

will

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. :)
 
D

DU

will said:
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-HTML/html.html#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-HTML/html.html#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/doctorunclear/Netscape7/Netscape7Section.html
 
W

will

Thanks for all that DU. Its been a while since Ive had to delve into
Javascript so the help is appreciated.

DU said:
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
 
D

DU

will said:
Thanks for all that DU. Its been a while since Ive had to delve into
Javascript so the help is appreciated.




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/doctorunclear/Netscape7/Netscape7Section.html
 
D

DU

DU said:
will said:
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/doctorunclear/HTMLJavascriptCSS/InsertCell.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/doctorunclear/Netscape7/Netscape7Section.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top