This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javascript function isn't returning a value

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Sorry , i forgot to call the function , Modifed cde

 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • 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:

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C is not true

Eric
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic