Jump to content
New Reality: Ads For Members ×

Jquery return


FooKelvin

Recommended Posts

Hi i have stuck with the ajax return success. Firstly let me explain what i going to do. i have a input form, the form have 3 field text. 1) start Date 2) end Date 3) quarter

the "quarter" field is a drop down list. i have a database to store the date of period of Q1,Q2,Q3,Q4. so i want to have, when a user select a drop down, the date will return the Q1 Period.

For now, i'am able to return the result like this: [{"qstartDate":"11/1/2014","qendDate":"1/31/2014"}]

But, when i wanted to return the date into my form, it fail. So, Here is my Code

$("#slc-quarter").change(function () {
    var quarter = $(this).val();
    $.ajax({
        url: "searchQuarterDetails.asp?term=" + quarter,
        success: function (data) {
                var a = qstartDate;
                alert(a)
            }
        //$("#qstartDate").val(ui.item.qstartDate);
        //$("#qendDate").val(ui.item.qendDate);
    })
})

The result that i get from this code after i change the drop down menu is: [object htmlinputelement]

Link to comment
https://forums.phpfreaks.com/topic/297939-jquery-return/
Share on other sites

Hi requinix,

 

i have two pages. 

select.asp and source.asp

 

select.asp contain of 3 field. on of the field is drop down list. so, when user select the drop down, it trigger ajax "url: "source.asp?term=" + quarter".

so the page of source.asp?term="+quarter" display:

 

[{qstartDate: "2/1/2015", qendDate: "4/30/2015", label: "Q2"}

    0{qstartDate: "2/1/2015", qendDate: "4/30/2015", label: "Q2"}

        label"Q2"

       qendDate"4/30/2015"

       qstartDate"2/1/2015"

 

I need to take the "qendDate" value and "qstartDate" value.

Link to comment
https://forums.phpfreaks.com/topic/297939-jquery-return/#findComment-1519708
Share on other sites

So something like this then?

$("#slc-quarter").change(function () {
var quarter = $(this).val();
$.ajax({
url: "searchQuarterDetails.asp?term=" + quarter,
success: function (data) {
$("#qstartDate").val(data[0].qstartDate);
$("#qendDate").val(data[0].qendDate);
}
})
})
Link to comment
https://forums.phpfreaks.com/topic/297939-jquery-return/#findComment-1519709
Share on other sites

Hi scootstah,

 

i tried but nothing appear in #qstartDate value.

i try to change to console for more details. 

 

like this,

success: function (data) {
                a = (data[0].qstartDate);
                console.log(a)
                $("#qendDate").val(data[0].qendDate);
            }

the console.log return "undefined"

Link to comment
https://forums.phpfreaks.com/topic/297939-jquery-return/#findComment-1519710
Share on other sites

Try:

$("#slc-quarter").change(function () {
var quarter = $(this).val();
$.ajax({
url: "searchQuarterDetails.asp?term=" + quarter,
dataType: 'json',
success: function (data) {
$("#qstartDate").val(data[0].qstartDate);
$("#qendDate").val(data[0].qendDate);
}
})
})
Link to comment
https://forums.phpfreaks.com/topic/297939-jquery-return/#findComment-1519739
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.