开发者

Is there other way to reference textbox?

开发者 https://www.devze.com 2023-03-14 09:11 出处:网络
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();

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消