LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 09:51 PM   #1
fhleung
Member
 
Registered: Aug 2004
Distribution: Fedora, Debian
Posts: 355

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-07-2013 at 12:59 AM. Reason: ask again
 
Old 04-30-2013, 12:11 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,946

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
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-07-2013, 12:55 AM   #3
fhleung
Member
 
Registered: Aug 2004
Distribution: Fedora, Debian
Posts: 355

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 01: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 01:44 AM
dump HTML that contains JavaScript? thomasjunier Linux - Software 6 09-08-2008 03:58 PM
javascript html select sudif Programming 1 04-22-2008 01:18 AM
Javascript & HTML Tux-O-Matic Programming 1 12-07-2006 06:32 PM
Html Javascript help apt Programming 3 03-21-2005 12:46 AM


All times are GMT -5. The time now is 07:26 PM.

Main Menu
Advertisement
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