This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes HTML, CSS and JavaScript and the fly likes How to pass data of text field to javascript function? 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 "How to pass data of text field to javascript function?" Watch "How to pass data of text field to javascript function?" New topic
Author

How to pass data of text field to javascript function?

Dipti Lokhande
Greenhorn

Joined: May 05, 2007
Posts: 9
How to pass data of one field on the event of other field to javascript function?

The code is given below :

function calculate(data1,data2)
{
var total = data1 * data2;
document.form.txtTotal.value = total;
}
:
:
:
<%
int i = 0;
while (i < 3)
{
%>
No1 : < input type = "text" name = "txtNo1"> <br>
No2 : < input type = "text" name = "txtNo1"> <br>
Total : < input type = "text" name = "txtTotal" onFocus = "calculate(data of txtNo1, data of txtNo2)"> <br>
<%
}
%>

I want to send value of txtNo1 & txtNo2 on onFocus event of txtTotal.
In the fucntion calculate(), I can not access their values of txtNo1 and txtNo2 directly by using docuement.form.......
How to achieve this?
[ May 09, 2008: Message edited by: Dipti Lokhande ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61086
    
  66

Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Soundar Sweet
Ranch Hand

Joined: Dec 17, 2004
Posts: 31
Try


Soundar
 
Consider Paul's rocket mass heater.
 
subject: How to pass data of text field to javascript function?