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");
}
7 2016
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 ')'
iam_clint 1,208
Recognized Expert Top Contributor
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="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.
iam_clint 1,208
Recognized Expert Top Contributor
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.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.
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.
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 :)
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 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...
|
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,...
|
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:
|
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 )
{
|
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/');"> </div></div>
| |
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...
|
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
|
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...
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
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...
| |