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
form submission without refresh
Moderator: General Moderators
Re: form submission without refresh
AJAX Tutorial should tell you everything you need to know.
Re: form submission without refresh
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
http://www.youtube.com/watch?v=BwExOhVaUyk
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Re: form submission without refresh
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
JS
the form code
i am thinking the problem is with the js and or php.
once this is done then it will work like i want
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>
once this is done then it will work like i want
Re: form submission without refresh
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?
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Re: form submission without refresh
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
I used PHP to get that, i figured the code on my own and does what i need it to.
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156