English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

document.myForm.myInput.text = test;





im getyting this error " document.myForm.myInput is null or not an object"1

2007-02-06 06:27:33 · 4 answers · asked by aryaxt 3 in Computers & Internet Programming & Design

i also tried
document.myForm.myInput.value = test;

2007-02-06 06:28:19 · update #1

4 answers

You need to show more code.
The first thing to be aware of is that your web page is executed from the top down.
If the javascript is not in a function then it is executed first before the form has been created.
Thus it is correct to issue the error that you are getting.
To fix this I would suggest that you put the javascript in a function called startUp.
Then code the body tag like this

2007-02-06 07:22:31 · answer #1 · answered by AnalProgrammer 7 · 0 1

Give the input field an ID rather than name. then you can use getElementByID to read the value. Also if start using JS libraries like the Yahoo YUI Library etc you can simply call objects using their simplified DOM collection methods.

Everything that is unique and stores a value or some sort of state info should have an ID. The added value being that you can then also use the ID to better target each element for custom styling via CSS.

in your example above, if you change name to id then the following code would work to get a value and it will work on all modern browsers

document.getElementById("myInput").value = "some test value"

2007-02-06 15:42:36 · answer #2 · answered by Klausy 2 · 1 0

To expand upon a previous answer:

When you use a name attribute in an HTML element, the Document Object Model (DOM) treats the element as though it is in an array.

Thus, using your current HTML, and assuming your text field is the only element with the name myInput, then you would access it via:

document.myForm.myInput[ 0 ].value

(And note that you assign textbox values with the value property; there is no text property for input in the IE or Mozilla DOMs).

The previous answer is correct; elements can share names but they can't share IDs. So, if you change your textbox to be , your script will work fine in both the IE and Mozilla DOMs.

The name attribute is more commonly used to handle checkboxes / radio buttons, where you often want to return more than one value.

Samples that handle form elements are below.

2007-02-06 17:04:56 · answer #3 · answered by Anonymous · 0 0

I think myInput.text needs to be myInput.value

The word test needs to be wrapped in quotes.

I think your form needs to precede the call referencing it.

2007-02-06 14:47:31 · answer #4 · answered by SkewsMe.com 3 · 0 1

fedest.com, questions and answers