Page 1 of 1

form submission without refresh

Posted: Fri May 27, 2011 10:31 am
by nite4000
I have a form that checks the database for the what is typed into the box which would be www.domainname.com i need to submit this without refresh and have it give 1 of 3 msgs domain is valid,domain is not valid or enter a domain(if box is left empty)

if anyone can help me out thanks

Re: form submission without refresh

Posted: Fri May 27, 2011 12:24 pm
by oscardog
AJAX Tutorial should tell you everything you need to know.

Re: form submission without refresh

Posted: Sat May 28, 2011 2:46 pm
by Pazuzu156
This should help you. jQuery with AJAX. It's for a contact form but you can incorporate it into any form you wish.

http://www.youtube.com/watch?v=BwExOhVaUyk

Re: form submission without refresh

Posted: Sun May 29, 2011 1:36 pm
by nite4000
That helped some but its not helping with what i need. I need to basically chk the database for a domain name which is entered into a text box and have it display a msg of either valid if its in the db or not valid if its not found.

i did manage to find the code i needed however its telling me a domain is not valid when its in the database and telling me its not valid when its not i need to make it say its valid if its found.

here is the code

first the php

Code: Select all

//get the username
	$domain = $_POST['domain'];
//mysql query to select field username if it's equal to the username that we check '
$result = mysql_query("select * from license where domain = '. $domain .'");

//if number of rows fields is bigger them 0 that means it's NOT available '
if(mysql_num_rows($result)< 0){
	//and we send 0 to the ajax request
	echo 0;
}else{
	//else if it's not bigger then 0, then it's available '
	//and we send 1 to the ajax request
	echo 1;
}


JS

Code: Select all

<script type="text/javascript">
$(document).ready(function() {

		//the min chars for username
		var min_chars = 10;

		//result texts
		var characters_error = 'Minimum amount of chars is 10';
		var checking_html = 'Checking...';

		//when button is clicked
		$('#check_username_availability').click(function(){
			//run the character number check
			if($('#domain').val().length < min_chars){
				//if it's bellow the minimum show characters_error text '
				$('#username_availability_result').html(characters_error);
			}else{
				//else show the cheking_text and run the function to check
				$('#username_availability_result').html(checking_html);
				check_availability();
			}
		});

  });

//function to check username availability
function check_availability(){

		//get the username
		var domain = $('#domain').val();

		//use ajax to run the check
		$.post("index.php", { domain: domain },
			function(result){
				//if the result is 1
				if(result == 1){
					//show that the domain is licensed
					$('#username_availability_result').html(domain + ' is  licensed');
				}else{
					//show that the domain is NOT licensed
					$('#username_availability_result').html(domain + ' is  not licensed');
				}
		});

}

</script>

the form code

Code: Select all

<input type='text' id='domain'> <input type='button' id='check_username_availability' value='Check Availability'>
<div id='username_availability_result'></div>

i am thinking the problem is with the js and or php.

once this is done then it will work like i want

Re: form submission without refresh

Posted: Sun May 29, 2011 8:35 pm
by Pazuzu156
OK now that's the issue I have. In my registration form I want to check if the username the user entered is in use or not based on the usernames entered into the database. Is that anything like the issue you have?

Re: form submission without refresh

Posted: Tue May 31, 2011 6:31 am
by nite4000
yeah but i managed to find another js/ajax solution. so i got it working not like i want but does the job

Re: form submission without refresh

Posted: Wed Jun 01, 2011 1:21 pm
by Pazuzu156
I used PHP to get that, i figured the code on my own and does what i need it to.