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");
}
7 1986
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.
Thanks, but the correct case of the onClick event is "onClick"
The error I am receiving is --- Error: Expected ')'
This -
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>';
-
Needs To Be -
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>";
-
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.
Because this one -
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>';
-
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.
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.
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 :)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
| |