Tye Lucas Tye Lucas - 1 year ago 150
Javascript Question

Unable to get property 'value' of undefined or null reference from dynamic inputs on modal

My modal opens and gets values from an AJAX call that is working perfectly, but then I wish to send those values back to another AJAX call when SUBMIT button is pressed, but when I try to get the values from the modal inputs I am getting:
Unable to get property 'value' of undefined or null reference

My button HTML:

<button type="button" name="edit" class="btn btn-primary" id="user-submit" data-dismiss="modal">Submit</button>

My script:

$('#user-submit').on('click', function () {

var userID = document.getElementById(userID).value;
var dbpassword = document.getElementById(dbpassword).value;
var firstname = document.getElementById(firstname).value;
var lastname = document.getElementById(lastname).value;
var email = document.getElementById(email).value;
var phone = document.getElementById(phone).value;
var username = document.getElementById(username).value;
var password = document.getElementById(password).value;
var role = document.getElementById(role).value;

url: 'includes/updateuser.php',
type: 'POST', // send input data and use it inside PHP code using $_POST[''];
data: {userID: userID}, {dbpassword: dbpassword}, {firstname: firstname}, {lastname: lastname}, {email: email}, {phone: phone}, {username: username}, {password: password}, {role: role},
dataType: "text", //using json to populate the returned array.

success:function(updateuser) {
alert("SUCCESS: User Updated Successfully!");

alert("ERROR: Please try again or call your Systems Administrator");



What am I doing wrong? Any help will be most appreciated!!! Thank you!!!

enter image description here

Answer Source

Unable to get property 'value' of undefined or null reference

The issue arise when js is not able to refer to the element.

In your case it is most likely that you are not passing userID (and other ids) as string. you may need do like this

document.getElementById('userID').value; // note the quotes
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download