|
|
 |
| Javascript How-To Ask your "How do I do this with Javascript?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other programmers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|
 |

June 4th, 2008, 10:23 PM
|
|
Authorized User
|
|
Join Date: Nov 2007
Location: , , .
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
populating drop down through text field
Hi,
Is there a way of populating a drop down list through a text field ? I am working on a project where a user can type in a text field. On enter or click the typed message should be copied to the drop down list and removed from the text field. I have seen some kind of solution from drop down to text field but not the other way around.
Can I get some directions here? thanks.
|

June 4th, 2008, 11:33 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi Nasir!!
Do you want to add these textbox values to dropdown from the client side??
e.g there is a text box ,dropdown and button.
user enters some name and clicks on the button,now only on the client side do you want to appear to the dropdown??(without post back to the server).
Then again its depends on technology(asp,php,or .NET) and the requirements/implementations too!!
Following code will give some directions on it
<script>
function addToDropdown()
{
//put your validation here before attaching to dropdown
txtName=document.getElementById('txtbox').value;
txtValue=txtName //if you want diff value put ur validation here
obj=document.getElementById("ddbox");
obj.options[obj.options.length] = new Option(txtName,txtValue)
obj.selectedIndex=obj.options.length-1;
}
</script>
<select name="ddbox" id="ddbox"></select>
<input type=text id="txtbox" >
<input type=button onclick="addToDropdown()" value="add To Dropdown">
to remove selected dropdown value/text
obj.options[obj.selectedIndex] = null;
Cheers :)
vinod
|

June 5th, 2008, 08:18 AM
|
|
Authorized User
|
|
Join Date: Nov 2007
Location: , , .
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Thanks a million Vinod, that was perfect !!!
|

June 5th, 2008, 08:43 AM
|
|
Authorized User
|
|
Join Date: Nov 2007
Location: , , .
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
........another one: how do i set the defualt value for drop down to the text copied from the text box ?
|

June 5th, 2008, 02:58 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi Nasir!!
dropdown has two thing, text and value
e.g.
<option value='x'>mytext</option>
in my previous post, i have put the default value of text as a default text..
txtName="mytext"
txtValue="x"
obj.options[obj.options.length] = new Option(txtName,txtValue)
//i have added below code so that everytime you enter the text and click on the button,newly added option should be default selected.
//if you comment below code you will find new option is added .
obj.selectedIndex=obj.options.length-1;
or I think you want to set the value of select box e.g. below code set the select box value to 2..
******test.html*******
<select id="sel">
<option value=1>VAl1</option>
<option value=2>VAL102</option>
</select>
<script>
obj=document.getElementById("sel")
obj.value=2
</script>
**********************
If this doesn't give any pointers to your question then could you explore more on ur requirement?
Cheers :)
vinod
|

June 30th, 2008, 11:01 AM
|
|
Authorized User
|
|
Join Date: Nov 2007
Location: , , .
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Thanks Vinod !!!
It took me sometime to reply though, sorry for that :)
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |