View Full Version : How do i make onChange textbox?

07-04-2006, 06:11 PM

I have been searching this for 24 hours,couldn't find good code.I want a script like this;

There will be 2 option value,1st is yes,2nd is no.If person select "yes" textbox will appear below selection area,if person select "no" a link will appear,and will redirect you to there when you click on it.If you can help i will be so happy.Thanks.Good bye.

NOTE:JS will be used in PHP..

07-05-2006, 01:24 AM
You mean

<input type='text' onchange='change()' />?

with a function like:

<script type='text/javascript'>
// <![CDATA[
function change() {
alert ("you have changed the textbox...")
// ]]>

or what? From all I understood was: how to make an onchange event...

please explain.

Thanks :D

Hope it helps :D

07-05-2006, 03:39 PM
i think this might help :

<select id="name " onchange="DropDownMenuList('name')">

<option> yes </option>
<option value= whatever.html > no </option>


<textarea type="text" id="Iname" name="name" class="hide">

function DropDownMenuList(e)
var list=document.getElementById(e)

if(list.options[list.selectedIndex].text == “ yes”)
document.getElementById(“I”+e).className = "view";



Css style sheets // this allows to display or not

.hide {
display: none;

.view {
display: inline;

and if u still not sure try using this website it may be the one to help figure it out, it may be similar to what u want

07-06-2006, 02:08 AM
Thanks for bothering to reply,but codes that you have given,didnt work.


here is an example how form will work,page down a little and select Category in problem type section,when you select"connection problem" text box appearing below select section.I want to make form like this,if you know how to make,please write,thanks good bye.

07-07-2006, 12:35 AM

There are basically two ways to do it. One is to put the textarea and the link in your HTML, and assign them "display: none;" styles. You then create a javascript function that fires when the option list changes, evaluates the selected index, and changes the "display" styles accordingly. That is the method akg250978 is trying to explain but I didn't study it closely enough to know why it didn't work for you.

The second method is what I'll show you. What this does is use javascript to dynamically generate the new elements based on the onChange event. This may seem more convoluted at first, but I think it is good to learn how to generate elements this way.

let me know if you have problems or questions.

function showresult() {
// clean up div if necessary
var result = document.getElementById('result');
var len = result.childNodes.length;
for(var i = 0; i < len; i++)
//evaluate option
if (document.getElementById('selOption').selectedIndex == 1)
//dynamically insert textarea
var newinput = document.createElement('textarea');
var inputIdName = 'textarea';
else if (document.getElementById('selOption').selectedIndex == 2)
//dynamically insert link
var a=document.createElement('a');
var tdText=document.createTextNode('Link Text Goes Here');

<div id="optionbox">
<form id="frmExample" name="frmExample">
<select id="selOption" name="selOption" onchange="showresult();">
<option value="0">Choose One</option>
<option value="1">Yes</option>
<option value="2">No</option>
<div id="result"></div>

07-07-2006, 12:42 AM
oh by the way, i looked at the source code for the site you mention. they use the visibility: hidden method... you should be able to tell what they are doing by just viewing the source of that page.

07-08-2006, 03:29 AM
Thank you very much for helping,last code has been working as intended,Thanks again.Good bye.