Search code examples
phpjavascriptconfirmation

display message with array data in confirmation box


i wants to show custom message in confirmation box like

var response=confirm(Are you sure you want to select these times?

1)3a.m to 4a.m

2)8a.m to 9a.m

so on...)

this data i am getting from php page in json format in multidimensional array on ajax success and i wants to show this json data by iterating, as message. data i am getting w'll be like [{'start_time':3a.m,'end_time':4a.m}{'start_time':8a.m,'end_time':9a.m}....]

Can anyone help me in this.

Thanks in advance


Solution

  • var data = [{'start_time':'3a.m','end_time':'4a.m'},{'start_time':'8a.m','end_time':'9a.m'}];
    
    var alertText = "Are you sure you want to select these times?\n"
    for(var i in data) {
        alertText += data[i].start_time+ " to "+ data[i].end_time +"\n";
    }
    var response = confirm( alertText );
    

    You can do this. This is show alert as you want.I give you only example using your data.