Go Premium for a chance to win a PS4. Enter to Win

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

Naming a form....can I ?

I have this form which I need to associate a name to it. but the only values that the name can have is either a number or a string with spaces. I am passing the name of the form through a parameter to a function. For example:
<form method=post action=... name=<%=str%>>

str : contains either a number or a string with spaces
      ("this is a test")

now when I try to retreive this str value in my function is says the the object is not defined.
this is how i am trying to do it:
function blabla(str,anothersimplestring)
{
   document.forms[str].test.value=anothersimplestring
}
test is the name of a simple input text box. I am trying to display the contents of anothersimplestring in this input box. If anyone can help me, I would appreciate it a lot. Thanks in advance.
0
AnitaP
Asked:
AnitaP
1 Solution
 
chrisboltCommented:
Couldn't you just leave out the NAME attribute from the <FORM> tag and use this code instead?:

function blabla(anothersimplestring) {
   document.forms[0].test.value=anothersimplestring
}
0
 
AnitaPAuthor Commented:
no I can not. Cause I have multiple forms in my page and I need to send the right information.
0
 
Michel PlungjanIT ExpertCommented:
1. Get rid of the spaces (f.ex. make them underscores) and use document.this_is_a_test.test.value=anothersimplestring

2. function blabla(str,anothersimplestring) {
      for (i=0,n=document.forms.length;i<n;i++) {
         if (document.forms[i].name == str) {
            document.forms[i].test.value=anothersimplestring;
            break;
         }
    }
}

Michel
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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