It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

How to display data in textbox

Postby ma-la on Wed Nov 26, 2008 12:27 pm

second one quantity value should be displayed in the textbox
ma-la
 
Posts: 6
Joined: Tue Nov 25, 2008 1:25 pm

Postby rangana on Wed Nov 26, 2008 12:55 pm

It doesn't makes sense to me since the second select element isn't a "select" element since you don't want the option element be a child of select element.

Anyway, this might help:
Code: Select all
<script type="text/javascript">
/**
* Copy option's value/text to textbox
* Additional Feature: Be able to instruct the script as to the mode you wish.
* Created by Raymond Angana [username = rangana]
* First seen in devppl.com/forum
* This script must stay intact for legal use
*/
var ray=
{
transfer:function(inp,out,mod)
   {
   this.getID(inp).onchange=function()
      {
         ray.getID(out).value=mod?this.options[this.options.selectedIndex].text:this.value;
      }
   },
getID:function(el)
   {
      return document.getElementById(el); // Get the element's id
   }
}
window.addEventListener?window.addEventListener('load',function()
   {
   /**
   * @param1 - ID of the select element
   * @param2 - ID of the textbox where you want the value be seen
   * @param3 - Mode you wish the script to run. You could choose from 0/1
      0 - Will use the value of the options
      1 - Will use the text of the options
   */
   ray.transfer('myselect','output',1); // Last argument could either be 0/1. If 0, then it will get the options value, if 1, it will get the options texts
   },false):
window.attachEvent('onload',function()
   {
   /**
   * @param1 - ID of the select element
   * @param2 - ID of the textbox where you want the value be seen
   * @param3 - Mode you wish the script to run. You could choose from 0/1
      0 - Will use the value of the options
      1 - Will use the text of the options
   */
   ray.transfer('myselect','output',1); // Last argument could either be 0/1. If 0, then it will get the options value, if 1, it will get the options texts
   }); // FF : IE
</script>
<select id="myselect">
<option value="Opt1">Option 1</option>
<option value="Opt2">Option 2</option>
<option value="Opt3">Option 3</option>
<option value="Opt4">Option 4</option>
<option value="Opt5">Option 5</option>
</select>
<input type="text" readonly="readonly" id="output">


You can change the mode from 0 - 1. Comments explain the purpose.

Default is 0, which gets the options value.

Hope that helps.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Previous

Who is online

Users browsing this forum: No registered users and 4 guests