Jump to content
Sign in to follow this  
FooKelvin

Jquery return

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]

Share this post


Link to post
Share on other sites

The dates are stored in data, which is actually an array of dates so I don't know what you'd want to do if it returns more than one set of dates (if that's possible).

 

data[0].qstartDate
data[0].qendDate

Share this post


Link to post
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.

Edited by FooKelvin

Share this post


Link to post
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);
}
})
})

Share this post


Link to post
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"

Share this post


Link to post
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);
}
})
})
  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • 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.