Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Oct 2002
    Location
    Mumbai,India
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I get information for selected item of a combo

    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

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    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>

  • #3
    New Coder
    Join Date
    Oct 2002
    Location
    Mumbai,India
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thanks for lightening reply

    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

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    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?

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts

    I understand now your question...

    You need the id in the option value in the server-side.
    Code:
    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.
    Code:
    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];
    }

  • #6
    New Coder
    Join Date
    Oct 2002
    Location
    Mumbai,India
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Your solution is perfect but..

    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>

  • #7
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What's this?
    You are not closing the opening option tag.......

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

  • #8
    New Coder
    Join Date
    Oct 2002
    Location
    Mumbai,India
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Only one problem and it's through

    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)

  • #9
    New Coder
    Join Date
    Oct 2002
    Location
    Mumbai,India
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Only one problem and it's through

    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)

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    How are you storing the addresses in the hidden field? What separator do you use?
    Code:
    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.

  • #11
    New Coder
    Join Date
    Oct 2002
    Location
    Mumbai,India
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks a lot for great help

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •