• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Javascript function isn't returning a value

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

Could anybody please tell me , why this javascript code isn't working .

I am passing a value to a function and expecting a return type from that function .
But nothing is being printed

Please see this code and suggest

Passing a vlue to a function and expecting some appended data to it ,but its not happening here .

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry , i forgot to call the function , Modifed cde

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a) Where are you returning value?
b) name is global, why are you passing it as an argument, although you can
c) use script tag within HEAD.
d) why new one(name)?

Try this:

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C is not true

Eric
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Kiran Va wrote:Hi ,

Could anybody please tell me , why this javascript code isn't working .

I am passing a value to a function and expecting a return type from that function .
But nothing is being printed

Please see this code and suggest

Passing a vlue to a function and expecting some appended data to it ,but its not happening here .



Where are you calling this function?
 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:C is not true



Beg your pardon, but 'not true' is not true as code I pasted works!!
There is one mistake though, change
<script language="text/javascript">
to
<script type="text/javascript">

Writing Javascript code within body tag may be useful in some circumstances but not recommended or required in general.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Varun Chopra wrote:

Eric Pascarello wrote:C is not true



Beg your pardon, but 'not true' is not true as code I pasted works!!



The script is not required to be in the head, so it is not true.

Eric
 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:

The script is not required to be in the head, so it is not true.

Eric



I did not say it is required, I recommended it. Everything is not always required, somethings are just better to follow.
 
reply
    Bookmark Topic Watch Topic
  • New Topic