www.webdeveloper.com
Results 1 to 4 of 4

Thread: Attention to all expert coders - why the **** does this not work?!

  1. #1
    Join Date
    Aug 2011
    Location
    Worthing, West Sussex
    Posts
    96

    Exclamation Attention to all expert coders - why the **** does this not work?!

    Just the part that says 'this works, but this doesn\'t'! Don't understand why the alert gives the data back (so the AJAX is fine) but the error handling doesn't work properly. Any suggestions?

    HTML Code:
    $(document).ready(function() {
    	$("#sit_date").datepicker();
    	$("select[name='usertype']").change(function() {
    		if($(this).val()=="0") {
    			$(".indv").slideUp(500);
    			$(".comp").slideDown(500);
    		} else {
    			$(".indv").slideDown(500);
    			$(".comp").slideUp(500);
    		}
    	});
    	$("input[name='marka'],input[name='markb']").bind("keypress paste keyup  blur focus", function() {
    		var marka = $("input[name='marka']").val();
    		var markb = $("input[name='markb']").val();
    		var perc = (marka/markb)*100;
    		if(perc>0 && perc<=100) {
    			$("#per").html(Math.round(perc));
    		} else {
    			$("#per").html("");
    		}
    	});
    	$("input[name='vcode']").bind("keypress keyup paste blur focus", function() {
    		$.post("include/ajax.php", { type: "checkVoucher", vcode: $(this).val() }, function(data) {
    			$("input[name='group']").val(data);
    		});
    		$.post("include/ajax.php", { type: "checkType", vcode: $(this).val() }, function(data) {
    			$("input[name='certificates']").val(data);
    		});
    	});
    	
    	
    	/*
    	//fix for fast typing/duplicate results with time() as request number
    	var latestRequestNumber = 0;
    	$.ajax({
    		type: "POST",
    		url: "include/ajax.php",
    		data: {company : serchval, requestNumber: ++latestRequestNumber},
    		success: function(data) {
    			var results = (JSON.parse(data));
    			if (results.requestNumber < latestRequestNumber) return;
    			// ... otherwise, display results from this response ...
    		}
    	});
    	*/
    	
    	
    	$("input[name='wbn']").bind("keypress keyup paste blur focus", function() {
    		$.post("include/ajax.php", { type: "getAssessment", wbn: $(this).val() }, function(data) {
    			if(data!="") {
    				$("select[name='assessment']").html(data);
    			}
    		});
    	});
    	
    	$("input[name='manual_add']").click(function() {
    		var list = "";
    		var error=0;
    		if($("input[name='fname']").val() == "") {
    			list = list + "<li>The first name field is blank</li>";
    			error++;
    		}
    		if($("input[name='lname']").val() == "") {
    			list = list + "<li>The last name field is blank</li>";
    			error++;
    		}
    		
    		var wbn = $("input[name='wbn']").val();
    		if(wbn == "") {
    			list = list + "<li>The workbook number field is blank</li>";
    			error++;
    		} else {
    			$.post("include/ajax.php", { type: "workbookNumber", wbn: wbn }, function(data) {
    				alert("This result works: " + data);
    				list = list + "<li>This result doesn't work:" + data + "</li>";
    				error++;
    				/*
    				if(data=="duplicate") {
    					$(".alert").slideDown(500);
    				} else {
    					list = list + "<li>" + data + "</li>";
    					error++;
    				}
    				*/
    			});
    		}
    		
    		if($("select[name='usertype']").val() == 0) {
    			if($("input[name='vcode']").val() == "") {
    				list = list + "<li>The voucher code field is blank</li>";
    				error++;
    			} else {
    				$.post("include/ajax.php", { type: "findVoucher", vcode: $("input[name='vcode']").val() }, function(data) {
    					if(data == "none") {
    						list = list + "<li>The voucher code does not exist</li>";
    						error++;
    					}
    				});
    			}
    		}
    		
    		
    		/*
    		if($("input[name='wbn']").val() != "") {
    			list = list + "<li>The workbook number field is blank</li>";
    			error++;
    		} else {
    			$.post("include/ajax.php", { type: "checkUsed", wbn: $("input[name='wbn']").val() }, function(data) {
    				alert(data);
    					list = list + "<li>"+data+"</li>";
    					error++;
    				if(data == "none") {
    					list = list + "<li>The workbook number does not exist</li>";
    					error++;
    				}
    				var arr = data.split('/');
    				
    				//problem here?
    				if(arr[0] != "0" && arr[2] != "0000-00-00 00:00:00") {
    					
    					list = list + "<li>The workbook code has already ben used.</li>";
    					error++;
    					$.post("include/ajax.php", { type: "checkNames", userid: arr[0], type: arr[1], fname: $("input[name='fname']").val(), lname: $("input[name='lname']").val() }, function(data) {
    						if(data == "") {
    							list = list + "<li>The workbook code has already ben used.</li>";
    							error++;
    							if(arr[1] == "0") {
    								list = list + "<li>This workbook number has been used by an online assessment user. If this is another attempt, please ensure the first and last names are correct.</li>";
    								error++;
    							}
    							if(arr[1] == "1") {
    								list = list + "<li>This workbook number has already been used by a manual assessment user. If this is another attempt, please ensure the first and last names are correct.</li>";
    								error++;
    							}
    						} else {
    							// work out what you're gonna do with the duplicate
    							// this workbook number has already been used, is this a duplicate or not? popup window thing... maybe if error==0, then test to see if the user exists with the same name and ask for duplicate with different box...
    							$(".alert").slideDown(500);
    						}
    					});
    				}
    			});
    		}
    		*/
    		
    		if(($("input[name='questions']").val() == "") && ($("input[name='marka']").val() != $("input[name='markb']").val())) {
    			list = list + "<li>The questions wrong field is blank</li>";
    			error++;
    		}
    		
    		if(error>0) {
    			$(".error").slideUp(500);
    			$(".jquery-error ul").html("").append(list);
    			$(".jquery-error").slideDown(500);
    		} else {
    			$("form").submit();
    		}
    	});
    });
    Titanium Web Designs Ltd - Bespoke websites and online systems

  2. #2
    Join Date
    Jan 2005
    Posts
    360
    You say that this does not work properly - can you elaborate on what does and doesn't happen, and what you expect it to do?

  3. #3
    Join Date
    Aug 2011
    Location
    Worthing, West Sussex
    Posts
    96
    Where the alert shows the error inside the post function, and the list gets added to the variable, basically the alert shows the data but the list and error variables do not work at all. It's as if they're not there.
    Titanium Web Designs Ltd - Bespoke websites and online systems

  4. #4
    Join Date
    Jan 2005
    Posts
    360
    I'm not convinced that your 'list' variable is in the same scope when you try to add to it, as when you try to read it - try Alert()ing that and check that it isn't a local/shadow variable.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles