...

View Full Version : How do I get information for selected item of a combo



vikaspa
06-29-2004, 05:11 AM
Dear All

I have a combo for customers.

I want to show the address the selected Customer (in combo)in a extarea

Is there a way to stthese address so that it can be displayed immediately.

Do I need to store in an array ?

If so how do I do it ?

Please help.

With regards
hanking you in advance
Vikas Athavale

glenngv
06-29-2004, 05:16 AM
Put it in the option value

<form>
<select name="cust" onchange="this.form.address.value=this.options[this.selectedIndex].value">
<option value="">Choose Customer</option>
<option value="Address of Customer 1">Customer 1</option>
<option value="Address of Customer 2">Customer 2</option>
<option value="Address of Customer 3">Customer 3</option>
</select>
<textarea name="address"></textarea>
</form>

vikaspa
06-29-2004, 05:23 AM
I missed one point here
eith this I will miss the customer id...

I Canmerge it with name in order to get the id..

But , want to see customer names only


Kindly help

thanking you in advance
Vikas Athavale

glenngv
06-29-2004, 05:51 AM
Can you explain it more clearly?
I don't get what you're saying. You can show customer's name only in the combo box.

...
<option value="">Choose Customer</option>
<option value="Makati City, Philippines">glenngv</option>
<option value="Mumbai, India">vikaspa</option>
...

Can you post your codes?

glenngv
06-29-2004, 06:04 AM
You need the id in the option value in the server-side.


function showAddr(sel){
var arr = sel.options[sel.selectedIndex].value.split("|");
sel.form.address.value=(arr.length==2) ? arr[1]:"";
}
...
<form>
<select name="cust" onchange="showAddr(this)">
<option value="">Choose Customer</option>
<option value="123|Address of Customer 1">Customer 1</option>
<option value="456|Address of Customer 2">Customer 2</option>
<option value="789|Address of Customer 3">Customer 3</option>
</select>
<textarea name="address"></textarea>
</form>

Then when the form is submitted, parse the selected option in the server-side to get the id.

Or you can use my original suggestion replacing the address with the id and generate a js array of the addresses with the same order as the option items.


var arr = new Array("","Address of Cust 1","Address of Cust 2","Address of Cust 3"); //generate this in server-side
function showAddr(sel){
sel.form.address.value=arr[sel.selectedIndex];
}

vikaspa
06-29-2004, 01:10 PM
Your solution is OK but ..

Value of $bldgdetails ="abcd1234"
the value is stored is abcd1234(displayed in text area for address)


Value of $bldgdetails ="abcd 1234" or "abcd,1234"
the value is stored is abcd(displayed in text area for address)

Why such thing happens

Find belw my complete code

<select name="consigneelist" size="1" class="text-b12" onChange="document.clientfrm.consigneeaddress.value= this.options[this.selectedIndex].value, alert(this.options[this.selectedIndex].value)" >
<?
echo "<option selected value=0>Select Client</option>";
$sqlclient = "select party_id,name,bldgdetails,streetarea,taluka,district,state,pin,country from party where consignee='Y' order by name desc";
$result=mysql_db_query($DB_NAME, $sqlclient, $connection);
if ($result)
{
}
else
{
echo "<br>Error while executing query<br>".$sqclient;
}

while($row=mysql_fetch_object($result))
{
$pid = $row->party_id;
$adr= settype($pid, "string");
$consigneeadr=$pid;
$bldgdetails=$row->bldgdetails;
$streetarea=$row->streetarea;

$name= $row->name;

echo "<option value=".$bldgdetails." ".$streetarea</option>";
}
?>
</select>

Willy Duitt
06-29-2004, 01:48 PM
What's this?
You are not closing the opening option tag.......

echo "<option value=".$bldgdetails." ".$streetarea</option>";

vikaspa
06-30-2004, 02:49 AM
I am really bothering you and I admire your valued help .


Function I use to display the address

function arra(inte)
{
alert(inte); (-> value shown is correct this is nothing but the customer id) var arr = new Array(document.clientfrm.test.value);
alert(document.clientfrm.test.value); (-> value shown is correct. This shows complete list of ddresses in a single string)
alert(arr[1]); (note : I expect this will sho some value) document.clientfrm.consigneeaddress.value=arr[inte];( the value displayed in undefined)
}

Notes

1. I am storing all addresses in hidden field "test" using php .

2. I checked with alert and found details are stored correctly

3. I am calling this function when selection is changed.

4. I am sending sel.selectedIndex to this function

in following combo
<option value="3">".Soloman."</option>";
<option value="11">".George."</option>";
<option value="5">".Henry."</option>";

I am passing 5 for Hrenry whereas I should pass 2
I am passing 11 for George whereas I should pass 1
I am passing 3 for Soloman whereas I should pass 0

Please inform me
1. why the array is not defined
2. how do I pass the item number than the index (which is customer id)

vikaspa
06-30-2004, 02:50 AM
I am really bothering you and I admire your valued help .


Function I use to display the address

function arra(inte)
{
alert(inte); (-> value shown is correct this is nothing but the customer id)
var arr = new Array(document.clientfrm.test.value);
alert(document.clientfrm.test.value); (-> value shown is correct. This shows complete list of ddresses in a single string)
alert(arr[1]); (note : I expect this will sho some value) document.clientfrm.consigneeaddress.value=arr[inte];( the value displayed in undefined)
}

Notes

1. I am storing all addresses in hidden field "test" using php .

2. I checked with alert and found details are stored correctly

3. I am calling this function when selection is changed.

4. I am sending sel.selectedIndex to this function

in following combo
<option value="3">".Soloman."</option>";
<option value="11">".George."</option>";
<option value="5">".Henry."</option>";

I am passing 5 for Hrenry whereas I should pass 2
I am passing 11 for George whereas I should pass 1
I am passing 3 for Soloman whereas I should pass 0

Please inform me
1. why the array is not defined in javascript
var arr = new Array(document.clientfrm.test.value); when the alert display shows coreect string
2. how do I pass the item number than the index (which is customer id)

glenngv
06-30-2004, 03:18 AM
How are you storing the addresses in the hidden field? What separator do you use?


function arra(sel)
{
var f = sel.form; //form reference (every control has form property that refers to the form it belongs)
var arr = f.test.value.split("|");//put the separator you're using
if (arr.length>0) {
f.consigneeaddress.value=arr[sel.selectedIndex];
}
}
...
<select name="consigneelist" size="1" class="text-b12" onchange="arra(this)" >

I used the reference to the combo box (by using the this keyword) as the function parameter so that you don't have to specify the form name in the function.

vikaspa
06-30-2004, 04:17 AM
I could solve this with your superb guidelines.

I am using ~ as seperator

var ab = document.clientfrm.test.value;
var arr = ab.split("~");
document.clientfrm.consigneeaddress.value=arr[inte];

"inte" is a parameter (index of combo) I am passing to the function


The problem is solved !


:) :) :) :) :)
THANK YOU SO MUCH



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum