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

Forum

Log In Sponsors
Partner Sites
Board index Programming JavaScript Forum

How to display data in textbox

How to display data in textbox

Postby ma-la on Tue Nov 25, 2008 2:28 pm

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?
ma-la
 
Posts: 6
Joined: Tue Nov 25, 2008 2:25 pm

Postby rangana on Wed Nov 26, 2008 3:02 am

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.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 6:14 am
Location: Cebu City Philippines

Postby ma-la on Wed Nov 26, 2008 7:09 am

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
ma-la
 
Posts: 6
Joined: Tue Nov 25, 2008 2:25 pm

Postby rangana on Wed Nov 26, 2008 8:12 am

Please show the generated markup.

The one that you see when you view the source.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 6:14 am
Location: Cebu City Philippines

Postby ma-la on Wed Nov 26, 2008 10:02 am

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
ma-la
 
Posts: 6
Joined: Tue Nov 25, 2008 2:25 pm

Postby rangana on Wed Nov 26, 2008 10:09 am

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.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 6:14 am
Location: Cebu City Philippines

Postby ma-la on Wed Nov 26, 2008 10:23 am

<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>
ma-la
 
Posts: 6
Joined: Tue Nov 25, 2008 2:25 pm

Postby rangana on Wed Nov 26, 2008 10:32 am

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

You should contain option element inside select element:
Code: Select all
<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?
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 6:14 am
Location: Cebu City Philippines

Postby ma-la on Wed Nov 26, 2008 10:39 am

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.
ma-la
 
Posts: 6
Joined: Tue Nov 25, 2008 2:25 pm

Postby rangana on Wed Nov 26, 2008 10:52 am

That doesn't makes sense.

Anyway, how about a response to my question?
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 6:14 am
Location: Cebu City Philippines

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

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

Postby rangana on Wed Nov 26, 2008 1: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 6:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: No registered users and 5 guests