简体   繁体   中英

Javascript Error in Safari

There are two instances of Javascript failing through Safari. It's only safari, I've tested on multiple machines with different versions.

I have a large form, at one point in the form, they submit via AJAX (don't worry it's all validated and safe to send). I pick the information up using this method:

var vcompany = document.forms['registerForm']['vcompany'].value;

This doesn't seem to work. Also, in another instance I am picking information up from a form and calculating based on that information, then outputting it as a total price. This also does not seem to work:

var dates_A =  document.forms['registerForm']['childADates[]']; //from a checkbox group

Does anybody know of any issues? I'm not getting an error, the commands just aren't firing...

I suppose this is one of the key moments of stupidity in my life... I had a variable named class which all browsers accepted but Safari would not, it is a reserved word. The moment of stupidity: not checking the error log.

Any particular reason you are getting references to the form elements via document.forms?

You should get better cross browser results by either document.getElementById() or document.getElementsByTagName().

//if you have the same id's as the input's "name" attribute
var vcompany = document.getElementById('vcompany').value;//text input
var dates_A =  document.getElementById('childADates[]').checked;//checkbox

Give that a shot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM