![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
artlover70 (AT) yahoo (DOT) com (Jay) wrote: However, when there is only one entry on the page and when I click on "Delete" or "Edit", I always get the message "No Entry/entries selected" even though I already select that entry ( The form is supposed to be submitted ). You were close to the problem with the commented out alert. When you have only one row, you do not have an array of names, but a single value. Perhaps there is some way of forcing a one element array of names, but I do not know it. snip |
#2
| |||||
| |||||
|
|
function isChecked( form, name ) { var g = form.elements[name]; if (g.length==null) { |
|
if(g.checked) return true; |
|
} else { for(var i=0; i<g.length; ++i ) { |
|
if(g[i].checked) return true; |
|
} } return false; } |
#3
| |||
| |||
|
|
mscir wrote: [snip] function isChecked( form, name ) { var g = form.elements[name]; if (g.length==null) { Comparing to undefined or null is a bad idea. For one, undefined, as a keyword, isn't recognised by all engines. Secondly, comparing to null is misleading as your actually comparing to undefined. Instead, do if( !g.length ) { This would evaluate true if length is undefined or zero. As it can never be zero, it'll do nicely. if(g.checked) return true; Or return g.checked; } else { for(var i=0; i<g.length; ++i ) { for( var i = 0, n = g.length; i < n; ++i ) { is faster. Actually, declaring 'n' along with 'g' at the start of the function, then writing if( !( n = g.length )) { and for( var i = 0; i < n; ++i ) { involves the fewest lookups. if(g[i].checked) return true; I'd recommend keeping a uniform coding style and always include braces. } } return false; } Mike |
![]() |
| Thread Tools | |
| Display Modes | |
| |