Dan06 Posted November 4, 2008 Share Posted November 4, 2008 I'm new to Javascript. I was trying to retrieve values from a form and I used the following code. var x = document.form['formName'].element['fieldName'].value; That didn't work, so I tried another way; I used the code below. var x = document.getElementById('formName').fieldName.value; This code worked. Can someone tell me where I went wrong with the first attempt/code? Thanks. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted November 4, 2008 Share Posted November 4, 2008 Your first line should be: var x = document.forms['formName'].elements['fieldName'].value; Notice the 's' at the end of 'forms' and 'elements'. Quote Link to comment Share on other sites More sharing options...
Dan06 Posted November 5, 2008 Author Share Posted November 5, 2008 I can't believe I missed the "s"... thanks for the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.