1
function getData(des, poid, divid){
            $.ajax({
                type: 'GET',
                url: 'loaddata.php?des=' + des + '&poid='+poid, //call storeemdata.php to store form data

                success: function(data) {
                    var ajaxDisplay = document.getElementById(divid);
                    ajaxDisplay.innerHTML = data;
                }
            });
        }

//Function call
<select name="descr" id="descr" onchange="getData(this.value,this.value,   'displaydata')">

This is the code and I passed multiple values in url. when I try to echo those values in next page it echo only one value (des) two times.Any help would be appreciated.

$slno = $_GET['des'];
$poid = $_GET['poid'];
echo $slno;
echo $poid;
4
  • also post code where the getData() will get call... Commented Jan 24, 2017 at 5:56
  • I agree that it seems like the error is in the actual calling of getData can you see the url being called in the request? Commented Jan 24, 2017 at 6:00
  • <select name="descr" id="descr" onchange="getData(this.value,this.value, 'displaydata')"> This is the code @pAsh Commented Jan 24, 2017 at 6:00
  • 1
    your answer shows your passing the same variable (this.value) twice Commented Jan 24, 2017 at 6:01

3 Answers 3

1

<select name="descr" id="descr" onchange="getData(this.value,this.value, 'displaydata')">

The issue is that in the display data function you are setting the des and poid url variables to the same value as shown in your code above.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for feedback @jesse. Can you please show me how to?
for the second parameter it would be a long line becase you would need to get the value of the other select with document.getElementbyid
Thanks @jesse. I'll try that and let you know if it worked.
1

You should pass ass second param inner text from option tag instead of the same value. To do this you can just use:

$(this).find('option:selected').text();

3 Comments

Thanks @Arkowsky. I'm trying to pass another value from another dropdown as well. I don't this this will work.
Can you show us more code? I mean how did you try implement this passing text from option in html
First I choose poid from a drop down and by matching poid I fetched des in another drop down. On selecting des these values should be passed by ajax. poid <select name="poid" onchange="javascript: submit()" > It reloads page and fetxh data in des.. des <select name="descr" id="descr" onchange="getData(this.value,this.value, 'displaydata')">
0

I found a way to do it. Thanks to everyone who looked into it to help me. Here is the code and it works like a charm.

function getData(des, divid){
    var poid = $("select[name='poid']").val();//this line pass second value "poid" in my case
            $.ajax({
                type: 'GET',
                url: 'loaddata.php?',
                data: {des : des, poid : poid},
                success: function(data) {
                    var ajaxDisplay = document.getElementById(divid);
                    ajaxDisplay.innerHTML = data;
                }
            });
        }

function call

<select name="des" id="des" onchange="getData(this.value, 'displaydata')">

ajax.php file

$slno = $_GET['des'];
$pid1 = $_GET['poid'];
echo $slno;
echo $pid1;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.