+ 1

Can some1 help me debug??

i know what the problem is but can 't figure out how to fix it. the problem is the var busreis and a specialy in the document.formulier.txtbusreis .value. the code seems to be correct in comparison to other working code. https://code.sololearn.com/Wn6LRlG2N3V5/?ref=app

23rd Oct 2018, 1:05 PM
B mad
B mad - avatar
9 Réponses
+ 2
* Remove </form> from line 7 * Add the following under the button: </form> <div id="output"></div> * Change the script as follows: function test() { var output_div = document.getElementById("output"); output_div.innerHTML = "Hallo" + "<br />"; var busreis = []; busreis[0] = document.formulier.txtbusreis1.value; busreis[1] = document.formulier.txtbusreis2.value; busreis[2] = document.formulier.txtbusreis3.value; var aantal = busreis.length; var teller = 1; for (var i = 0; i < aantal; i++) { output_div.innerHTML += "busreis " + teller + " = " + busreis[i] + "<br />"; teller++; } } Hth, cmiiw
23rd Oct 2018, 3:09 PM
Ipang
+ 2
You're welcome, well, what I noticed from the code was that you code the button to re-write the document content, using document.write(), the problem with document.write is, it erases everything that was already on the document, that includes your 3 text inputs and the button. Then, just after the content had been erased, you try to read the value of the text inputs, but you couldn't succeed, because they had been erased. That's what I saw through your code. My edit writes the text input values into a div, this is safe, as the document content is intact, only the div's content changes. Hope you understand : )
23rd Oct 2018, 6:19 PM
Ipang
+ 2
I always get error message running that code after I click the button: "Uncaught TypeError: Cannot read property 'txtbusreis1' of undefined. Line: 20" You don't get that error?
23rd Oct 2018, 6:59 PM
Ipang
+ 2
Good for you if it works, I had also suggested to move form closing down if you noticed my first response : )
23rd Oct 2018, 7:15 PM
Ipang
+ 1
thx for the answer, but thats not what i'm looking for. i want to know what goes wrong in my code
23rd Oct 2018, 5:41 PM
B mad
B mad - avatar
+ 1
the problem is that when i change the value after busreis[0] to a value like "text1" and change the other to comments it works
23rd Oct 2018, 6:52 PM
B mad
B mad - avatar
+ 1
no i didn't get an error message. but thx to some1 else we found the problem. the problem was that right after te form opening tag was the closing tag so the form was empty😶😶 after we put the closing form tag on the right place it worked 👏👏👏
23rd Oct 2018, 7:09 PM
B mad
B mad - avatar
+ 1
thx for your time and patience
23rd Oct 2018, 7:10 PM
B mad
B mad - avatar
+ 1
i didn't see it as i was blinded by your beautyfull code 😅😅
23rd Oct 2018, 7:50 PM
B mad
B mad - avatar