D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Some help with javascript & firefox

 

On Tuesday 12 February 2008 23:41, Kevin Lucas wrote:
> >     now I get
> >     parseint is not defined
> >     http://www.minionsbandb.co.uk/oldsplitaddtable.html
> >     Line 106
> >
> >
> > Woops, that's my fault. This is what I get for typing it out instead
> > of cut/pasting it. The function is parseInt()
> > Note, the capital 'I'. It's case sensitive. Check this link for the
> > ins and outs of it:
> > http://www.w3schools.com/jsref/jsref_parseInt.asp
> >
> >
> >     alert("vat_low" + rowNum);
> >     alert("vat_low" + rowNum.value);
> >     <!-- alert (parseint(document.splitfm.vat_low.value)); -->
> >     alert (newTxt2.ID)
Just a couple of notes here:
Every element of a document can have an id attribute. This should be unique 
across the document.
Not every element can have a name attribute. This does not have to be unique: 
you can have as many elements in a form with the same name and their values 
are turned into an array IIRC - as multiple selects would.
eg:
//
<form name='myform' action=....>
<input type='text' name='eric' id='f1'>
<input type='text' name='eric' id='f2'>
</form>
//
I think the Tidy extension for firefox will find and warn of multiple id's.
It might not seem like much but when your writing code its very useful to be 
quite sure what your looking at.
If I go for:
var val=getElementbyId('f1').value;
//I will get what I'm looking for
If I go for:
var val=document.myform.eric.value; 
//This will probably cause an exception as an array does not have a value.

This may not seem like much but as I say - when debugging you have to know 
that what your looking at is what you think it is.
If you add a non-unique id then tidy will tell you.
If you get some code working and then add to it and accidentally add a 
non-unique name then your code will either stop working or misbehave and you 
are likely to spend a lot of time working over the code until you discover 
that the error is a side effect.
I think this may be why most people use id's to resolve things rather than 
names. 
Also id's can be used in style sheets whereas names cant so if you do style as 
well as function that may be of some concern.

On a slightly separate note when debugging I often like to see values as the 
code runs - this can be done by using alert() popups or a debugger both of 
which can be a pain or I've got a bit of a simple frameset and code that 
effectively crates a console debugging window that you can send debugging 
messages to. If anyone thinks they can make use of it then I'll gpl it and 
stick it up so you can 'have a play'.
Tom te tom te tom



-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html