HighDots Forums  

Re: firefox not firing onclick

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: firefox not firing onclick in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Michael Winter
 
Posts: n/a

Default Re: firefox not firing onclick - 07-06-2005 , 12:40 PM






On 06/07/2005 17:24, realraven2000 (AT) hotmail (DOT) com wrote:

[snip]

Quote:
script language="JavaScript" type="text/JavaScript"
!--
Drop the language attribute and the SGML comments.

[snip]

Quote:
alert("checked=" + document.frmProdDet("checkbox" + ncount).checked);
A form object is not a function, so calling it will only cause an error.
Use square brackets:

alert('checked=' + document.frmProdDet['checkbox' + ncount].checked);

The same applies later. However, you can go one step further by using
the forms and elements collections, as well as saving a reference to the
form, rather than resolving it more than once:

function chkbuy(ncount) {
var elements = document.forms.frmProdDet.elements;

if(elements['checkbox' + ncount].checked) {
elements['txtQty' + ncount].value = '1';
} else {
elements['txtQty' + ncount].value = '';
}
}

or even better (variables truncated to avoid wrapping):

function chkbuy(n) {
var e = document.forms.frmProdDet.elements;

e['txtQty' + n].value = e['checkbox' + n].checked
? '1'
: '';
}

[snip]

Quote:
input type="checkbox" name="checkbox<%=ncount%>"
onclick=javascript:chkbuy(<%=ncount%>)
That onclick attribute must be quoted. You can also drop the javascript:
prefix unless you're using client-side VBScript elsewhere (in which
case, compatibility with Firefox is rather pointless .

Hope that helps,
Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.


Reply With Quote
  #2  
Old   
realraven2000@hotmail.com
 
Posts: n/a

Default Re: firefox not firing onclick - 07-06-2005 , 02:00 PM






Thanks Mike,

lovely code. Didn't know you could use single quotes for strings as
well. But I like the use of the ? : operator reminds me of the times
when I was still programming C++ (bliss). I liked the suggestion using
'this' as well, but it doesn't quite work as I still would have to
reference the textbox and end up passing two references or ending up
with a mish mash. Not using the form.elements collection, in case its
to oblique for my colleage. But I am a JScript newbie myself wish I
could replace all the serverside VBScript for Java as well, but too
rusty - hence no exercise, no cigar.

This is the final function:

function chkbuy(ncount)
{
document.frmProdDet["txtQty" + ncount].value =
(document.frmProdDet["checkbox" + ncount].checked) ? "1" : "";
}


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.