Closed Thread Icon

Topic awaiting preservation: How to access to the value of form inside of JS??? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8691" title="Pages that link to Topic awaiting preservation: How to access to the value of form inside of JS??? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: How to access to the value of form inside of JS??? <span class="small">(Page 1 of 1)</span>\

 
Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 06-05-2003 04:07

Hi, guys. How are you?
I am coding JavaScript since this morning. Better than yesterday.
Some of them are working fine. It makes me feel good.

Well, I have got an very important question, anyway. Here is my mission:

quote:
User can input how many marks they have. Then input text box appers according to the user input number. JS add all marks up then show the avarage of marks.



I succeed showing input box according to user input data. Please see here

And code is:

code:
<html>
<head>
</head>
<body>

<form name="theForm">
<p>How many mark do you have?
<input type="text" name="num" onBlur="cal()">
</p>
</form>

<script type="text/javascript">
function cal(){
var max = document.theForm.num.value;
for(i=1; i<=max; i++){
document.write("Enter the mark" + i + ": ");
document.write('<input type="text" name="mark">');
document.write("<br />");
}
}
</script>

</body>
</html>



But from this point, I am confused how to add each mark. Do you know what I mean? This cal fanction loop up to max times. User input mark into text box. But what I am wondering is how to access to those input data???! Would you know any tips? Any help will be great.


Hiroki Kozai

rickindy
Nervous Wreck (II) Inmate

From: Indianapolis, In USA
Insane since: Jan 2002

posted posted 06-05-2003 13:38

Just a guess, but I would think that when you reworte the document to show the imark input boxes, you wouild have to include all those within a new form and then have another function you would call when the form is submitted.
For example, at the start of the write loop in your cal function, wirte a form tag with a new form name and at the end have a submit (or some other) button that calls a different function to evaluate what the user has entered. You can access those values using newformName.inputName[i].value. The input boxes on the new form will all have the same name, so you will need to find out how many of them there are by getting the length of the array of the form boxes.
For example, if the input boxes in the new form are called "marks", you can find out how many of them there are with newformName.marks.length and then looping through that array.
I haven't actually tried to do this, but it should work.
Maybe some of the real gurus can chime in here.


Few problems in life can't be solved by chocolate

quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 06-05-2003 21:12

A much easier way to do this would be to use the prompt function:

code:
var mark = prompt('Enter the value of mark number' + i);


Then add this to a running total.

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 06-05-2003 23:24

Hi, rickindy. Hi, quisja.
Many many thanks for your reply.
I was wondering if my English made sense to you or not.
I am pleased to hear from you, guys.
And Many thanks again for your advices.
I will try around.
Cya.

Hiroki Kozai

« BackwardsOnwards »

Show Forum Drop Down Menu