Join the AMA (Ask Me Anything) with the Firefox leadership team to celebrate Firefox 20th anniversary and discuss Firefox’s future on Mozilla Connect. Mark your calendar on Thursday, November 14, 18:00 - 20:00 UTC!

Funkcjonalność tej witryny będzie ograniczona w czasie konserwacji. Jeśli artykuł nie rozwiązuje twojego problemu i chcesz zadać pytanie, to nasza społeczność wsparcia jest dostępna na @FirefoxSupport na Twitterze i /r/firefox na Reddicie.

Przeszukaj pomoc

Unikaj oszustw związanych z pomocą.Nigdy nie będziemy prosić Cię o dzwonienie na numer telefonu, wysyłanie SMS-ów ani o udostępnianie danych osobowych. Zgłoś podejrzaną aktywność, korzystając z opcji „Zgłoś nadużycie”.

Więcej informacji

PHP/javascript assigning a value to a text field doesn't work?

  • 2 odpowiedzi
  • 1 osoba ma ten problem
  • 11 wyświetleń
  • Ostatnia odpowiedź od rking.ph

more options

I have a website someone else coded, where a text field won't display a value that is assigned to it.

Both form1.textfield3.value = form1.textfield1.value; and form1.textfield3.value = "99";

do not work, and the text field remains blank.

This same code works on Internet Explorer (Win and OSX), Safari, Chrome, and Opera. It does NOT work on Firefox 8 or 9.01 (Win and OSX) or 3.6.25; it used to work on an older Firefox we had (version unknown).

Javascript is enabled; is there anything else we can check?

I have a website someone else coded, where a text field won't display a value that is assigned to it. Both form1.textfield3.value = form1.textfield1.value; and form1.textfield3.value = "99"; do not work, and the text field remains blank. This same code works on Internet Explorer (Win and OSX), Safari, Chrome, and Opera. It does NOT work on Firefox 8 or 9.01 (Win and OSX) or 3.6.25; it used to work on an older Firefox we had (version unknown). Javascript is enabled; is there anything else we can check?

Wybrane rozwiązanie

If you check Firefox's Error Console (Ctrl+Shift+j), you will see "form1 is not defined". This is because Firefox does not automatically convert form1 into a reference to <form name="form1">. Instead, you need to edit the code a bit.

You can resolve the above error by beginning each function where you refer to form1 with this:

var form1 = document.forms["form1"];

However, this probably will just move the error to the next part of the notation (e.g., textfield3). The proper way to refer to the value of a named form field is:

document.forms["form1"].elements["textfield3"].value

or if you have defined form1,

form1.elements["textfield3"].value

So you have some editing to do. Not sure whether there are any shortcuts.

This forum focuses on end-user support. You can find more web development help on the mozillaZine Web Development board. Separate forum, separate registration.

Przeczytaj tę odpowiedź w całym kontekście 👍 1

Wszystkie odpowiedzi (2)

more options

Wybrane rozwiązanie

If you check Firefox's Error Console (Ctrl+Shift+j), you will see "form1 is not defined". This is because Firefox does not automatically convert form1 into a reference to <form name="form1">. Instead, you need to edit the code a bit.

You can resolve the above error by beginning each function where you refer to form1 with this:

var form1 = document.forms["form1"];

However, this probably will just move the error to the next part of the notation (e.g., textfield3). The proper way to refer to the value of a named form field is:

document.forms["form1"].elements["textfield3"].value

or if you have defined form1,

form1.elements["textfield3"].value

So you have some editing to do. Not sure whether there are any shortcuts.

This forum focuses on end-user support. You can find more web development help on the mozillaZine Web Development board. Separate forum, separate registration.

more options

Thanks very much! I tested a few different permutations; the one that finally worked on Firefox was document.forms["form1"].textfield3.value (the other formats did not work - not sure why). I just replaced all necessary instances and everything worked in all the browsers we tested. I'm a bit disappointed that Firefox needed a little special attention, when other browsers handled the old code just fine, but I'm glad our code wasn't too complicated.

Zmodyfikowany przez rking.ph w dniu