View Full Version : passing arguments with spaces
gsanbrook
01-31-2003, 04:21 PM
Ok Javascript pros,
This ought to be easy (I'm not a seasoned js guy yet).
I have this function:
function ShowBom(sVal,x,y,sDB)
{
alert(sVal);
}
I call the function with this value:
onClick=ShowBom ('D151268P01',1,2,'PFMMC')
and it works fine - message is displayed.
IF I call it this way:
onClick=ShowBom('D151 PARTIAL PRT',1,2,'PFMMC')
It won't work.
What is it with the spaces that causes the problem?
Thanks in advance.
head8k
01-31-2003, 04:33 PM
works fine for me :confused: what browser are you getting this error in?
gsanbrook
01-31-2003, 04:37 PM
Internet Explorer 5.1
I have tried this a million different ways and it won't work. Any ideas?
head8k
01-31-2003, 04:42 PM
Have you tried escaping the string?
function ShowBom(sVal,x,y,sDB){
alert(unescape(sVal));
}
<a href="#" onclick="ShowBom(escape('D151 PARTIAL PRT'),1,2,'PFMMC')">test</a>
If this doesn't work can you post your code...
gsanbrook
01-31-2003, 04:52 PM
Thanks, but escape didn't work either. Here is the code:
<script language="JavaScript">
function ShowBom(sVal,x,y,sDB)
{
alert(sVal);
if (sVal != "")
{
frmMain.PN.value = sVal;
frmMain.P.value = window.event.altKey;
frmMain.submit();
}
}
</script>
Section of calling code:
<TD CLASS=TDBOM onClick=ShowBom(' 4.0 MFD 370V'),window.event.clientX,window.event.clientY,'PFMMC') onmouseover="this.style.backgroundColor='#D8F2FC';this.style.fontSize='11pt';this.style.fontWeight='normal';" onmouseout="this.style.backgroundColor='#E9E9E9';this.style.fontSize='8pt';this.style.fontWeight='normal';">200/230-F</TD>
It's inside a table and contained in a form. I have taken out all the complicating factors to try to get it to run, but nothing seems to work. I don't even get an error message in the status bar, just 'nuttin. It does render the style just fine. It simply does nothing when the value contains any spaces, functions perfectly if it doesn't have spaces.
????
Borgtex
01-31-2003, 05:01 PM
does that work?
onClick="ShowBom(' 4.0 MFD 370V',window.event.clientX,window.event.clientY,'PFMMC')"
head8k
01-31-2003, 05:03 PM
Sorry you've got me stumped. Unfortuantely I have to sign off in a minute so can't spend any more time looking at this. Perhaps someone else will jump in?
One thing I'd recommend is that you don't use an onclick handler on a table cell - it won't work in all browsers.
gsanbrook
01-31-2003, 05:11 PM
Well BorgTex, I have been assimilated! I don't know why, but enclosing the function in double-quotes does make it work!!!
Thanks to everyone for the help.
Head8, I am lucky enough to code for a company that standardizes just about everything. 40,000 INTRA-Net users and all on IE 5.x so I get the privledge of ignoring Netscape. I appreciate your looking into this problem also.
Regards,
Gsanbrook
Borgtex
01-31-2003, 05:36 PM
Originally posted by gsanbrook
Well BorgTex, I have been assimilated! I don't know why, but enclosing the function in double-quotes does make it work!!!
I'ts because if you don't enclose it, the HTML interpreter thinks that the function ends at the first space, and the rest is more HTML; in your case, it was trying to execute:
onClick=ShowBom('D151
so that obviously doesn't works.
You know, you only have to obey the rules of the collective... ;)
whammy
01-31-2003, 11:40 PM
Just another reason to code correctly. ;)
http://www.w3schools.com/xhtml
If you follow the rules outlined for xHTML (or even HTML 4), you won't run into problems like this - even if you don't declare a doctype, etc. :)
BrainJar
02-01-2003, 04:59 AM
Just a fair warning: don't get too comfortable with the fact that your users are all on the same browser and version.
There are several differences between IE 5.0 and 5.5 and 6.0. Microsoft has a habit of forcing new versions of IE on you when you upgrade or install other software. I've seen more than one application break because of that.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.