Knighto05 Knighto05 - 3 months ago 9
HTML Question

action after trigger click fired

I already checked out this post:
Perform an action after trigger('click') finishes firing?
But nothing I tried so far worked.

Suppose I have this menu in my page:

<ul class="nav nav-tabs">
<li role="presentation" id="home">
<span>
Home
</span>
</li>

<li role="presentation" id="user">
<span>
User
</span>
</li>
</ul>


When I click "user" tab, I get this content:

<button id="save-changes" role="button">Save it</button>
<form>
<input type="text" id="nom" name="nom" placeholder="Your Name">
<input type="text" id="prenom" name="prenom" placeholder="Your Surname">
<input type="text" id="login" name="login" placeholder="Your Login">
</form>


After submitting data, I'm redirected to "Home":

<div>
<div class="breadcrumb">
<div id="saved-success" style="display:none">
Data Saved successfully
</div>
</div>
<div class="content-body">
some stuff here...
</div>


I want the message inside the div "saved-success" to appear.
To manage the submit I have this jquery function:

$(document).on("click","#save-changes",function(){
dataarray = array(
login: $("#login").val();
nom: $("#nom").val();
prenom: $("#prenom").val();
);
$.post(getBaseUrl(true)+"/UserParam/saveUser",dataarray,function(){
$("#home").trigger("click");
$("#saved-success").css("display", "block");
});


I am successfully redirected to "home" but the div "saved-success" remain hidden. Need help from experts. How do I make the message to show after redirection?

Answer

Try this

$(document).on("click","#save-change",function(){
 dataarray = array(
    login: $("#login").val();
    nom: $("#nom").val();
    prenom: $("#prenom").val();
 );
 $.post(getBaseUrl(true)+"/UserParam/saveUser",dataarray,function(){
    $("#home").trigger("click");
    setTimeout(function(){
    document.getElementById("updated-success").style.display = "block";
    }},2000);
});