473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Simple onClick problem

5
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.XMLDOM");
D.async=false;
D.loadXML(xml);
supplierquery.innerHTML='';
var s='';
s=s+'</b><Table class="pnumblock" Style="Background-Color:#f5f5f5;border:1px solid black" cellpadding=0px cellspacing=0px width=100%>';

for(var i=0;i<D.childNodes[0].childNodes.length;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.getAttribute('xSUPP')+' </A></td></tr>';
}
s = s + '</table>';
supplierquery.innerHTML = s;

}
}

function setVnd(v) {
alert("got here");
}
Apr 27 '07 #1
7 1986
drhowarddrfine
7,435 Expert 4TB
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
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 Expert 1GB
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
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="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>';

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 Expert 1GB
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.getAttribute('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 Expert 4TB
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 Expert 4TB
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
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...
13
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...
9
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...
3
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...
10
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...
0
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...
24
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...
2
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
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,...

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.