By some reason action does not want to be performed on this textbox when variable is used for name:
var formQty = new String("QTY." + productName).toString();
var total = document.MainForm.elements["formQty"].value;
document.MainForm.elements["formQty"].value = sum;
This is HTML: input type="text" name="QTY.1-DAY-ACUVUE" size="3" maxlength="8" onkeydown="javascript:QtyEnabledAddToCart();" value="1"
I only have name of texbox, not Id. var total does not return value when var f开发者_StackOverflow中文版ormQty is used. If I hardcode the name instead of using variable var formQty, operation works. Only with variable it does not. I compared my varaible value with actual name and they are equal. Used both lengh comparison and == comparison. Both returned true.
Is there another way of defining var total?
These are quite popular
document.getElementsByName("element-name");
document.getElementById("element-id");
You can also use indices
document.forms[0].elements[0];
document.forms[0].elements[1];
精彩评论