Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Search this Thread
Old 05-04-2013, 11:59 PM   #1
Registered: Aug 2004
Distribution: Fedora, Debian
Posts: 323

Rep: Reputation: 30
howto JavaScript take HTML input variable -- continuous

Please copy & paste the following code (it is SOME text input)

My trouble was cannot take document.table1.aX.value where X is something~
<script language="javascript">

function sum(X)
alert( "sum =  " + (parseInt(document.table1.aX.value)+parseInt(document.table1.bX.value))  ) ;
return true


<form name="table1">
<input name="a1" type="text" /><input name="b1" disabled="disabled" value="1" type="text" /><input onclick="sum(1);" value="a1+b1" type="button" /><br />
<input name="a2" type="text" /><input name="b2" disabled="disabled" value="2" type="text" /><input onclick="sum(2);" value="a2+b2" type="button" /><br />
<input name="a3" type="text" /><input name="b3" disabled="disabled" value="3" type="text" /><input onclick="sum(3);" value="a3+b3" type="button" />

I try to explain the design, each row doing the same thing: SUM of text input.

I would like to have a JavaScript function / module
for MANY rowS.

So the JavaScript function has 1 input parameter to tell which row.

Last edited by fhleung; 05-05-2013 at 12:26 AM.
Old 05-05-2013, 02:50 AM   #2
LQ Newbie
Registered: May 2013
Posts: 1

Rep: Reputation: Disabled
JavaScript does not allow call by reference parameters so you can't do
and expect X to represent the value. Instead it represents an element named "aX"

Accept my proposal


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
howto JavaScript take HTML input variable fhleung Programming 2 05-06-2013 11:55 PM
problem while comparing awk field variable with input variable entered using keyboard vinay007 Programming 12 08-23-2011 12:44 AM
javascript html select sudif Programming 1 04-22-2008 12:18 AM
Javascript & HTML Tux-O-Matic Programming 1 12-07-2006 05:32 PM
Html Javascript help apt Programming 3 03-20-2005 11:46 PM

All times are GMT -5. The time now is 06:03 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration