473,766 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

firefox not firing onclick

Hi,

my colleague coded the following onclick events with Javascript which
only seem to fire in IE not in firefox. The checkboxes are built in
Form frmProdDet while looping through a recordset (ncount=0..1..2 ..n)
of Stock Items. The idea is to prefill quantity of ordered items with 1
when buy checkbox is checked, and to empty it when cleared. I put in
alert for testing displays in IE fine, not in fx. My guess its a
syntactical problem.

Any idea why this is not firing in firefox?

apart from this the site works well in both MSIE and ff. According to
him it does not have to be Mozilla compatible, but it would be nicer
for me (as I do most of my testing with ff first).

thanks in advance.
Axel

Relevant code:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3.  
  4. <script language="JavaScript" type="text/JavaScript">
  5. <!--
  6. function chkbuy(ncount)
  7. {
  8. //alert
  9. alert("checked=" + document.frmProdDet("checkbox" + ncount).checked);
  10. if (document.frmProdDet("checkbox" + ncount).checked==true)
  11. {
  12. document.frmProdDet("txtQty" + ncount).value="1";
  13. }
  14. else
  15. {
  16. document.frmProdDet("txtQty" + ncount).value="";
  17. }
  18. }
  19. //-->
  20. </script>
  21.  
  22. <form Name="frmProdDet"  Method="post">
  23.  
  24. <table><tr>
  25.  
  26.  
  27. <td width="30"> <div align="left">
  28. <input type="checkbox" name="checkbox<%=ncount%>"
  29. onclick=javascript:chkbuy(<%=ncount%>)>
  30. </div></td>
  31. <td width="31"> <input name="txtQty<%=ncount%>" type="text"
  32. class="bodysmall" size="2">
  33. </td>
  34.  
  35. </table></tr>
  36.  
  37.  
  38. </form>
  39.  
Jul 23 '05 #1
4 17995


re***********@h otmail.com wrote:

alert("checked= " + document.frmPro dDet("checkbox" + ncount).checked );

^^^^^^^^^^^^^^^ ^^^^^
That is a function call, I am sure you get a script error in the Firefox
JavaScript console. If you want to access a property of an object then use
document.frmPro dDet["checkbox" + ncount]

However it appears easier to simply use
<input onclick="chkbuy (this);"
and then in the function you can directly process the input e.g.
function chkbuy (input) {
if (input.checked) {

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
On 06/07/2005 17:24, re***********@h otmail.com wrote:

[snip]
<script language="JavaS cript" type="text/JavaScript">
<!--
Drop the language attribute and the SGML comments.

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

alert('checked= ' + document.frmPro dDet['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.elem ents;

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.elem ents;

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

[snip]
<input type="checkbox" name="checkbox< %=ncount%>"
onclick=Javascr ipt:chkbuy(<%=n count%>)>


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.
Jul 23 '05 #3
Lee
re***********@h otmail.com said:

Hi,

my colleague coded the following onclick events with Javascript which
only seem to fire in IE not in firefox. The checkboxes are built in
Form frmProdDet while looping through a recordset (ncount=0..1..2 ..n)
of Stock Items. The idea is to prefill quantity of ordered items with 1
when buy checkbox is checked, and to empty it when cleared. I put in
alert for testing displays in IE fine, not in fx. My guess its a
syntactical problem.

Any idea why this is not firing in firefox?


The syntax is wrong in a way that IE tolerates.
The references to form elements should be as below.
Also, you don't need the "<!--" and "//-->" comments
and you don't need to compare a Boolean value to true.
<script language="JavaS cript" type="text/JavaScript">
function chkbuy(ncount)
{
//alert
alert("checked= " + document.frmPro dDet.elements["checkbox" + count].checked);
if (document.frmPr odDet.elements["checkbox" + ncount].checked)
{
document.frmPro dDet.elements["txtQty" + ncount].value="1";
}
else
{
document.frmPro dDet.elements["txtQty" + ncount].value="";
}
}
</script>

Jul 23 '05 #4
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.frmPro dDet["txtQty" + ncount].value =
(document.frmPr odDet["checkbox" + ncount].checked) ? "1" : "";
}

Jul 23 '05 #5

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

Similar topics

4
9301
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form action="MaintNotification.php?ReqID=5" method="post" name="frm5"> <tr align="left" bgcolor="#dddddd" class="text" onClick="submit()"
3
3854
by: usenet | last post by:
Hi All, I have some initialization to be done at page load time, which changes the text of some anchors so that they are consistent with the query string (these anchors are used as criteria selectors, and should be initialized to the criteria contained within the url). IE and Safari fire the onload event before rendering any elements, so when the event handler synchronizes the anchors, they are rendered with the right contents...
4
2666
by: the other john | last post by:
I came across a third party script I want to learn how to configure as well as learn more dhtml in the doing. I'm not much of a JS guy yet but I'm working on it. This script works fine in IE6 but is a dead fish in FireFox. There is no support offered on the site where it came from. I'd really appreciate help with this as it will not only to get it working but to learn how it all works so I can add it to my repertoire. Thanks!
2
2824
by: =?Utf-8?B?Uml0YUc=?= | last post by:
I posted this question in the C# discussion group but am posting it here also since ASP is involved. I'm new to C# and need some help regarding an onClick event not firing. I have a data grid that I add a cell to programatically. The cell is a hyperlink and the onClick is set to _doPostBack. In my code I handle the event but when I click on that added hyperlink nothing happens. Here's my code (I'll just show the relevant stuff).
11
1619
by: ft310 | last post by:
Use Internet Explorer go to http://rhodeisland-aa.org/tester/meetings/index.htm On the left click "and go to meetings" Click any address in the right hand 'location' column. The entire page reloads in the frame. (Bad) Perform the same test using Firefox
3
5519
by: Jay | last post by:
I am on the 2.0 framework and have run the c:\windows\microsoft.net \framework\v1.1.4322\aspnet_regiis.exe -c and had no success. About half of the buttons on my webforms are firing and the other half are not, primarily anything on the Master is firing but those in the content pane are not. This was working fine yesterday!! I've reviewed all the code changes and can't seem to find a culprit. Here's one example of what I'm trying to...
9
5567
Basharat
by: Basharat | last post by:
Hi all I have problem on firing "onmouseleave" event of <div> html element. Here is the code im using: <div ID="BSHelpPanel" class="PageMenuMain" onclick="javascript:this.style.display='none';" runat="server" > its working fine in IE while some other events too are not firing in firefox like ondeactivate onfocusout etc.
3
3480
by: sacha4 | last post by:
Hi, I need some help with my onClick event. I realise that there is some problem with the javascript but what exactly it is i am not able to know. <input type="Button" onClick="location = '' + jump.options.value;" value="Go!" /> This is my code for the onClick event. need help ! thanks!
21
13462
by: brucedodds | last post by:
I have an Access 2003 form bound to a SQL Server table via ODBC. Often clicking a button on the form has the effect of requerying the form rather than firing the OnClick event. Does anyone have an explanation? Is this evidence of corruption, or a known side effect? TIA Bruce
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.