shane07 Posted July 15, 2009 Share Posted July 15, 2009 <form name="form"> <input name="data[name]"/> <input name="data[address]"/> <input type="submit" onclick="return validate()"/> </form> <script> function validate(){ var name=document.form.data['name'].value; alert(name); } </script> This piece of code is not working. It says document.form.data is undefined. Any hint about this problem? Quote Link to comment https://forums.phpfreaks.com/topic/166026-documentformnameelementnameindexvalue-is-not-working/ Share on other sites More sharing options...
KevinM1 Posted July 15, 2009 Share Posted July 15, 2009 <form name="form"> <input name="data[name]"/> <input name="data[address]"/> <input type="submit" onclick="return validate()"/> </form> <script> function validate(){ var name=document.form.data['name'].value; alert(name); } </script> This piece of code is not working. It says document.form.data is undefined. Any hint about this problem? It's a syntax issue. Since the inputs use array notation, you can't reference them quite the way you're attempting to. Instead, try: document.forms['form'].elements['data[name]'].value; See also: http://www.javascripttoolbox.com/bestpractices/#squarebracket Quote Link to comment https://forums.phpfreaks.com/topic/166026-documentformnameelementnameindexvalue-is-not-working/#findComment-875692 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.