LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 04-29-2013, 08:51 PM   #1
fhleung
Member
 
Registered: Aug 2004
Distribution: Fedora, Debian
Posts: 354

Rep: Reputation: 30
howto JavaScript take HTML input variable


Please paste following code
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
}
</script>

<form name="table1">
<input name="a1" type="text" />
<input name="b1" type="text" disabled="disabled" value="1"/>
<input onclick="checkinput(1)" type="button" />
<br>
<input name="a2" type="text" />
<input name="b2" type="text" disabled="disabled" value="2"/>
<input onclick="checkinput(2)" type="button" />
</form>
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
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,820

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

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

Value of 'id1':
<script>
document.write(document.getElementById('id1').value);
</script>
 
Old 05-06-2013, 11:55 PM   #3
fhleung
Member
 
Registered: Aug 2004
Distribution: Fedora, Debian
Posts: 354

Original Poster
Rep: Reputation: 30
running JavaScript

Please paste following code

Code:
<script>

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


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


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

</script>
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?
 
  


Reply


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


All times are GMT -5. The time now is 02:59 AM.

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