473,699 Members | 2,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple onClick problem

5 New Member
I have done this function before and I cannot figure out why it is not working. I am receiving the results of an xmlhttp call and I am looping through the values I am creating links with an OnClick. I created a simple function with just an alert, but the link is not kicking off the function. I have several examples of the same process working on different pages. I must be missing something simple.

This is the code from the relavent section:
The issue is with the onClick of the Anchor Tag.

var D = new ActiveXObject(" Microsoft.XMLDO M");
D.async=false;
D.loadXML(xml);
supplierquery.i nnerHTML='';
var s='';
s=s+'</b><Table class="pnumbloc k" Style="Backgrou nd-Color:#f5f5f5;b order:1px solid black" cellpadding=0px cellspacing=0px width=100%>';

for(var i=0;i<D.childNo des[0].childNodes.len gth;i++) {
var e = D.childNodes[0].childNodes[i];
var getVnd = e.getAttribute( 'xSUPP');

s = s + '<tr valign=top><td Style="border-bottom:1px solid black">
<A HREF="#" onClick="setVnd ('+getVnd+')" class="pnum"> '+e.getAttribut e('xSUPP')+' </A></td></tr>';
}
s = s + '</table>';
supplierquery.i nnerHTML = s;

}
}

function setVnd(v) {
alert("got here");
}
Apr 27 '07 #1
7 2016
drhowarddrfine
7,435 Recognized Expert Expert
I'm not a javascript guy but I believe, with xhtml or xml, OnClick needs to be lower case because there it's case sensitive.
Apr 27 '07 #2
WSPL5
5 New Member
Thanks, but the correct case of the onClick event is "onClick"
The error I am receiving is --- Error: Expected ')'
Apr 27 '07 #3
iam_clint
1,208 Recognized Expert Top Contributor
This
Expand|Select|Wrap|Line Numbers
  1. s = s + '<tr valign=top><td Style="border-bottom:1px solid black">
  2. <A HREF="#" onClick="setVnd('+getVnd+')" class="pnum"> '+e.getAttribute('xSUPP')+' </A></td></tr>';
  3.  
Needs To Be

Expand|Select|Wrap|Line Numbers
  1. s = s + "<tr valign=top><td Style=\"border-bottom:1px solid black\"><A HREF=\"#\" onClick=\"setVnd('"+getVnd+"');\" class=\"pnum\"> "+e.getAttribute('xSUPP')+" </A></td></tr>";
  2.  
Apr 27 '07 #4
WSPL5
5 New Member
Thanks a million, that fixed the problem. I guess I was concentrating on the onClick and did not take into account the rest of the string. The wierd thing is that I have a very similar string in another function that works fine:

Code that works:
s = s + '<tr valign=top><td width=20 Style="Backgrou nd-color:#fff;bord er:1px solid gray"><A HREF="#" onClick="delMRB ('+getMRBID+')" ><img src="/icons/actn011.gif" border=0></A></td><td width=250 Style="Backgrou nd-color:#fff;bord er:1px solid gray"><A HREF="#" onClick="setMRB ('+e.getAttribu te('xPNUM3')+' )"> '+e.getAttribut e('xPNUM')+' </A></td><td width=250 Style="Backgrou nd-color:#fff;bord er:1px solid gray"> '+e.getAttribut e('xPNUM1')+'</td><td Style="Backgrou nd-color:#fff;bord er:1px solid gray"> '+e.getAttribut e('xPNUM2')+'</td></tr>';

Do you know why this works and the one you fixed didn't? I probably spend more time debugging string issues than anything else in javascript.

Thanks for the help.
Apr 27 '07 #5
iam_clint
1,208 Recognized Expert Top Contributor
Because this one
Expand|Select|Wrap|Line Numbers
  1. s = s + '<tr valign=top><td width=20 Style="Background-color:#fff;border:1px solid gray"><A HREF="#" onClick="delMRB('+getMRBID+')"><img src="/icons/actn011.gif" border=0></A></td><td width=250 Style="Background-color:#fff;border:1px solid gray"><A HREF="#" onClick="setMRB('+e.getAttribute('xPNUM3')+' )"> '+e.getAttribute('xPNUM')+' </A></td><td width=250 Style="Background-color:#fff;border:1px solid gray"> '+e.getAttribute('xPNUM1')+'</td><td Style="Background-color:#fff;border:1px solid gray"> '+e.getAttribute('xPNUM2')+'</td></tr>';
  2.  
Doesn't have syntax errors
This ones syntax error is here
s = s + '<tr valign=top><td Style="border-bottom:1px solid black">
<A HREF="#" onClick="setVnd ("'+getVnd+'")" class="pnum"> '+e.getAttribut e('xSUPP')+' </A></td></tr>';

the bold underlined text is all that really needed to be changed but i didn't like the string at all that way so i made it cleaner after i found your error.
Apr 27 '07 #6
drhowarddrfine
7,435 Recognized Expert Expert
Thanks, but the correct case of the onClick event is "onClick"
I should have known better but, no, the correct case is 'onclick'. I forgot onclick is an HTML attribute and not javascript. While HTML doesn't care about case, Xhtml and XML do. Therefore, you should always use lowercase.
Apr 27 '07 #7
pbmods
5,821 Recognized Expert Expert
Why are you using InnerHTML? Why not just create a template node and then clone it?

Would save you a lot of headaches, especially in the keeping-track-of-quotes department :)
Apr 28 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1464
by: not | last post by:
Hello All, I am trying to develop a relatively simple self-quiz form in javascript, but I'm having no luck getting it to work. What I am looking for is a script that allow the user to select one of three answers for each question, and automatically assign a value to their answer ("never"=0, "sometimes"=1, "always"=2). There would be anywhere from ten to thirty questions. I want the script to calculate the running total, and then...
13
1718
by: lost hope | last post by:
hi, i have a very simple html page with a global variable, a function to increment its value, and a form that calls the function. however, what happens is that every time i click the image, the page is reloaded, and the value is reset to 1. is this what i should be expecting? are global variables not persistent across reloads? if this is the case, how can i set it up so that clicking the button doesn't reload the page automatically,...
9
2117
by: Astra | last post by:
Hi everybody Wonder if you could help me out. I created a simple JavaScript routine to enable a user to click backwards and forwards between small news articles. This routine works fine in IE and Safari, but in the latest FireFox I get no title or article, but do see the prev and next links and the article number. My HTML and JS simple routine is as follows:
3
1642
by: Marc Llenas | last post by:
Hi there, I'm stuck on a validation function for a form and I cannot figure out what the problem is. The page is in ASP. Any ideas? The function being called is: <script language="JavaScript" type="text/javascript"> function checkform ( form ) {
10
67757
by: Eric-Sebastien Lachance | last post by:
Hey there, I decided to just create a 100% height and width div that filled the space over a background header image, and add an onclick event to redirect to the my index... Doesn't seem to work in FireFox only, just in IE. Here's the code: <div id="headerimg"><div style="width: 100%; height: 100%; cursor: hand; cursor: pointer;" onclick="top.location.href('http://www.monamouchtim.com/');">&nbsp;</div></div>
0
1886
by: 42 | last post by:
I implemented a simple class inherited from Page to create a page template. It simply wraps some trivial html around the inherited page, and puts the inherited page into a form. The problem I have run into is that the emitted html at the end of the process is slightly different and doesn't work. Please don't be put off by all the source code. All the guts are in this first base class, and it doesn't do much. The rest is trivial...
24
6330
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to have on his site, a Javascript Calculator for working out the cost of what they want, for example: 1 widget and 2 widglets = £5.00
2
1958
by: stevemtno | last post by:
I've got a problem with a web page I'm working on. I have 4 modules - one of them has 2 tabs, two of them have 4 tabs. When the user clicks on the tabs, the content below them changes. However, when the user clicks on the tab (any tab), the browser goes back to the top of the page (I'm assuming it's refreshing, I'm not sure). I'm attaching the JS code below, along with the 2-tab version of the module and its accompanying CSS. Any help will be...
0
8691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9038
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...
1
8920
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8887
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
4378
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
4633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3060
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
3
2012
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.