Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Naming a form....can I ?

Posted on 1998-09-30
3
Medium Priority
?
160 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 160 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

704 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