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. Link to comment https://forums.phpfreaks.com/topic/131377-code-to-retrieve-values-from-a-form/ 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'. Link to comment https://forums.phpfreaks.com/topic/131377-code-to-retrieve-values-from-a-form/#findComment-682290 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. Link to comment https://forums.phpfreaks.com/topic/131377-code-to-retrieve-values-from-a-form/#findComment-682638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.