[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

javascript element search

Hi,
 I am using this javascirpt fuction but my page contains around 5000 controls as we are using regulare expression its taking time to load the page some times it stop processing. Is there any other way to do this with out regexpression.

<html>
<head>
<script language="javascript">
function fill()
{
  var re = /^txtJpn_(\d+)/;
  var match;

  for (var i = 0; i < document.forms[0].elements.length; i++)
  {
     match = re.exec(document.forms[0].elements[i].name);
     if (match) {
         document.getElementById("txtOthers_" + match[1]).value = document.forms[0].elements[i].value;
     }
  }
}
</script>
</head>
<body>
<form>
<input type="text" name="txtJpn_0" >
<input type="text" name="txtOthers_0">
<input type="text" name="txtJpn_1">
<input type="text" name="txtOthers_1">
<input type="text" name="txtJpn_2">
<input type="text" name="txtOthers_2">
<input type="text" name="txtJpn_3">
<input type="text" name="txtOthers_3">
<input type="text" name="txtJpn_4">
<input type="text" name="txtOthers_4">
<input type="text" name="txtJpn_5">
<input type="text" name="txtOthers_5">
<input type="text" name="txtJpn_6">
<input type="text" name="txtOthers_6">
<input type="button" onclick="fill();" value="Fill">
</form>
</body>
</html>
0
sateeshkumarj
Asked:
sateeshkumarj
  • 2
1 Solution
 
sateeshkumarjAuthor Commented:
this question is a continuation of this below question.
http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21823189.html
0
 
ZvonkoSystems architectCommented:
Here an example:

<html>
<head>
<title>Zvonko &#42;</title>
<script language="javascript">
function fill(theBtn){
  var theForm = theBtn.form;
  for(var i=0;theForm["txtJpn_"+i];i++){
    theForm["txtOthers_"+i].value = theForm["txtJpn_"+i].value;
  }
}
</script>
</head>
<body>
<form>
<input type="text" name="txtJpn_0" >
<input type="text" name="txtOthers_0"><br>
<input type="text" name="txtJpn_1">
<input type="text" name="txtOthers_1"><br>
<input type="text" name="txtJpn_2">
<input type="text" name="txtOthers_2"><br>
<input type="text" name="txtJpn_3">
<input type="text" name="txtOthers_3"><br>
<input type="text" name="txtJpn_4">
<input type="text" name="txtOthers_4"><br>
<input type="text" name="txtJpn_5">
<input type="text" name="txtOthers_5"><br>
<input type="text" name="txtJpn_6">
<input type="text" name="txtOthers_6"><br>
<input type="button" onclick="fill(this);" value="Fill">
</form>
</body>
</html>

0
 
ZvonkoSystems architectCommented:
Please explain why you graded my support with the grade B.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now