473,473 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem while dynamically passing params to javascript functions.

10 New Member
Hi,

I am using the following javascript method inside a js file.

function createDivRow(label,text) {

var formedTd = '<tr><td>' + label + '</td><td> <a href="#" onclick="javascript:eventHandlerFunction("'+text+' ")">'+text+'</a></td></tr>';
return formedTd;
}

But it's throwing syntax error.
I have tried the following way also.

function createDivRow(label,text) {

var formedTd = '<tr><td>' + label + '</td><td> <a href="#" onclick="javascript:eventHandlerFunction('+text+') ">'+text+'</a></td></tr>';
return formedTd;
}

this version throwing ')' expected and also, the value of text which i am passing dynamically is undefined.

I am not able to call the eventHandlerFunction() by passing the dynamic value of the 'text' .

I am using IE6. can any one help me....
Jun 12 '07 #1
6 2008
gits
5,390 Recognized Expert Moderator Expert
hi ...

try this:

Expand|Select|Wrap|Line Numbers
  1. var formedTd = '<tr><td>' 
  2.     + label 
  3.     + '</td><td> <a href="#" onclick="javascript:eventHandlerFunction("'
  4.     + text 
  5.     + '")">'     
  6.     + text
  7.     + '</a></td></tr>';
  8.  
the problem should be your linebreak before 'onclick'

kind regards ...
Jun 12 '07 #2
haijdp
10 New Member
hi ...

try this:

Expand|Select|Wrap|Line Numbers
  1. var formedTd = '<tr><td>' 
  2.     + label 
  3.     + '</td><td> <a href="#" onclick="javascript:eventHandlerFunction("'
  4.     + text 
  5.     + '")">'     
  6.     + text
  7.     + '</a></td></tr>';
  8.  
the problem should be your linebreak before 'onclick'

kind regards ...
Hi...
Thanks for your reply. I am still getting the syntax error...:(
Jun 12 '07 #3
gits
5,390 Recognized Expert Moderator Expert
... when trying this in FF & IE it works for me ...

[HTML]<body>
<script>
var label = 'test';
var text = 'test1';

var formedTd = '<tr><td>'
+ label
+ '</td><td> <a href="#" onclick="javascript:eventHandlerFunction("'
+ text
+ '")">'
+ text
+ '</a></td></tr>';

alert(formedTd);
</script>
</body>
[/HTML]

please post your code that is not working ...

kind regards ...
Jun 12 '07 #4
gits
5,390 Recognized Expert Moderator Expert
ahhhhhhhhhh ... got your problem ... you put the formedTd-string in an HTML-page and you want the function called ... ;) of course ...

you must escape the quotes and single quotes of course ... sorry that i forgot it ... use the following:

Expand|Select|Wrap|Line Numbers
  1.       var formedTd = '<tr><td>'
  2.           + label
  3.           + '</td><td> <a href="#" onclick="javascript:eventHandlerFunction(\''
  4.           + text
  5.           + '\')">'     
  6.           + text
  7.           + '</a></td></tr>';
  8.  
but note ... that assumes that text is a string passed to your eventHandlerFunction ... otherwise you should delete the both escaped quotes

kind regards
Jun 12 '07 #5
haijdp
10 New Member
ahhhhhhhhhh ... got your problem ... you put the formedTd-string in an HTML-page and you want the function called ... ;) of course ...

you must escape the quotes and single quotes of course ... sorry that i forgot it ... use the following:

Expand|Select|Wrap|Line Numbers
  1.       var formedTd = '<tr><td>'
  2.           + label
  3.           + '</td><td> <a href="#" onclick="javascript:eventHandlerFunction(\''
  4.           + text
  5.           + '\')">'     
  6.           + text
  7.           + '</a></td></tr>';
  8.  
but note ... that assumes that text is a string passed to your eventHandlerFunction ... otherwise you should delete the both escaped quotes

kind regards
yeah...,with the single quote escapes, it's working now...
Thanks a lot for your help.I tried different ways of calling that function with the dynamic value of 'text'.But nothing helped me. I am really thankful to you...:)
Jun 13 '07 #6
gits
5,390 Recognized Expert Moderator Expert
glad to help you ... come back when you have more questions ... ;)

kind regards ...
Jun 13 '07 #7

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

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
2
by: Holger Butschek | last post by:
Hi folks, first of all, I'm absolutly new to javascript. I have designed a html-form and am trying to path parameters with the suffix of i.e. ?Seminartitel=hallowelt in the url. In the head...
5
by: danny.myint | last post by:
I was under the assumption that javascript loads all the <head></head> elements before processing the <body> tag in Mozilla/Netscape/Firefox. It doesn't seem like it, with my problem. I have...
4
by: 63q2o4i02 | last post by:
Hi, I'm writing a hand-written recursive decent parser for SPICE syntax parsing. In one case I have one function that handles a bunch of similar cases (you pass the name and the number of...
1
by: johnjsforum | last post by:
Buddies, I have a web page to create HTML buttons dynamically as in the “formDivColorPicker” function ////////////////////////////////////////////////////////////////////////////////////...
3
by: modermo | last post by:
Hey new to javascript figuring out how to fix this darn problem. I employ an image rollover, and it works beautifully in safari. But in firefox, the image has an annoying blue border around...
7
xNephilimx
by: xNephilimx | last post by:
lHi guys! I'm having a little problem that's getting on my nerves, I couldn't find a solution, I also tryed googling it and I found nothing... (my field of expertise is in AS 2 and 3, but I still...
3
by: q-rious | last post by:
Hello All, 1. I would like to pass some variables (x and y below) from Javascript to PHP, process them in PHP, and return some other variables (a abd b) back to Javascript. --(x,y)--...
1
by: avpkills2002 | last post by:
I seem to be getting this weird problem in Internet explorer. I have written a code for parsing a XML file and displaying the output. The code works perfectly fine with ffx(Firefox).However is not...
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...
1
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...
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,...
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.