File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Calling a function from within a value attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Calling a function from within a value attribute" Watch "Calling a function from within a value attribute" New topic
Author

Calling a function from within a value attribute

K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
How do I call a function within the 'value' attribute of an input tag?

e.g.

<input type="text" value="'return myValue()'"/>

This doesn't seem to work. The myValue() function returns a string which should be the input's value. How can it be done?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

You can't do it that way. Rather, put something like the following into an onload handler:


[ December 19, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
dnyan ginde
Ranch Hand

Joined: Jan 17, 2006
Posts: 68
U could also call the javascript function onclick of a button(if u have one on the screen)and populate the value of ur text element in the javascript function.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

dnyan ginde, JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

Please read this for more information.

thanks,
bear
Forum Bartender
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling a function from within a value attribute