将动态ID传递给javascript [英] passing dynamic id's to javascript

查看:140
本文介绍了将动态ID传递给javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个while循环,它改变了每个输入字段的id。

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

如果我有3个订单我应该有3个ID

above if i have 3 orders i should have 3 ids

id- pro0
id- pro1
id- pro2

id- pro0 id- pro1 id- pro2

在我的javascript中我想要的调用id就像这样

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;

  }

问题是值不起作用。

它适用于单个变量,例如在循环外传递东西但是当我想从循环内发送id时它们不起作用。任何人都可以帮助

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

非常感谢

kardklub

推荐答案

form.pro0.value;

用于访问输入名称为 pro0

尝试 form.productitemsupdate_0.value

尝试使用 getElementById http://www.tizag.com/javascriptT/javascript-getelementbyid.php

同时更改您的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>";

这篇关于将动态ID传递给javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆