How can i put my form value in javascript array

Posted by Lucas van den Abbeele on Stack Overflow See other posts from Stack Overflow or by Lucas van den Abbeele
Published on 2013-11-09T15:41:53Z Indexed on 2013/11/09 15:53 UTC
Read the original article Hit count: 221

Filed under:
|
|

I want to make a script where i can put my form in the javascript array invoer[] and display the total

It constantly stops working and i searched a lot, i really can't find the right way :D

This is my javascript code

var strijk = ['broek', 'hemd', 'tshirt', 'lakens', 'korte broek', 'babykledij'];
var minuten = [5, 10, 5, 6, 3, 3];

function invoerstrijk() {
    document.write("<form action='' method='get' name='strijkform'>");
    for (var a = 0; a < minuten.length; a++) {
        document.write(strijk[a] + "<input id='" + strijk[a] + "' name ='" + strijk[a] + "' type='text' />" + "<BR>");
    }

    document.write("<button onclick='opgeven()'>opgeven</button>");
    document.write("</form>");
}

function opgeven() {
    var invoer = [];
    for (var a = 0; a < minuten.length; a++) {
        invoer[a] = document.getElementByI(strijk[a]).value;
    }

    var totaal;
    for (var a = 0; a < minuten.length; a++) {
        totaal += parseint(invoer[a]) * parseint(minuten[a]);
    }
    document.write("<input name=" + strijk[a] + " type='text' value=" + invoer[a] + " readonly />");
    if (invoer != []) {
        document.write("totaal aantal minuten" + totaal);
    } else {
        document.write("geen invoer");
    }
}

my html looks likes this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<script type="text/javascript" >
//my javasccript
</script>

<button id="B1" onclick="invoerstrijk()" >Nieuwe strijk</button>
</body>
</html>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about arrays