Jump to content

jimmyt1988

Members
  • Posts

    81
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jimmyt1988's Achievements

Member

Member (2/5)

0

Reputation

  1. YEHAAAAAAA WOOPEEEEE WIPPEEEEEe, YIPPEEE DOO DAAAAAA, YIPPEEEDEE DAYYY... $.ajax({ type: "POST", url: "registration-post.php", data: type + "=" + process + "&check=2", async: false, success: function(data){ var returnedValue = $.trim(data); if(returnedValue=="ok"){ $(obj).css(registration.errorNotificationType, registration.validatedColour); }else{ registration.validationCollection.push(returnedValue); //$('.error').append(returnedValue + "<br />"); $(obj).css(registration.errorNotificationType, registration.errorColour); registration.progress = false; alert(registration.progress); } } }); async: false LOLLLLLL!!!! OMG everything just works perfect.. YEHAAAAAA, finit!
  2. Any ideas of simulating an ajax callback. Only when the information comes back or fails should it continue through my functions? Perhaps i'm too tired. i guess ill have a sleep soon.
  3. <td> <input onfocus = "this.style.background = 'url(blank.png) no-repeat'" onblur = "this.style.background = 'url(original.png) no-repeat'" type="text" name="user" maxlength="30" value="" id="userbox"> </td> <td> <input onfocus = "this.style.background = 'url(blank.png) no-repeat'" onblur = "this.style.background = 'url(original.png) no-repeat'" type="password" name="pass" maxlength="30" value="" id="passbox"> </td>
  4. I think its safe to say that the ajax call is taking its sweet time. The alert must give it that extra pause that it requires.
  5. Well. You have a selection of ajax, php and jquery libraries that you'll require. on the onchange event, you can call a function() that does a $.post - http://api.jquery.com/jQuery.post/ to a php file. That php file can do all the datbase work and exit() or return() the code you need, back to the html page you started at. Good luck.
  6. try this: <td> <input onfocus = "this.style.background = 'url(blank.png)'" onblur = "this.style.background = 'url(original.png)'" type="text" name="user" maxlength="30" value="" id="userbox"> </td> <td> <input onfocus = "this.style.background = 'url(blank.png)'" onblur = "this.style.background = 'url(original.png)'" type="password" name="pass" maxlength="30" value="" id="passbox"> </td>
  7. can you also include the functions: $this->baseURL $this->addParameter The function you have included is part of an object. $this-> refers to its neighbouring functions. That means that in the object there are 2 functions more we need. They are the above. Cheers in advance!
  8. What are you returning from your php script? Can you include the php here too
  9. -tr's cannot have widths and heights set. -td's cannot have a height of 0, otherwise they'll collapse into one column. -Best way to do it is to include divs inside each cell... Try this: <html> <head> <title>the title</title> <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.pack.js"></script> <script type="text/javascript" language="javascript"> $(document).ready( function(){ $("#hide").click( function(){ $("tr.target td div").slideUp("slow", function(){ //$(this).parent().parent().fadeOut(); }); } ); $("#show").click( function(){ $(".target").show("slow"); } ); } ); </script> <style> p{ background-color:#bca; width:200px; border:1px solid green; } div{ width:auto; height:auto; background:red; } table, td, tr{ } </style> </head> <body> <button id="hide"> Hide </button> <button id="show"> Show</button> <table> <tr><td>1</td><td>1</td><td>1</td></tr> <tr><td>1</td><td>1</td><td>1</td></tr> <tr class="target"><td><div>1</div></td><td><div>1</div></td><td><div>1</div></td></tr> <tr><td>1</td><td>1</td><td>1</td></tr> </table> <div class="target"> </div> </body> </html>
  10. Well, I'm not sure what the context of your code is but here's a start on what I think you need to know: $(element name).each( function(index){ if(index==3){ //do something if the current iteration = 3 } } ); .each in jQuery is a way to iterate through all the elements that have the element name you have assigned in the selector: http://api.jquery.com/each/
  11. registration.validate() is called. var registration = { flushErrors: function(){ $('form[name=registrationForm] .error').html(""); this.errorCollection = []; this.errorMessage = ""; this.validationCollection = []; this.validationErrorMessage = ""; this.progress = true; }, sanitiseField: /([A-Za-z0-9\_\-\.])$/, usernameMinimumChar: 5, passwordMinimumChar: 6, errorColour: "#F46C38", errorNotificationType: "border-color", errorCollection: [], errorMessage: "", errorPrefix: "Please fill in the following missing fields: ", validationCollection: [], validationErrorMessage: "", validatedColour: "#F0F0F0", progress: true, ajaxCall: function(process, obj, type){ $.post("registration-post.php", type + "=" + process + "&check=1", function(data){ var returnedValue = $.trim(data); if(returnedValue==""){ $(obj).css(registration.errorNotificationType, registration.validatedColour); }else{ //1 alert(returnedValue); registration.validationCollection.push(String(returnedValue)); //$('.error').append(returnedValue + "<br />"); $(obj).css(registration.errorNotificationType, registration.errorColour); registration.progress = false; } } ); }, emailValidation: function(email, obj, type){ var filter = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if(!filter.test(email)){ this.validationCollection.push("The email address you have entered does not seem to be a valid entry"); $(obj).css(registration.errorNotificationType, registration.errorColour); this.progress = false; }else{ $(obj).css(registration.errorNotificationType, registration.validatedColour); } this.ajaxCall(email, obj, type); }, usernameValidation: function(username, obj, type){ if(!this.sanitiseField.test(username)){ this.validationCollection.push("Your username must only contain (A-Z, a-z, 0-9, _, -, .). Please try again."); $(obj).css(registration.errorNotificationType, registration.errorColour); this.progress = false; }else{ $(obj).css(registration.errorNotificationType, registration.validatedColour); } if(username.length < this.usernameMinimumChar){ this.validationCollection.push("Your username must contain atleast " + this.usernameMinimumChar + " characters"); $(obj).css(registration.errorNotificationType, registration.errorColour); this.progress = false; }else{ $(obj).css(registration.errorNotificationType, registration.validatedColour); } this.ajaxCall(username, obj, type); }, passwordValidation: function(password, obj){ if(!this.sanitiseField.test(password)){ this.validationCollection.push("Your password must only contain (A-Z, a-z, 0-9, _, -, .). Please try again."); $(obj).css(registration.errorNotificationType, registration.errorColour); this.progress = false; }else{ $(obj).css(registration.errorNotificationType, registration.validatedColour); } if(password.length < this.passwordMinimumChar){ this.validationCollection.push("Your password must contain atleast " + this.passwordMinimumChar + " characters"); $(obj).css(registration.errorNotificationType, registration.errorColour); this.progress = false; }else{ $(obj).css(registration.errorNotificationType, registration.validatedColour); if(password!=$('#registerUser input[name=confirmPassword]').val()){ this.validationCollection.push("Your confirmation password does not match your chosen password"); $($('#registerUser input[name=confirmPassword]').val()).css(registration.errorNotificationType, registration.errorColour); this.progress = false; }else{ $($('#registerUser input[name=confirmPassword]').val()).css(registration.errorNotificationType, registration.validatedColour); } } }, validate: function(){ this.flushErrors(); $('#registerUser input[type=text], #registerUser input[type=password]').each( function(){ if($(this).val() == ""){ $(this).css(registration.errorNotificationType, registration.errorColour); //registration.errorCollection.push($(this).parent().prev().text().replace(": ", "")); registration.errorCollection.push($(this).parent().prev().text()); registration.progress = false; }else{ switch($(this).attr("name")){ case "email": registration.emailValidation($(this).val(), $(this), $(this).attr("name")); break; case "username": registration.usernameValidation($(this).val(), $(this), $(this).attr("name")); break; case "password": registration.passwordValidation($(this).val(), $(this)); break; default: $(this).css(registration.errorNotificationType, registration.validatedColour); } } } ); if(this.progress){ return this.progress; }else{ for (var i=0; i<this.errorCollection.length; i++){ if(i==(this.errorCollection.length)-1){ this.errorMessage += this.errorCollection; }else{ this.errorMessage += this.errorCollection + ", "; } } //2 alert(""); for (var i=0; i<this.validationCollection.length;i++){ if(i==(this.validationCollection.length)-1){ this.validationErrorMessage += this.validationCollection; }else{ this.validationErrorMessage += this.validationCollection + "<br />"; } } if(this.errorMessage == ""){ $('form[name=registrationForm] .error').html(this.validationErrorMessage); }else{ $('form[name=registrationForm] .error').html(this.errorPrefix + this.errorMessage + "<br />" + this.validationErrorMessage); } } return this.progress; } } 1st red highlighted code: the alert returns "The email you have entered is already registered. Please try another!". I push it into an array... 2nd red highlighted code: If i do not call an alert just before itterating through my array, the array contains nothing.. If I itterate through it just after an alert(""); the array works fine. explain
  12. Ah I see... Because I added *check=1 to the ajax, my little for loop is putting 2 post datas into the mysql. Anyway of removing a Post entry from the Post array
  13. function checkDuplication(){ $this->connection = new connection(); $this->connection->connect(); //$this->loadData(); if(count($_POST) > 0){ $keys = array_keys($_POST); foreach($keys As $field){ $postData = $_POST[$field]; $postField = $field; } } //line 97 $matchUser = mysql_num_rows(mysql_query("SELECT " . $postField . " FROM " . $this->table . " WHERE '" . $postField . "' = '" . $postData . "'")); if($matchUser>=1){ exit("The " . $postField . " you have entered is already registered. Please try another!"); }else{ $this->validationBool = true; exit(); } } I call this duplication function twice... once to check if the email is duplicate, and once to check if username is duplicate.. these function triggers are sent from ajax posts. Why would I be getting the error: Warning: mysql_num_rows() expects exactly 1 parameter, 2 given in D:\InstallationFiles\wamp\www\*****.co.uk\www\*****.php on line 97
  14. Hi all, Is there a way to get jquery ajax to run a specific PHP function. At the moment Im sending extra paramaters like check=1: ajaxCall: function(process, obj, type){ $.post("registration-post.php", type + "=" + process + "&check=1", function(data){ alert(data); if(data==""){ $(obj).css(registration.errorNotificationType, registration.validatedColour); }else{ //registration.validationCollection.push($.trim(data)); $('.error').append($.trim(data) + "<br />"); $(obj).css(registration.errorNotificationType, registration.errorColour); registration.progress = false; } } ); } then doing an if statement, if($_POST["check"]==1){ $registration->checkDuplication(); } if($registration->validationBool){ $registration->validateFields(); } but its not really doing the job i need it to do. I'm a little stuck in my own battle to make cleaner coding
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.