473,327 Members | 2,103 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,327 software developers and data experts.

Param passing issue

Hope someone can help .....

Have a function which creates a HTML HREF

function fLink(aText)
{ return '<a href=javascript:DoLinkSearch("'+aText+'")>'+aText+ '</a>'; }
If the parameter value is "simple" (no spaces), then the function returns
the HTML as expected

However, if the value does contain spaces, the HTML returned is cut off at
the first space

eg

called with FRED returns
javascript:DoLinkSearch("FRED")>FRED</a>'

called with FRED SMITH returns javascript:DoLinkSearch("FRED

which is invalid HTML

Can anyone explain what is happening and how I "fix" the problem

Thanks,

Brian
Feb 3 '06 #1
3 1690
"Brian" <br**********@esc.vic.gov.au> wrote in message
news:dr***********@otis.netspace.net.au...
Hope someone can help .....

Have a function which creates a HTML HREF

function fLink(aText)
{ return '<a href=javascript:DoLinkSearch("'+aText+'")>'+aText+ '</a>'; }
If the parameter value is "simple" (no spaces), then the function returns
the HTML as expected

However, if the value does contain spaces, the HTML returned is cut off at
the first space

eg

called with FRED returns
javascript:DoLinkSearch("FRED")>FRED</a>'

called with FRED SMITH returns javascript:DoLinkSearch("FRED
which is invalid HTML

Can anyone explain what is happening and how I "fix" the problem

Thanks,

Brian


Use escape() as in:

function fLink(aText) {
return '<a
href=javascript:DoLinkSearch("'+escape(aText)+'")> '+aText+'</a>';
}
Feb 3 '06 #2
Brian wrote:
Hope someone can help .....

Have a function which creates a HTML HREF

function fLink(aText)
{ return '<a href=javascript:DoLinkSearch("'+aText+'")>'+aText+ '</a>'; }
If the parameter value is "simple" (no spaces), then the function returns
the HTML as expected

However, if the value does contain spaces, the HTML returned is cut off at
the first space

eg

called with FRED returns
javascript:DoLinkSearch("FRED")>FRED</a>'

called with FRED SMITH returns javascript:DoLinkSearch("FRED

which is invalid HTML
The function will always return invalid HTML regardless of what
parameter you pass it. Error correction by the browser means that
sometimes it works if it's not too broken. Introducing spaces into the
parameter takes it beyond the error correction capabilities of most
browsers and you see the brokenness.

Attribute values (in this case the value of the A element's href
attribute) should be enclosed in quotes:

"In certain cases, authors may specify the value of an attribute
without any quotation marks. The attribute value may only contain
letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45),
periods (ASCII decimal 46), underscores (ASCII decimal 95), and
colons (ASCII decimal 58). We recommend using quotation marks even
when it is possible to eliminate them."

<URL:http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2>

In the example, the inclusion of brackets () and quotes in the attribute
value means that it must have quotes. Single and double quotes have to
be properly nested and quoted:
return '<a href="javascript:DoLinkSearch(\''
+ aText + '\');">' + aText + '</a>';

Which gets really messy - why not use DOM (see below)?

Can anyone explain what is happening and how I "fix" the problem


Explanation above, the suggested 'fix' is just a bandaid.

Using script in the href attribute leads to mysterious behaviour for
some users so put something valid in the href and the script into an
onclick attribute that returns false to stop navigation.

The following will return an A element ready for insertion to your
document based on the same call you have now:

function fLink(aText)
{
var oA;
if (document.createElement && document.createTextNode){
oA = document.createElement('a');
oA.onclick = function (){
DoLinkSearch(aText);
return false;
}
oA.href = '#';
oA.appendChild(document.createTextNode(aText));
}
return oA;
}

In the calling function, make sure an element is returned and if so,
append it somewhere in the document.
--
Rob
Feb 3 '06 #3
On 2006-02-03, Brian <br**********@esc.vic.gov.au> wrote:
Hope someone can help .....

Have a function which creates a HTML HREF

function fLink(aText)
{ return '<a href=javascript:DoLinkSearch("'+aText+'")>'+aText+ '</a>'; }
If the parameter value is "simple" (no spaces), then the function returns
the HTML as expected

However, if the value does contain spaces, the HTML returned is cut off at
the first space

eg

called with FRED returns
javascript:DoLinkSearch("FRED")>FRED</a>'

called with FRED SMITH returns javascript:DoLinkSearch("FRED

which is invalid HTML
both examples are invalid HTML.
Can anyone explain what is happening and how I "fix" the problem


html needs "these quottes" around the whole href value.
also </ in a string is invalid javascript.
function fLink(aText)
{ return '<a href="javascript:DoLinkSearch(\''+aText+'\')">'+aT ext+'<\/a>'; }

--

Bye.
Jasen
Feb 3 '06 #4

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

Similar topics

1
by: Daryl | last post by:
Hello I am using apply-templates and would like to pass a parameter to the template using with-param. Using call-template passes the parameter, but when I use apply-templates, the parameter seems...
12
by: Keith Chadwick | last post by:
I have a fairly hefty XSLT file that for the sake of debugging and clarity I wish to split into some separate sub-templates contained within the same file. The master template calls an...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
0
by: Daimy | last post by:
I meet the same problem below, please help me! Thanks! //written by some one I have developed a windows forms user control, which I am going to host in Internet Explorer.. I am familiar...
8
by: Dennis Myrén | last post by:
I have these tiny classes, implementing an interface through which their method Render ( CosWriter writer ) ; is called. Given a specific context, there are potentially a lot of such objects,...
1
by: Dim | last post by:
Hi i am trying to create a Thread using _beginthread that will access data in a class but i keep getting a C2664: '_beginthread' : cannot convert parameter 1 from 'void (DBLR<T>&)' to 'void (__cdecl...
2
by: VB Programmer | last post by:
I created a VB6 user control with a ActiveX Knob on it. Here's the simple code: Public Property Get Value() As Integer Value = CWKnob.Value End Property Public Property Let Value(Value As...
3
by: Marc Castrechini | last post by:
First off this is a great reference for passing data between the Data Access and Business Layers:...
19
by: Brett Romero | last post by:
Here's a table of data I'm putting into a collection: CodeId CodeGroup CodeSubGroup Type 1 K K.1 Shar1 2 K ...
4
by: Bob Bedford | last post by:
Hi all, I'm stuck with some php code that runs out of time limit. This is due to a long XML file process that has to save pictures on the disk. What I've now: - read XML file - parse XML...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.