
I want to replace window.prompt with a textbox but it doesnt work,please help.
<script>
function addOption(Area){
oc = Area.options.length;
if(Area.selectedIndex==oc-1){
newOpt = window.prompt("Enter Area","");
if(newOpt+"">""){
Area.options[oc] = new Option(Area.options[oc-1].text);
Area.options[oc-1] = new Option(newOpt, newOpt, true, true);
}
}
}
</script>
//dropdownlist
<select name="Area" id="Area" onchange="addOption(this)">
<option value="Please Select">Please Select</option>
<option value="Johannesburg">Johannesburg</option>
<option value="Pretoria">Pretoria</option>
<option value="Cape Town">Cape Town</option>
<option value="Durban">Durban</option>
<option value="Other Specify">Other Specify</option>
</select>

<html>
<script>
function show(){
oc = Area.options.length;
if(Area.selectedIndex==oc-1){
document.getElementById('lab').style.visibility="visible";
document.getElementById('val').style.visibility="visible";
document.getElementById('b').style.visibility="visible";
}
}
function addOption(){
oc = Area.options.length;
newOpt = document.getElementById('val').value;
Area.options[oc] = new Option(Area.options[oc-1].text);
Area.options[oc-1] = new Option(newOpt, newOpt, true, true);
document.getElementById('lab').style.visibility="hidden";
document.getElementById('val').style.visibility="hidden";
document.getElementById('b').style.visibility="hidden";
}
</script>
<select name="Area" id="Area" onchange="show()">
<option value="Please Select">Please Select</option>
<option value="Johannesburg">Johannesburg</option>
<option value="Pretoria">Pretoria</option>
<option value="Cape Town">Cape Town</option>
<option value="Durban">Durban</option>
<option value="Other Specify">Other Specify</option>
</select>
<br><br>
<label id="lab" style="visibility:hidden;">Enter Area</label><input style="visibility:hidden;" type="text" id="val" ><input type="button" id="b" style="visibility:hidden;" value="ok" onclick="addOption();">
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.