/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] loading gif when pressed submit

Hello,

I’m trying through a form to display a loading gif when pressed the submit button.

I’ve found on the net this code, but something is wrong.

If a keep the [B]id=”form33″[/B] I can see my loading.gif displayed in place of the submit button, but nothing else happen, form not send.
If I delete [B]id=”form33″[/B], I don’t see anymore the loading gif, but my form is correctly sent and after few seconds ping2.php is opened..

[CODE]<script type=”text/javascript”>
function EnvoiMessage() {

$(this).submit();
document.getElementById(‘form33’).innerHTML = ‘<img src=”img/loading.gif” alt=”Loading…” />’;
}

</script>[/CODE]

[CODE]<form id=”form33″ action=”ping2.php” method=”post”>
<p>
<input type=”hidden” id=”router_ip” name=”router_ip” value=”<?php echo $donnees[‘router_ip’]; ?>” />
<input type=”submit” name=”submit” id=”submit” onclick=”EnvoiMessage()” value=”Ping”/>
</p>
</form>[/CODE]

what’s wrong with this javascript code?
How can I display a loading gif during the loading of the page?

Thanks for your help

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorMay 23.2011 — The loaded page is ping2.php so that you should write the javascript code there. JavaScript is a client-side language, thus changing the session (ans the submit action changes the session) will make all the JavaScript changes lost.
Copy linkTweet thisAlerts:
@hhmauthorMay 25.2011 — Hi,

problem solved with:

[CODE]<!-- Un bouton avec '+' dedans, et un onclick qui appelle une fonction avec -->
<!-- en param le bouton et l'id du div à afficher/masquer. -->
<button type="button" onclick="toggle_div(this,'id_du_div');">+</button>

<!-- Un div caché avec un attribut id -->
<div id="id_du_div" style="display:none;">
Yop yop yop yop yop yop yop yop
</div>

<!-- Le JS... -->
<script type="text/javascript">
function toggle_div(bouton, id) { // On déclare la fonction toggle_div qui prend en param le bouton et un id
var div = document.getElementById(id); // On récupère le div ciblé grâce à l'id
if(div.style.display=="none") { // Si le div est masqué...
div.style.display = "block"; // ... on l'affiche...
bouton.innerHTML = "-"; // ... et on change le contenu du bouton.
} else { // S'il est visible...
div.style.display = "none"; // ... on le masque...
bouton.innerHTML = "+"; // ... et on change le contenu du bouton.
}
}
</script>
[/CODE]


thx again for your help ?
×

Success!

Help @hhm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...