Solved

Naming a form....can I ?

Posted on 1998-09-30
3
158 Views
Last Modified: 2013-12-25
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
Comment
Question by:AnitaP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Expert Comment

by:chrisbolt
ID: 1828893
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
 

Author Comment

by:AnitaP
ID: 1828894
no I can not. Cause I have multiple forms in my page and I need to send the right information.
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 40 total points
ID: 1828895
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question