|
-
July 2nd, 2007, 12:05 PM
#1
From <Select> to Textbox
Hello,
I got the following html
Code:
<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
Code:
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.
-
July 2nd, 2007, 12:45 PM
#2
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
July 2nd, 2007, 01:23 PM
#3
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.
Last edited by PeejAvery; July 2nd, 2007 at 02:29 PM.
-
July 2nd, 2007, 02:28 PM
#4
Re: From <Select> to Textbox
Your problem is the HTML. You have onselect in your select tag. Use onchange.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
July 2nd, 2007, 03:40 PM
#5
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
-
July 2nd, 2007, 04:03 PM
#6
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
-
July 2nd, 2007, 04:10 PM
#7
Re: From <Select> to Textbox
 Originally Posted by kimoo
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
July 3rd, 2007, 01:32 AM
#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. For example
Code:
<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);
}
Muhammad Waqas Badar
-
July 3rd, 2007, 07:07 AM
#9
Re: From <Select> to Textbox
 Originally Posted by Waqas_Badar
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|