DEVPPL
http://www.devppl.com/forum/

How to display data in textbox
http://www.devppl.com/forum/viewtopic.php?f=49&t=12399
Page 1 of 1

Author:  ma-la [ Tue Nov 25, 2008 2:28 pm ]
Post subject:  How to display data in textbox

I want to fetch data from mysql and display in textbox when I click the corresponding item in listbox. I used SQL JSTL to fetch data for listbox. Please help me how to display data in textbox?

Author:  rangana [ Wed Nov 26, 2008 3:02 am ]
Post subject: 

You can use the value method available on the textbox element.

Please show us the generated markup of your listbox (select element) so we could help you have a script of your desire.

Author:  ma-la [ Wed Nov 26, 2008 7:09 am ]
Post subject: 

My listbox has some product names
LG
Sanyo
like this
When I click LG item in listbox corresponding data should be displayed in the textbox

I tried

<input style="WIDTH: 83px; HEIGHT: 23px" size="10" name="Quantity">
<c:forEach var="row" items="${list.rows}">
<c:set var="quantity ">"{row.quantity }"
</c:set>
<option>
<c:out value="{row.quantity }"/>
</option>
</c:forEach>

All datas are displayed.But I want to display one data. Please help me

Author:  rangana [ Wed Nov 26, 2008 8:12 am ]
Post subject: 

Please show the generated markup.

The one that you see when you view the source.

Author:  ma-la [ Wed Nov 26, 2008 10:02 am ]
Post subject: 

I am not getting what you are asking

I used

<sql:query var="list" dataSource="${dataSource}">
select user_id,name,sum(quantity) as quantity from Product GROUP BY name;
</sql:query>

I have Name Listbox and quantity textbox

The values are displayed as 200,400,800..outside the textbox

I want to display the corresponding value in the textbox when I click the name in the listbox

Please help

Author:  rangana [ Wed Nov 26, 2008 10:09 am ]
Post subject: 

The code you're showing is a server-side script (or better yet a raw file).

I'm asking for the generated markup.

The one you see when you view the page's source.

Hope that makes sense.

Author:  ma-la [ Wed Nov 26, 2008 10:23 am ]
Post subject: 

<table cellspacing="0" cellpadding="3" width="40%" align="left" border="0">

<tr>
<td>&nbsp; Stock Code</td>
<td><select size="1" name="name">

<option>
LG
</option>


<option>
Samsung
</option>


<option>
Sony
</option>




</select></td></tr>
<tr>
<td>&nbsp; Quantity</td>
<td><input style="WIDTH: 83px; HEIGHT: 23px" size="10" name="Quantity">



<option>
20200
</option>



<option>
12000
</option>



<option>
200
</option>





</td>
</tr>

Author:  rangana [ Wed Nov 26, 2008 10:32 am ]
Post subject: 

I see. You're second select element is erroneous.

You should contain option element inside select element:
Code:
<option>
20200
</option>



<option>
12000
</option>



<option>
200
</option>


Which of the two select element are you wanting its selectedIndex texts be shown on the textbox?

Author:  ma-la [ Wed Nov 26, 2008 10:39 am ]
Post subject: 

I don't want to list all quantity data in the listbox. If I use option inside select ,all values will be listed in the listbox.

Author:  rangana [ Wed Nov 26, 2008 10:52 am ]
Post subject: 

That doesn't makes sense.

Anyway, how about a response to my question?

Author:  ma-la [ Wed Nov 26, 2008 1:27 pm ]
Post subject: 

second one quantity value should be displayed in the textbox

Author:  rangana [ Wed Nov 26, 2008 1:55 pm ]
Post subject: 

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:
<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.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/