LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   howto JavaScript take HTML input variable -- continuous (https://www.linuxquestions.org/questions/programming-9/howto-javascript-take-html-input-variable-continuous-4175460745/)

fhleung 05-04-2013 11:59 PM

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~
Code:

<script language="javascript">

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

</script>


<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" />
</form>


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.

awesomeousPrime 05-05-2013 02:50 AM

Hello,
JavaScript does not allow call by reference parameters so you can't do
document.table1.aX
and expect X to represent the value. Instead it represents an element named "aX"

:D

Accept my proposal ;)

fhleung 07-27-2014 07:58 PM

JavaScript can do much job at client side, IF I got a text file AT CLIENT side machine, I mean the file is NOT at web server but at user machine, I would like to open the file by browser WITHOUT network

another JS question, can anyone show me reference link on howto:
open .txt text file in JavaScript please?

dugan 07-27-2014 08:14 PM

Use a FileReader.

https://developer.mozilla.org/en-US/...b_applications

NevemTeve 07-27-2014 11:50 PM

You shouldn't reuse old topics though.

fhleung 08-02-2014 03:47 AM

Assume that having NO networking, NO internet...
Can I using a browser to open/read a file? like .txt file type or any other file type?

Well, I know I can open file(s) by click
File -> open -> browse the file(s) in directory inside harddisk

Answer: following link:
http://stackoverflow.com/questions/1...-in-javascript
http://stackoverflow.com/questions/1...ocal-text-file

fhleung 03-14-2015 09:14 PM

further asking
 
please help if anyone know... JavaScript onclick()

onclick() working on <a href=link></a> tag?

reference: http://www.w3schools.com/jsref/event_onclick.asp

firstfire 03-14-2015 11:19 PM

Sure, it works:
Code:

<html>
    <body>
        <a href="http://google.com" onclick='alert("Hi there"); return false;'>Some link</a>
    </body>
</html>

Quote:

Originally Posted by NevemTeve (Post 5210575)
You shouldn't reuse old topics though.


fhleung 03-16-2015 08:21 PM

thank you for replying, furthermore saying... below the code:

Code:

<script>
function f1()
{
document.getElementById("content").innerHTML =
"<div>JavaScript howTo?</div>" +
"<div>onclick</div>";
}
</script>

<table style="float:center;" border=2>
<tr>
<td style="text-align:center; font-size: 1in; width:3in;  height: 3in"><a href="" onclick="f1();" style="text-decoration:none;">click 1</a></td>
<td style="text-align:center; font-size: 1in; width:3in;  height: 3in"><a href="" onclick="f2();" style="text-decoration:none;">click 2</a></td>
</tr>
</table>

<p id="content">

Please copy and paste the code to .html file, I would like to
onclick text or a href link THEN... popup the content by JavaScript function f1()


thank you and see if above clear?

AnanthaP 03-24-2015 09:01 AM

Something like
Code:

for(ii=0;ii<11;ii++)
{
if (ii < 10) j="X0"+ ii ;
else j="X"+ ii ;
document.write("<Option value=\" + j + \"") ......
}

and so on perhaps.

I have to check it out but I think that j will be successively X01, X02, X03 ... X09, X10 and so on


All times are GMT -5. The time now is 10:49 AM.