PDA

View Full Version : SelectBox


balan
01-17-2006, 04:18 AM
Hi all,
I got a selectbox which displays some datas. In that same form i got a textbox. If i type some text into the textbox, that text should be transferred displayed into the selectbox along with the other text. Anybody got sample coding for this. Thank you.

balen

dntget0wned
01-18-2006, 12:23 AM
<html>
<head>
<title>THIS JAVASCRIPT SHOULD WORK</title>
<script>
<!--
function add1(){
var adde = az.ab.value
var addf = az.abc.options.length
az.abc.options[addf] = new Option(adde)
az.ab.value = ''}
-->
</script>
</head>
<body>
<form name="az" onsubmit="add1();return false">
<select name="abc">
<option>R4ND0M</option>
</select>
<input type="text" name="ab" value=""></input>
<button type="submit">ADD 1</button>
</form>
</body>
</html>

dntget0wned
01-18-2006, 04:57 PM
If you also would like to add More objects to the drop down menu that have values
you would use the following code:
______________________________________
<html>
<head>
<title>THIS JAVASCRIPT SHOULD WORK</title>
<script>
<!--
function add1(){
var adde = az.ab.value
var addf = az.ab2.value
var addg = az.abc.options.length
az.abc.options[addg] = new Option(adde,addf)
az.ab.value = ''
az.ab2.value = ''}
-->
</script>
</head>
<body>
<form name="az" onsubmit="add1();return false">
<select name="abc">
<option>R4ND0M</option>
</select>
<font size="3">Text:</font><input type="text" name="ab" value=""></input><font size="3">Value:</font><input type="text" name="ab2" value=""></input>
<button type="submit">ADD 1</button>
</form>
</body>
</html>

balan
01-20-2006, 09:06 AM
Hello,
Thank you for ur sample coding, it works fine. I need another help. I have a select box which displays some items. if the user clicks the submit button without choosing any item in the select box i need an alert to be displayed ("choose an item from the select box). In this i am already calling a function like this

<select NAME="sub_topic" SIZE="15" style="width:200;" onChange="checkchild(this.options[this.selectedIndex].value);">

<option value=''>Select one</option>
<option value=''>one</option>
<option value=''>two</option>
</select>

Balen

dntget0wned
01-20-2006, 07:21 PM
<script>
<!--
function checkchild(){
if (a.sub_topic.selectedIndex == -1 || a.sub_topic.selectedIndex == 0){
alert('Please Select an Option!');return false}}
-->
</script>
<form name="a" onsubmit="checkchild()" action="" method="">
<select NAME="sub_topic" SIZE="15" style="width:200;">
<option value=''>Select one</option>
<option value=''>one</option>
<option value=''>two</option>
</select>
<input type="submit" value="GO"></input>
</form>