Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function that populates textfield not working on firefox

Status
Not open for further replies.

mpartarrieu

Programmer
Nov 21, 2006
34
ES
Hi all,

I've written this javascript function that populates a textfield when an option is selected from a dropdown menu. It works fine in IE, but nothing happens using firefox.

Here's the function:

Code:
function update_it(valor,referencia)
 {
 var m = document.getElementById(referencia);
 m.value = valor.options[valor.selectedIndex].value;
 }

And here's the form I'm calling the function from:

Code:
<form action="actiob.php" method="post" name="formulario">

<input type="text" name="text_1" value="" size="5" />
<br /><br />

<select name="change_text_1" id="change_text_1" onchange="update_it(this,'text_1')">
 <option value=""></option>
 <option value="1">Value 1</option>
 <option value="2">Value 2</option>
 <option value="3">Value 3</option>
 <option value="4">Value 4</option>
</select>

</form>

Any ideas??? TIA

 
The problem is with this line:
Code:
<input type="text" name="text_1" value="" size="5" />

You have not supplied an id for the input element, yet you are using getElementBy[!]Id[/!] to try to access that element. Seemingly IE is using the element's name (incorrectly) as the id, and that's why it's working in that browser. Give the element an id (in addition to the name) and it should work fine in both browsers:
Code:
<input type="text" name="text_1" [!]id="text_1"[/!] value="" size="5" />


-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top