-3

I'm trying to load a div from another html page, then fill it with values from my main html page. My div is correctly loaded and displayed, but it seems like it doesn't want to fill up. Here's what I have so far :

$("#valider").click(function() {
    $("#ag_pub_panneau_detail_html").load( "https://tc610/ag_pub_collecte/Ag_pub_panneau_detail.html #ag_pub_panneau_detail_master_div");
    $("#ag_pub_panneau_detail_html").show();
});

So when I click on the "valider" button, my div is loaded and displayed, so far so good.

And here's where I'm struggling, I tried this :

if ($('ag_pub_panneau_detail_html').is(':visible')) {
    $('#ag_pub_panneau_entityid').val($('#ag_id_panneau').val());
}

but the div stays blank. So I tried this instead :

$("#valider").click(function() {
    $("#ag_pub_panneau_detail_html").load( "https://tc610/ag_pub_collecte/Ag_pub_panneau_detail.html #ag_pub_panneau_detail_master_div", fillDiv());
    $("#ag_pub_panneau_detail_html").show();
});

function fillDiv(){
    $('#ag_pub_panneau_entityid').val($('#ag_id_panneau').val());
}

But I get the same result. So I tried something else :

$("#valider").click(function() {
    $("#ag_pub_panneau_detail_html").load( "https://tc610/ag_pub_collecte/Ag_pub_panneau_detail.html #ag_pub_panneau_detail_master_div");
    $("#ag_pub_panneau_detail_html").show();
    $('#ag_pub_panneau_entityid').val($('#ag_id_panneau').val());
});

I was thinking that since the .show() works well, I could add my line below it, but it doesn't seem to execute either.

So I used to think that this line :

$('#ag_pub_panneau_entityid').val($('#ag_id_panneau').val());

Was wrong but when I execute it from the Chrome console, the field is correctly filled... I don't know what's happening, and I'm out of ideas for my issue.

Is there something I'm doing wrong ?

I can provide more code/details if you want to, just ask me Any help would be greatly appreciated !

darzang
  • 156
  • 2
  • 17
  • Have you checked the console to ensure the AJAX request is working? You're probably being blocked by the Same Origin Policy – Rory McCrossan Mar 15 '17 at 10:52
  • Do you have an example page, this requires element inspection – Datadimension Mar 15 '17 at 10:52
  • What element type is `#ag_pub_panneau_entityid` A `div` does not have a `value` attribute. You have to use `.text()` or `.html()` instead – empiric Mar 15 '17 at 10:54
  • @RoryMcCrossan Sorry for my ignorance but how can I do this ? Can I see it from chrome DevTools using F12 ? – darzang Mar 15 '17 at 10:55
  • Yes - use the Network tab – Rory McCrossan Mar 15 '17 at 10:55
  • @DataMechanics I'd currently working on a fiddle to expose my issue. I'll edit my post when it's done – darzang Mar 15 '17 at 10:56
  • @RoryMcCrossan In the Network tab I have one thing : Ag_pub_panneau_detail.html with a status of 200 ( which is good right ? ) When I click on it and go to Response Tab I have the HTML corresponding to my div. Hope that's what you wanted me to find – darzang Mar 15 '17 at 11:12
  • Yes, it sounds like your code should be working. Are you sure the `#ag_pub_panneau_detail_master_div` element exists in the response text? – Rory McCrossan Mar 15 '17 at 11:13
  • @empiric #ag-pub-panneau-entityid is an input – darzang Mar 15 '17 at 11:13
  • @RoryMcCrossan Yeah it is the main div containing other div, and it is present in my response text – darzang Mar 15 '17 at 11:15

1 Answers1

-1

I managed to get it working, what I did is that I created a js file for the Ag_pub_panneau_detail.html page (the one that is loaded) in which I just wrote :

$(document).ready(function() 
{

$('#ag_pub_panneau_entityid').val(localStorage.getItem("ag_pub_panneau_entityid"));

}); 

And now it works like a charm :)

By the way, can I know why I have those downvotes on my question ?

Anyway thanks for your help !

darzang
  • 156
  • 2
  • 17