473,382 Members | 1,313 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,382 software developers and data experts.

problem with the parameter transmission in function

<< Translation in english of my main post >>
Hi,

I do not success to pass by parameter the contents of "param".
in the function "Main" if I replace Suite('+param+') by Suite('+40+')
dans la fonction Main si je remplace Suite('+param+') par Suite('+40+')
then all is ok.
For info, the parameter "param" will be a string

Thanks for your help
Chris

Corresponding code:

function Main(param) {
alert("test "+param); <<<<<<<<<<< Ici tout se passe bien : le contenu de
param est bien affiché
fchaine=''
....
+'<div ><a href="#" onclick="javascript:return Suite('+param+');"><IMG
src="tg.gif" ></a></div>'
....
document.write(fchaine);
}
-----------------------
function Suite(param) {

alert("test "+formulaire); <<<<<<<<<<< Ici rien ne va plus il est ecrit:
test [objet]
return false;
}

Jul 23 '05 #1
7 2419
Chris wrote:
<snip>
For info, the parameter "param" will be a string <snip> +'<div ><a href="#" onclick="javascript:return Suite('+param+');">
<IMG src="tg.gif" ></a></div>'

<snip>

If the value held in - param - is a string then it probably wants to be
quoted within the event handling attribute string. However, when the
string literal used is delimited with single quotes it can only contain
unescaped double quotes. But you are using double quotes to delimit the
HTML attribute values so javascript strings within the HTML attribute
values can only be delimited with shingle quotes. To get around this the
single quotes used to surround - param - in the output need to be
escaped to - \' -

The "javascript:" prefix to the event handling attribute string is
worthless on non-IE browsers and probably redundant on IE. It can be
omitted.
+'<div ><a href="#" onclick="return Suite(\''+param+'\');">'
+'<IMG src="tg.gif" ></a></div>'

Richard.
Jul 23 '05 #2
Thanks for your answer Richard.
+'<div ><a href="#" onclick="return Suite(\''+param+'\');">'
+'<IMG src="tg.gif" ></a></div>'


I tried this solution but I obtain in fonction "Suite"

function Suite(param) {

alert("test "+param); <<<<<<<<<<< Display: test+param+ instead of the
contents of the variable param.
test [objet]
return false;
}

If you have an other idea...

Thanks
Chris.
Jul 23 '05 #3
Chris wrote:
Thanks for your answer Richard.
+'<div ><a href="#" onclick="return Suite(\''+param+'\');">'
+'<IMG src="tg.gif" ></a></div>'


I tried this solution but I obtain in fonction "Suite"

function Suite(param) {

alert("test "+param); <<<<<<<<<<< Display: test+param+ instead
of the contents of the variable param.
test [objet]
return false;
}

If you have an other idea...


I don't need to have other ideas. Based on the information available
that was the correct answer. If it doesn't work then there is something
in the unshown code (or your implementation) that is causing the
problem. No body can debug code they cannot see so you are on your own
until you decide to reveal what you are actually doing.

Richard.
Jul 23 '05 #4
In article <ce*******************@news.demon.co.uk>,
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote:
+'<div ><a href="#" onclick="javascript:return Suite('+param+');">
<IMG src="tg.gif" ></a></div>'


I am not sure what the poster implied by:
return Suite('+param+')

We can assume the OP wants to call Suite. The use of + in this context
is curious. It reminds me of the syntax used in alerts as:
alert("parm = " + parm + ".");

The complete line was:
onclick="javascript:return Suite('+param+');"

This says you want to pass the string "+parma+" to Suite.

The translation does include the words:
parameter the contents of "param"

This says the OP want to pass the variable parma to Suite.

onclick="javascript:return Suite(param);"

To clarify, onclick specifies a character string of javascript code.
What means you use normal javascript syntax in the string. The only
problem is the of quote. The string ends with the second occurrence of
whatever type of quote you started the string.

To pass the variable parma to the function Suite, you need to just do:

onclick="return Suite(param);"

It assume you have declared the global variable param somewhere else as
in:

<script>
var param = 5;
</script>

....

<body>

....

<div ><a href="#" onclick="return Suite(param);">
<IMG src="tg.gif" ></a></div>

....

</body>

The point here is that param has no special meaning in the context of he
<a> tag as this does.

There is also the curious +' at the beginning of the line that may
indicate that the code is coming out of a document.write or something.

Which is why Richard mentioned the escaping, I assume. He assume you
wanted to get the variable when you did the assumed document write.

I assume you know returning false will stop the link.

If this doesn't help, we need more information.

Robert
Jul 23 '05 #5
Robert wrote:
Richard Cornford wrote:
+'<div ><a href="#" onclick="javascript:return Suite('+param+
');"><IMG src="tg.gif" ></a></div>'

I am not sure what the poster implied by:
return Suite('+param+')

We can assume the OP wants to call Suite. The use of + in this
context is curious. It reminds me of the syntax used in alerts as:
alert("parm = " + parm + ".");

The complete line was:
onclick="javascript:return Suite('+param+');"


The plus symbols are for string concatenation and have a single quote
delimited string literal on each side of them.
This says you want to pass the string "+parma+" to Suite.
The plus symbols themselves should not be making it into the constructed
HTML string. That fact that it appears that they are speaks of
misimplementation or errors elsewhere.
The translation does include the words:
parameter the contents of "param"

This says the OP want to pass the variable parma to Suite.

onclick="javascript:return Suite(param);"
The code string appears to be constructed within a function called -
Main - with - param - as its only formal parameter, so - param - will be
out of scope in any resulting event handlers.

<snip> It assume you have declared the global variable
param somewhere else as in:
Me?

<snip> The point here is that param has no special meaning in the
context of he <a> tag as this does.

There is also the curious +' at the beginning of the line
that may indicate that the code is coming out of a
document.write or something.

<snip>

I would have said that it was the - document.write(fchaine); - statement
that implied the use of document.write. ;)

Richard.
Jul 23 '05 #6
In article <ce*******************@news.demon.co.uk>,
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote:
I would have said that it was the - document.write(fchaine); - statement
that implied the use of document.write. ;)

Richard.
I think you were right in your first post. The OP wants to generate the
value of param. Perhaps, param contain a single or double quote. A
quote mark would mess up the syntax.

var param = 5;

document.write('<div ><a href="#" onclick="return Suite(\'' +
param +
'\');"><IMG src="tg.gif"></a></div>');

generate...

<div ><a href="#" onclick="return Suite('5');"<IMG src="tg.gif"></a></div>
but
var parma = "Let's begin.";

gemerate...

<div ><a href="#" onclick="return Suite('Let's begin.');"<IMG src="tg.gif"></a></div>


which would be a problem.

To avoid problems with quoting, try:

document.write('<div ><a href="#" onclick="return Suite(\'' +
escape(param) +
'\');"><IMG src="tg.gif"></a></div>');

I haven't tested this code. Hope the general idea helps.

Robert
Jul 23 '05 #7
Robert wrote:
Richard Cornford wrote: <snip> I think you were right in your first post. The OP wants to generate
the value of param. Perhaps, param contain a single or double quote.
A quote mark would mess up the syntax.
Yes it would, but the symptom of failure in the post responding to my
suggestion was the alerting or "+param+" (with the plus symbols passed
to the - Suite - function in the argument string), which suggests a
different problem (specifically, doing what you think you have seen
instead of what was shown).

<snip> document.write('<div ><a href="#" onclick="return Suite(\'' +
escape(param) +
'\');"><IMG src="tg.gif"></a></div>');

I haven't tested this code. Hope the general idea helps.


Using the - escape - method on the string parameter would call for the
use of - unescape - on the argument received by the function in order to
reverse the process. A String.prototype.replace call that inserted an
escape character before single quotes and replaced double quotes with
their hex escape-sequence value (- \x22 -, or used hex-escapes for both,
single is - \x27 -; as the string literals "\\x22" and "\\x27",
respectively) should avoid the potential problem with quote characters
without the need to convert back.

Using scripts to create strings that are used as HTML which creates new
scripts, is always problematic. It is always difficult to see what is
what at each level (and debugging is a nightmare). It gets even worse
when you add dynamically creating the first script with server-side
scripting to the sequence. It is one of those things that is best
avoided (or minimised) at the design stage as it results in an ongoing
maintenance headache.

Richard.
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Holger Joukl | last post by:
Hi, what version of python are you using? I got the same error when invoking a customized, 2-year-old version of distutils with python 2.3.3 (instead of 1.5.2, as before). Reason is code in...
0
by: Holger Joukl | last post by:
Hi there, I have severe problems running python 1.5.2 (yes I know, but this is a productive environment; cannot switch to py 2.3.3 until later this year...) on several multi-processor sun...
2
by: Holger Joukl | last post by:
Hi, migrating from good old python 1.5.2 to python 2.3, I have a problem running a program that features some threads which execute calls to an extension module. Problem is that all of a sudden,...
0
by: tyousaf | last post by:
Hi i am new to mysql and mysql++, i have installed mysql server, it is running fine. i also installed "mysql++-1.7.9gcc3.2-2.i386.rpm" (i have gcc 3.3) , first of all as the readme file says to do...
17
by: Dave | last post by:
Hi I'm making a 3D Engine which consists of the class C3DEngine. Part of this engine is a file loader, a class called CMeshLoader. I have made an instance of CMeshLoader in C3DEngine, ie...
3
by: Chris | last post by:
function Main(param) { alert("test "+param); <<<<<<<<<<< Ici tout se passe bien : le contenu de param est bien affiché fchaine='' .... +'<div ><a href="#" onclick="javascript:return...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
8
by: Martin Z | last post by:
INSERT INTO dbo.Transmission (TransmissionDate, TransmissionDirection, Filename, TransmittedData) VALUES (@TransmissionDate,@TransmissionDirection,@Filename,@TransmittedData); SELECT @retVal =...
10
by: oktayarslan | last post by:
Hi all; I have a problem when inserting an element to a vector. All I want is reading some data from a file and putting them into a vector. But the program is crashing after pushing a data which...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.