Skip to content Skip to sidebar Skip to footer

Why Am I Getting This Javascript Error "connection Is Not Defined"?

I'm not sure why I'm getting this error: connection is not defined document.getElementById('flashTest').sendValFromHtml(connection.value); This is my code: function submitCheck

Solution 1:

First, store the form as a local variable:

var form = document.getElementById("formTest");

Then use this local variable instead of querying the DOM multiple times:

var hasConnection = form.connection.value.length != 0; 
var hasLocation = form.location.value.length != 0;

Lastly, prefix connection with form.:

document.getElementById("flashTest").sendValFromHtml(form.connection.value);

Solution 2:

Replace:

var hasConnection = document.getElementById("formTest").connection.value.length != 0; 
var hasLocation = document.getElementById("formTest").location.value.length != 0;

with:

var hasConnection = document.getElementById("connection").value.length != 0; 
var hasLocation = document.getElementById("location").value.length != 0;

Solution 3:

Change connection.value to:

document.forms.formTest.connection.value

Post a Comment for "Why Am I Getting This Javascript Error "connection Is Not Defined"?"