2 Replies - 702 Views - Last Post: 29 August 2012 - 07:01 PM

#1 JDeveloper.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 31-August 11

Validate Form without refreshing "radiobutton doesn't work"

Posted 29 August 2012 - 05:51 PM

Hello
I need help i found this tutorial http://net.tutsplus....h-using-jquery/ for validating form without refreshing but the problem is i think this is for just text fields :) but i'm using 4 different radiobuttons i really need this script to work with these radiobutton !

here is the javascript file :) !
$(function() {		
		  $('.error').hide();  
		  
		  $(".button").click(function() {  
			// validate and process form here  
			  
			$('.error').hide(); 

			
			  var name = $("input#name").val();  
				if (name == "") {  
			  $("label#name_error").show();  
			  $("input#name").focus();  
			  return false;  
			}  
				var email = $("input#email").val();  
				if (email == "") {  
			  $("label#email_error").show();  
			  $("input#email").focus();  
			  return false;  
			}  
				var mobile = $("input#mobile").val();  
				if (mobile == "") {  
			  $("label#mobile_error").show();  
			  $("input#mobile").focus();  
			  return false;  
			}  
			 var college = $("input#college").val();  
				if (college == "") {  
			  $("label#college_error").show();  
			  $("input#college").focus();  
			  return false;  
			}  var university = $("input#university").val();  
				if (university == "") {  
			  $("label#university_error").show();  
			  $("input#university").focus();  
			  return false;  
			}  var level = $("input#level").val();  
				if (level == "") {  
			  $("label#level_error").show();  
			  $("input#level").focus();  
			  return false;  
			}  var first_preference = $("input#first_preference").val();  
				if (first_preference == "") {  
			  $("label#first_preference_error").show();  
			  $("input#first_preference").focus();  
			  return false;  
			}  var second_preference = $("input#second_preference").val();  
				if (second_preference == "") {  
			  $("label#second_preference_error").show();  
			  $("input#second_preference").focus();  
			  return false;  
			}  var third_preference = $("input#third_preference").val();  
				if (third_preference == "") {  
			  $("label#third_preference_error").show();  
			  $("input#third_preference").focus();  
			  return false;  
			}  var heard = $("input#heard").val();  
				if (heard == "") {  
			  $("label#heard_error").show();  
			  $("input#heard").focus();  
			  return false;  
			} 	var applying = $("input#applying").val();  
				if (applying == "") {  
			  $("label#applying_error").show();  
			  $("input#applying").focus();  
			  return false;  
			}	var strength = $("input#strength").val();  
				if (strength == "") {  
			  $("label#strength_error").show();  
			  $("input#strength").focus();  
			  return false;  
			}	var weakness = $("input#weakness").val();  
				if (weakness == "") {  
			  $("label#weakness_error").show();  
			  $("input#weakness").focus();  
			  return false;  
			}	var previousEx = $("input#previousEx").val();  
				if (previousEx == "") {  
			  $("label#previousEx_error").show();  
			  $("input#previousEx").focus();  
			  return false;  
			}   
		
		
			
		var dataString = 'name='+ name + '&email=' + email + '&mobile=' + mobile + '&college=' + college + '&university=' + university + '&level=' + level + '&first_preference=' + first_preference + '&second_preference=' + second_preference + '&third_preference=' + third_preference + '&heard=' + heard + '&applying=' + applying + '&strength=' + strength + '&weakness=' + weakness + '&previousEx=' + previousEx;
		$.ajax({
			  type: "POST",
			  url: "php/database_sorting.php",
			  data: dataString,
			  success: function() {
				$('#contact_form').html("<div id='message'></div>");
				$('#message').html("<h2>Contact Form Submitted!</h2>")
				.append("<p>We will be in touch soon.</p>")
				.hide()
				.fadeIn(1500, function() {
				  $('#message').append("<img id='checkmark' src='images/done.png' />");
				});
			  }
		});
			return false;
			});
});
		runonload(function(){
		  $("input#name").select().focus();
		});


This post has been edited by JDeveloper.: 29 August 2012 - 05:56 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Validate Form without refreshing "radiobutton doesn't work"

#2 calvinthedestroyer  Icon User is offline

  • D.I.C Lover

Reputation: 167
  • View blog
  • Posts: 1,908
  • Joined: 13-October 07

Re: Validate Form without refreshing "radiobutton doesn't work"

Posted 29 August 2012 - 06:57 PM

Is this on a web site where I can see the whole page?

What kind of errors are you getting?

I only see one $(".button"), where are the other three?
Was This Post Helpful? 0
  • +
  • -

#3 JDeveloper.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 31-August 11

Re: Validate Form without refreshing "radiobutton doesn't work"

Posted 29 August 2012 - 07:01 PM

the only error this are not working for valdiating radio buttons but working with textfields :)
the website page is very normal just a form with radio buttons and textfields :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1