Click here to Skip to main content
14,392,749 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,
I need to retrieve all text boxes values of a form and store them in var.

i am only succeeding with the below getting the first value

var plate_length = document.getElementById("plate_length").value;

var plate_width = document.getElementById("plate_width").value;


What I have tried:

function generate()
         {

var plate_length = document.getElementById("plate_length").value;

var plate_width = document.getElementById("plate_width").value;
   }

<form>

<tr>
<td style="color:#660000"><label>Width:</label></td>
<td style="color:#660000"><input type="number" min="0.1" step="0.1" name="plate_width" id="plate_width"></td>
<td style="color:#660000">meters.</td>
</tr>

<tr>
<td style="color:#660000"><label>Length:</label></td>
<td style="color:#660000"><input type="number" min="0.1" step="0.1" name="plate_length" id="plate_length"></td>
<td style="color:#660000"> meters.</td>
</tr>
Posted
Updated 29-Mar-17 13:22pm
v2
Comments
F-ES Sitecore 29-Mar-17 8:30am
   
What's wrong with what you've got so far?
Bryian Tan 29-Mar-17 9:22am
   
something like this?
var allTextBoxValue = plate_length +','+plate_width;
Member 13092275 29-Mar-17 9:40am
   
Actually I have 17 input boxes. I need to store each inbox value to a var.
How can i assign each value to a var?
Member 13092275 29-Mar-17 9:43am
   
I am only able to store the first inbox value. Other inbox value are not beimg parsed
Bryian Tan 29-Mar-17 9:55am
   
all textbox value into a variable? in comma separated?
Member 13092275 29-Mar-17 9:56am
   
No each in a variable.
Var1 = value of text box 1
Var2 = value of text box 2
.
.
.
Bryian Tan 29-Mar-17 10:06am
   
then what wrong with what you have so far?
var plate_length = document.getElementById("plate_length").value;
var plate_width = document.getElementById("plate_width").value;
var whatEver = document.getElementById("plate_whatEver").value;
...
Member 13092275 29-Mar-17 10:07am
   
I am only gettimg the value of the first var. Others are not being parsed.
Got a clue?
Bryian Tan 29-Mar-17 10:16am
   
I don't see anything wrong. https://jsfiddle.net/945vnbn5/
Karthik_Mahalingam 29-Mar-17 23:26pm
   
post the mark up for 17 textbox

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Quote:
i am only succeeding with the below getting the first value

Use the deb console in browser to check for possible errors.
Use the debugger to see what works and what don't.
What happen if you swap both lines ?

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100