accessing the content of multiple input boxes (from javascript) which were created dynamically with ASP 
Author Message
 accessing the content of multiple input boxes (from javascript) which were created dynamically with ASP

Hi, I have an ASP page which generates multiple input boxes as follows

<form name="myform" method="post" action="nextpage.asp">
For i = 1 to 3
  For j = 1 to 10
<input type="text" name="prod<%= i%><%= j%>" value="" size="4"
maxlength="4">
  Next
Next
<input type=button name="badd" value="Add" onClick="test();">
</form>

Then, on the click of a button I want to be able to run through the
contents of
each input box (prod11, prod12, prod13, prod21 etc) to do some testing.
I currently have the following Javascript code which I have been
experimenting with :

function prodobj(prod,x,y)
{
    var str = new String(prod)
    str = str + x + y
   this.prodcode = str;

Quote:
}

function test() {
var valid = False;

for (i = 1;  i < 11;  i++)
  {
    for (j = 1;  j < 4;  j++)
    {
    p = new prodobj("document.myform.prod",i,j); 'attempt to make an
object
    var pstr = p.prodcode.value; 'get the value of the object
    if (i == 1 && j == 1)
      {
      alert(pstr); 'test the first value to see if it works
      }
     'test each value here
    }
  }
if (valid == True) {
  document.myform.submit();

Quote:
}
}

It works, obviously, if you use the literal name of the input box eg.
document.myform.prod11.value
but I can't get javascript to recognise dynamically created input boxes.

I have tried slightly different versions of the above javascript code
but each time I get 'undefined' in
the message box or the error message 'p.prodcode is not an object'.

Could any javascript gurus please help me on this one ?

Thanks in advance

Simon O'Neill



Sun, 28 Jul 2002 03:00:00 GMT  
 accessing the content of multiple input boxes (from javascript) which were created dynamically with ASP
Hi

You mean something like this?

Should work in Netscape if you remove
the innerHTML


<html>
<head>
<title>Main</title>
<script type="text/javascript">
function test( f ){
for(i = 0; i < 10; i++)
   {
   showOff.innerHTML += f[("pro" + i)].value + "<br>";
   }

Quote:
}

</script>
</head>
<body bgcolor="#000000" text="#FFFFFF">
<form>
<%
for(i = 0; i < 10; i++)
   {
   Response.Write("<input type='text' name='pro" + i +"'><br>");
   }
%>
<input type="button" value="Click" onclick="test(this.form)">
</form>
<div id="showOff"></div>
</body>
</html>

--
Best Regards
   Vidar Petursson
http://www.icysoft.com


No matter where you go there you are.
-

Quote:
> Hi, I have an ASP page which generates multiple input boxes as follows

> <form name="myform" method="post" action="nextpage.asp">
> For i = 1 to 3
>   For j = 1 to 10
> <input type="text" name="prod<%= i%><%= j%>" value="" size="4"
> maxlength="4">
>   Next
> Next
> <input type=button name="badd" value="Add" onClick="test();">
> </form>

> Then, on the click of a button I want to be able to run through the
> contents of
> each input box (prod11, prod12, prod13, prod21 etc) to do some testing.
> I currently have the following Javascript code which I have been
> experimenting with :

> function prodobj(prod,x,y)
> {
>     var str = new String(prod)
>     str = str + x + y
>    this.prodcode = str;
> }

> function test() {
> var valid = False;

> for (i = 1;  i < 11;  i++)
>   {
>     for (j = 1;  j < 4;  j++)
>     {
>     p = new prodobj("document.myform.prod",i,j); 'attempt to make an
> object
>     var pstr = p.prodcode.value; 'get the value of the object
>     if (i == 1 && j == 1)
>       {
>       alert(pstr); 'test the first value to see if it works
>       }
>      'test each value here
>     }
>   }
> if (valid == True) {
>   document.myform.submit();
> }
> }

> It works, obviously, if you use the literal name of the input box eg.
> document.myform.prod11.value
> but I can't get javascript to recognise dynamically created input boxes.

> I have tried slightly different versions of the above javascript code
> but each time I get 'undefined' in
> the message box or the error message 'p.prodcode is not an object'.

> Could any javascript gurus please help me on this one ?

> Thanks in advance

> Simon O'Neill



Sun, 28 Jul 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Validating input from input box against an array of suitable inputs

2. Problem with DOM and JavaScript: INPUT nodes created at run-time

3. accessing input boxes

4. accessing HTML content with javascript

5. Permission denied when using Input boxes and message boxes

6. creating a text box errors message for empty text box

7. javascript array problem, or am I just stupid!!!

8. Printing contents of multiple frames

9. Dragging contents of a multiple selection list.....?

10. I am new to javascript and have a question

11. Problems with Printing content created by Document.Write

12. Problems with Printing content created by Document.Write

 

 
Powered by phpBB® Forum Software