From <Select> to Textbox

Hello,

I got the following html

<select id="P_City" tabindex="9" onSelect="JCopyField()" >
<option value="1">Boston</option>
<option value="2">Ithaca</option>
<option value="3">New York</option>
</select>

<input name="" type="text" id="E_City">

What i want is when a user chooses one of the cities from the list.. it should show up in the textbox.. so i wrote the JCopyField() function as follows

Function JCopyField(){

document.T_Form.getElementById('E_City').value = document.T_Form.getElementById('P_City').value;
}

But it does not work.. can anyone take the bug out.. its driving me buts

regards,
kimoo.
[792 byte] By [kimoo] at [2007-11-20 8:59:48]
# 1 Re: From <Select> to Textbox
That's because it's just document.getElementById(). Don't call the form. Also, I would recommend downloading Firefox and using their JavaScript debugger. It will help you greatly.
PeejAvery at 2007-11-8 0:42:44 >
# 2 Re: From <Select> to Textbox
Downloaded JavaScript debugger...kind of cool.

The problem seems to be the HTML not the JavaScript.

EDIT: Accidentally edited instead of quoting.
kimoo at 2007-11-8 0:43:37 >
# 3 Re: From <Select> to Textbox
Your problem is the HTML. You have onselect in your select tag. Use onchange.
PeejAvery at 2007-11-8 0:44:45 >
# 4 Re: From <Select> to Textbox
i can not believe that i had been trying to debug such a mistake for sooo long..

Guess what even onChange does not work.. and i am still trying to find out why

gonna break my box today :$

kimoo
kimoo at 2007-11-8 0:45:41 >
# 5 Re: From <Select> to Textbox
NOOOOOOOOOOOOOO

the problem was in two things

1. onSelect had to be onChange

2. Guess this just guess the 'F' of the word function in the Javascript was UpperCase and it had to be LowerCase

OMG ~ i just love programming..

kimoo
kimoo at 2007-11-8 0:46:46 >
# 6 Re: From <Select> to Textbox
2. Guess this just guess the 'F' of the word function in the Javascript was UpperCase and it had to be LowerCase
What I said was correct with the onchange. Funny though, I didn't event thing about F instead of f. Sometimes you just look over things.
PeejAvery at 2007-11-8 0:47:42 >
# 7 Re: From <Select> to Textbox
I think to get value from select element first you to get its selected index and then from options array get its value. For example

<select name="abc" id="abc" onchange="showSelectedValue()">
<option value="A">A
<option value="B">B
<option value="C">C
</select>
function showSelectedValue()
{
var selectedIndex = document.getElementById('abc').selectedIndex;
alert(document.getElementById('abc').options[selectedIndex].value);
}
Waqas_Badar at 2007-11-8 0:48:51 >
# 8 Re: From <Select> to Textbox
I think to get value from select element first you to get its selected index and then from options array get its value.
You miss the point. The point was to fill the textbox when a user selects something from the drop-down. Not alter the drop-down by using JavaScript.

Anyway, the issue has already been resolved.
PeejAvery at 2007-11-8 0:49:45 >