Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a table which consists of 2 columns, ContactName and Usertype. I have a dropdown list which consists of data from ContactName. When I select any value in the dropdown, its Usertype should be shown according to what was selected. Please help me. I have done this much so far. When I select any value in the dropdown, the same value is shown but I want the user type.

<?php
    if(!isset($_SESSION)) {
        session_start(); 
    }

    $dingo=$_SESSION['dingo'];
    $query11="Select ISO3,Notify,Dingoid from rahul_tbl_users where Dingoid=$dingo";
    $query123=mysql_query($query11);
    $query1234=mysql_fetch_array($query123);
    $fetch=mysql_query("SELECT tdd.Dingoid,tc.Dingoid,tc.A_End,tbidd.OpportunityNumber,        tbidd.Status,tbidd.Country,tbidd.OpportunityName,tbidd.Allocatedto,tbidd.Email,tbidd.Customer,tbidd.Country,tbidd.ContactName,tc.Usertype,tbidd.G1_OPPID
        FROM  scott123.rahul_tbl_users tdd inner join scott123.rahul_user_opps tc on
        tdd.Dingoid=tc.Dingoid Inner Join scott123.rahul_tbl_opportunities tbidd
        on tc.A_End=tbidd.OpportunityNumber
        WHERE tc.Dingoid =$dingo");
    $fetch_result=mysql_fetch_array($fetch);
?>

<form method="post" action="">

<?php
    $SQLString="SELECT distinct(G1_OPPID),ContactName from rahul_tbl_opportunities where G1_OPPID IS NOT NULL and ContactName!='' ";
    $result1 = mysql_query($SQLString); 
    $select_box='<select name="select1"  id="select1" onchange="javascript:load_value(this.value);">';
    $input="";

    while($rows1 = mysql_fetch_array($result1)) {  
        $select_box .='<option id="user_name" value="'.$rows1["ContactName"].'">'.$rows1['ContactName'].'</option>';  
    }

    $input ='<input type="text" name="test" id="test" value="" />';

    echo $select_box."</select>";
    echo $input;
?>

<input type="submit" name="submit_name11" value="Add Permission"/>
<input type="submit" name="submit_name12" value="Edit Permission"/>   
</form>
share|improve this question
 
DO you have something against my eyes? –  Qǝ uoɯᴉs May 25 at 19:29
 
where is the javascript you have tried? –  karthikr May 25 at 19:29
 
@karthikr The only JavaScript he wrote is the tag –  Qǝ uoɯᴉs May 25 at 19:30
 
You would have to include some javascript/jquery like this: stackoverflow.com/questions/11309817/… to achieve what you are looking for. Change the ids to the Ids you use in your implementation –  karthikr May 25 at 19:31
 
I am sorry here is my javascript code <script type="text/javascript"> function load_value(value) { document.getElementById("test").value=value; } </script> –  Rahul Deshmukh May 25 at 19:34
add comment

1 Answer

What I gather is you just want the textbox to display what is currently selected in the select box?

Change your onchange event in the select box to be:

onchange="transferValue();"

And add this script tag:

<script type="text/javascript">
    function transferValue(){
        var selectBox = document.getElementById("select1");
        var selectedOption = selectBox.options[selectBox.selectedIndex].value;
        var textBox = document.getElementById("test");
        textBox.value = selectedOption;
    }

    window.onload = function(){
        transferValue();
    };
</script>
share|improve this answer
 
No actually my textbox value is different than select box. –  Rahul Deshmukh May 25 at 21:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.