Help answer threads with 0 replies.
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 04-29-2013, 08:51 PM   #1
Registered: Aug 2004
Distribution: Lubuntu Live OS
Posts: 432

Rep: Reputation: 30
howto JavaScript take HTML input variable

Please paste following code
<script language="javascript">
function checkinput(X)
var a = "a" + X ;
alert( "answer = " + (parseInt(document.table1.elements[a].value)+parseInt(document.table1['b'+X].value))  ) ;
return true

<form name="table1">
<input name="a1" type="text" />
<input name="b1" type="text" disabled="disabled" value="1"/>
<input onclick="checkinput(1)" type="button" />
<input name="a2" type="text" />
<input name="b2" type="text" disabled="disabled" value="2"/>
<input onclick="checkinput(2)" type="button" />
I like to take HTML input variable a ,
but variable a was string type,
I want to do calculation...

ANSWER: parseInt()

Last edited by fhleung; 05-06-2013 at 11:59 PM. Reason: ask again
Old 04-29-2013, 11:11 PM   #2
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,235

Rep: Reputation: 979Reputation: 979Reputation: 979Reputation: 979Reputation: 979Reputation: 979Reputation: 979Reputation: 979
Or try this (table/tr/td has nothing to do with this, so I leave it out):

<input type=text id='id1' value='Value1'>

Value of 'id1':
Old 05-06-2013, 11:55 PM   #3
Registered: Aug 2004
Distribution: Lubuntu Live OS
Posts: 432

Original Poster
Rep: Reputation: 30
running JavaScript

Please paste following code


function add1() {
var x = x+1;
document.write('answer = ' + x);

function minus1() {
var y = y+1;
document.write('answer = ' , y);

document.write('<input onclick="add1();" value="+1" type="button"><br>');
document.write('<input onclick="minus1();" value="-1" type="button"><br>');

buttons disappearing after onclick

I'd like to keep running a JavaScript code,
in the same html page

but now was, when button onclick, it show "answer = "

Please help if the above code OK?

Last edited by fhleung; 05-07-2013 at 12:20 AM. Reason: Please help if the above code OK?


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
problem while comparing awk field variable with input variable entered using keyboard vinay007 Programming 12 08-23-2011 12:44 AM
dump HTML that contains JavaScript? thomasjunier Linux - Software 6 09-08-2008 02:58 PM
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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:30 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration