Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > javascript parameter isn't passing

Reply
Thread Tools

javascript parameter isn't passing

 
 
Mary Kline
Guest
Posts: n/a
 
      05-31-2009
hi,

why the parameter cno isn't passing? What wrong in this?
<script type="text/javascript">
function test(cno)
{
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
if (browser=="Netscape")
{
document.write('<strong>Supported Browsers :<\/strong> IE only.');
}
if (browser=="Microsoft Internet Explorer")
{
document.write('<script type="text/javascript" src="http://
dl.tvunetworks.com/webplayer/myTVU.js?c="+cno
+"&amp;w=550&amp;h=385&amp;autoplay=1&amp;style=0" ><\/script>');
}
}
test(1111);
</script>


Any help appreciated.

TIA
-Mary

 
Reply With Quote
 
 
 
 
Eric Bednarz
Guest
Posts: n/a
 
      05-31-2009
Mary Kline <(E-Mail Removed)> writes:

> why the parameter cno isn't passing?


Because you don’t use it. You just write ‘cno’ as part of a longer
string.

> What wrong in this?


> var browser=navigator.appName;


That, for starters.

This probably answers why you want to use document.write to insert the
script element in the first place. Instead of user agent sniffing you
should use conditional comments, e.g.

<!--[if IE]>
<script type="text/javascript" src="[…]"></script>
<![endif]–>

Cf. <http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx>

Another question would be why you want to make that IE-only in the first
place.

 
Reply With Quote
 
 
 
 
kouPhax
Guest
Posts: n/a
 
      06-01-2009
On May 31, 10:19*pm, Eric Bednarz <(E-Mail Removed)> wrote:

> <!--[if IE]>
> <script type="text/javascript" src="[]"></script>
> <![endif]>


Assuming the OP's code above is the actual script she intends to use
then script "written" onto the page has a dynamic URL (built seemingly
from user input - and passed as the argument to the function).
Conditional comments wouldn't actually work in this case.

> Another question would be why you want to make that IE-only in the first
> place.


This is the question that needs answered first I think.

James.

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      06-01-2009
Mary Kline wrote:
> why the parameter cno isn't passing? What wrong in this?
> <script type="text/javascript">
> function test(cno)
> {
> var browser=navigator.appName;
> var b_version=navigator.appVersion;
> var version=parseFloat(b_version);

^^^^^^^
Unused variable.

> if (browser=="Netscape")
> {
> document.write('<strong>Supported Browsers :<\/strong> IE only.');
> }
> if (browser=="Microsoft Internet Explorer")
> {
> document.write('<script type="text/javascript" src="http://
> dl.tvunetworks.com/webplayer/myTVU.js?c="+cno
> +"&amp;w=550&amp;h=385&amp;autoplay=1&amp;style=0" ><\/script>');
> }
> }
> test(1111);
> </script>


Provided there is no script error¹, I see two distinct possibilities:

A) You are using a browser for which

navigator.appName == "Microsoft Internet Explorer"

does not apply. Possibility: Mozilla Firefox.

See also <http://PointedEars.de/scripts/test/whatami>.

B) You are redeclaring test() below. Variable instantiation
takes place before execution.


HTH

PointedEars
___________
¹ <http://www.jibbering.com/faq/#javascriptErrors>
 
Reply With Quote
 
Garrett Smith
Guest
Posts: n/a
 
      06-01-2009
Mary Kline wrote:
> hi,
>
> why the parameter cno isn't passing? What wrong in this?


[...]

I suggest getting rid of that code. Whatever it is intended to do, it is
badly designed. This is evidenced by a question Eric Bednarz raised.

>
>
> Any help appreciated.
>


Learn to ask a smart question. Particularly about describing the goal,
not why the reckless strategy (with unused variables) in the code posted
fails[1].

Read the FAQ section on posting[2].

Also see the FAQ notes on browser detection and what to do instead[3].

[1]http://catb.org/esr/faqs/smart-questions.html#goal
[2]http://jibbering.com/faq/#posting
[3]http://jibbering.com/faq/faq_notes/not_browser_detect.html#bdTop

Garrett
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing parameter to javascript function alf ASP .Net 2 04-01-2011 10:32 AM
Passing parameter to function not expecting parameter Mister B C Programming 8 08-26-2010 08:01 AM
MS VS .NET passing parameter to Javascript renoreno Software 0 08-23-2007 05:10 PM
passing id of an element as a parameter in javascript... soyo Javascript 1 02-07-2006 02:55 PM
passing a parameter to pop up window by javascript how? Bishoy George ASP .Net 8 09-28-2005 12:47 AM



Advertisments