By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,741 Members | 1,973 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,741 IT Pros & Developers. It's quick & easy.

Value entered in text box appears automatically in combo box (or text box)

100+
P: 106
i'm new to ajax and i have a simple text box and a combo box and i need whenever the user enters a text in the text box that value appears at the combo box or whatever field( another text box maybe )
Nov 3 '08 #1
Share this Question
Share on Google+
4 Replies


RamananKalirajan
100+
P: 607
Do u really want to do this thing with AJAX, u can achieve this task wothout AJAX.

[HTML] <html>
<head>
<script type="text/javascript">
function doThis()
{

var x = document.getElementById('myText').value;
if(x==""||x==null||x==false)
{
alert("Please Enter the Value in the Text Field");
document.getElementById('myText').focus;
}
else
{
document.getElementById('mySelect').add(new Option(x,x));
}
}
</script>
</head>
<body>
Enter Text: <input type="text" id="myText" name="myText">
&nbsp;&nbsp;&nbsp;
<input type="button" value="Add to Combo" onclick="doThis()">
<br/><br/>
<select id="mySelect" name="mySelect">
<option>Select</select>
</select>
</body>
</html>[/HTML]

If u want to do it with Ajax, post the code what u have tried. I will try to help u out

Regards
Ramanan Kalirajan
Nov 4 '08 #2

acoder
Expert Mod 15k+
P: 16,027
jessy, I have changed your thread title.

Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

Moderator.
Nov 4 '08 #3

100+
P: 106
Thanks alot for you reply .. did what u said although i was trying to try something new (like ajax) but anyway, now i need when this value is added to the combo box the old option which is ( no data added ) be removed from the combo box
here's my trial :

Expand|Select|Wrap|Line Numbers
  1. var opt= document.getElementById("no");
  2.          opt.remove(0);
where "no" is the name of the option i want to remove not the name of the select statement
Nov 4 '08 #4

RamananKalirajan
100+
P: 607
Thanks alot for you reply .. did what u said although i was trying to try something new (like ajax) but anyway, now i need when this value is added to the combo box the old option which is ( no data added ) be removed from the combo box
here's my trial :

Expand|Select|Wrap|Line Numbers
  1. var opt= document.getElementById("no");
  2.          opt.remove(0);
where "no" is the name of the option i want to remove not the name of the select statement

Removing u can do easily

[HTML] var sel = document.getElementById('mySelect').selectedIndex;
document.getElementById('mySelect').remove(sel);[/HTML]

This piece of code will do the work what u are aiming at.

Regards
Ramanan Kalirajan
Nov 5 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.