开发者

passing dynamic id's to javascript

i have a while loop that changes the id of each input field.

   print"<td><input style=\"text-align:center\" type=text name=productitemsupdate_$num value=\"$row[productitems]\" size=5 id=pro$num>}</td>"; <-- 开发者_运维问答this should produce pro0

above if i have 3 orders i should have 3 ids

id- pro0 id- pro1 id- pro2

in my javascript i want to call the id's like so

var pro = form.pro0.value;

  if(pro == "") {

  inlineMsg('pro','You can\'t leave this blank.',10);

  return false;

  }

the problem is the value does not work.

It works with single variables like passing things outside the loop but when i want to send the id's from within the loop they do not work. can anyone help

many thanks

kardklub


form.pro0.value;

is used to access input with name as pro0

Try form.productitemsupdate_0.value or

try using getElementById http://www.tizag.com/javascriptT/javascript-getelementbyid.php

Also change your php code to

print"<td><input style=\"text-align:center\" type=\"text\" name=\"productitemsupdate_$num\" value=\"$row[productitems]\" size=\"5\" id=\"pro$num\">}</td>";


Use square bracket notation instead of dot notation.

foo.bar === foo['bar']

You can pass the string in a variable rather than as a literal.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜