What I want to do:
When I click on a submit button (which goes to for example Google) my script should...
- append a "loading.gif" to a DIV with the ID = #loading to simulate that the page is loading and after that
- check if the user filled out a form correctly. If not, a popup should appear.
- After that it should go to GOOGLE
I know it is quite easy but I can't find the mistake in my code so far. My JSFiddle: http://jsfiddle.net/cZshY/
Example If someone puts the wrong university (Berlin instead of Hamburg) into the "university" field this should happen:
- A loading.gif should appear.
- After that a message should pop-up ("wrong university")
My HTML:
<div>
<form>
<p>Nickname: <input name="name" type="text" id="nickname"></p>
<p>University: <input name="university" type="text" id="univer" value="University of Berlin">
<p>Login: <input name="login" type="text" id="loginData" value="LE_StuRa"></p>
<p>Password:<input name="passwordfield" type="password" id="passw" value="34kle1"></p>
</form>
</div>
<div id="loading"></div>
<form action="http://google.com">
<input type="submit" value="Continue" id="googleButton">
</form>
My Javascript/jquery:
$(document).ready(function(){
$("#googleButton").click(function(){
var load = $("<img src='http://www.tj-auctions.com/images/loading.gif'/>");
$(load).prependTo("#loading").fadeOut(3000, function(){
if ( $("#loginData").val() != "LE_StuRa" || $("#univer").val() != "University of Hamburg" ) {
alert ("Wrong login data");
return false;
};
if ( $("#passw").val() != "34kle1" ) {
alert ("Wrong password");
return false;
};
if ( !$("#nickname").val() ) {
alert ("Please enter a nickname!");
return false;
});
});
});
});