PDA

View Full Version : Using Javascript - Display Form Value in the html document



gandhikr
05-04-2010, 07:43 AM
Hello,

Kindly refer to attached image.

When someone selects the option from the drop down menu, The value of the field should be displayed near right side of the drop down.

Kindly let me know what Javascript code should I use?

Thanks a million
Kaushal

vwphillips
05-04-2010, 11:18 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/

function ShowValue(sel,id){
var obj=document.getElementById(id);
obj[obj.nodeName.toUpperCase()=='INPUT'?'value':'innerHTML']=sel.value;
}
/*]]>*/
</script></head>

<body>
<select onchange="ShowValue(this,'txt');" >
<option value="" >Select</option>
<option value="value 1" >Option 1</option>
<option value="value 2" >Option 2</option>
</select> <span id="txt" ></span>
<br />
<select onchange="ShowValue(this,'txt2');" >
<option value="" >Select</option>
<option value="value 1" >Option 1</option>
<option value="value 2" >Option 2</option>
</select> <input id="txt2" />
</body>

</html>