Im using a Dynamic Dependent Select Box within my jQuery validation form, although i have ran into a problem in regards to the remote check.
Firstly, i will explain the process of the Select Box.
An example,
Select Box 1 contains a list of countries: England, America, Australia. Once a user selects one of these countries, it will then populate the second select box with the cities within that country. Then the third select box will populate the towns within that city.
What i have currently got now is the script checking the database with raw results.
This is my javascript:
As you can see List1, List2, and List3 are the select box's. Once the user selects the option from the third select box (List3) it will then run a php script to check the database (im not sure if this is the proper way of doing it).
- <script type="text/javascript">
- $(function(){
- $("#register_form").validate({
- debug: false,
- rules: {
- List1: { required: true },
- List2: { required: true },
- List3: { required: true, remote: "check-team.php" },
- firstname: { required: true, maxlength: 14 },
- lastname: { required: true, maxlength: 14 },
- email: { maxlength: 32, remote: "check_email.php" },
- mobile: { required: true, minlength: 10, number: true, remote: "check_mobile.php" },
- password: { required: true, maxlength: 14 },
- password2: { required: true, equalTo: "#password" }
- },
- messages: {
- List3:{ remote: "Team already registered." },
- email:{ remote: "Already subscribed" },
- mobile:{ remote: "Mobile already registered." }
- },
- submitHandler: function(form) {
- // do other stuff for a valid form
- $.post('process.php', $("#register_form").serialize(), function(data) {
- $('.results').html(data);
- });
- }
- });
- });
- </script>
In my database i have 3 fields Country, City, Towns. The php script checks to see if the Country, City and Town have been registered as a whole unit.
- <?php include 'database.php'; ?>
- <?php
- $List1 = mysql_real_escape_string($_REQUEST['List1']);
- $List2 = mysql_real_escape_string($_REQUEST['List2']);
- $List3 = mysql_real_escape_string($_REQUEST['List3']);
- $sql = "SELECT COUNT(id) FROM users WHERE `country` = '".$List1."' AND `city` = '".$List2."' AND `town` = '".$List3."'";
- $results = mysql_query($sql) or die(mysql_error());
- if (mysql_result($results, 0) > 0) {
- echo "false";
- } else {
- echo "true";
- }
- ?>
Im not sure if I am doing this the right way but it doesn't seem to be working, although if i change the variables to raw existing data like this:
$List1 = 'Australia';
$List2 = 'Sydney';
$List3 = 'Newtown';
Doing it this way does seem to work. But using the request seems to have some kind of problem...
Here is my html aswell:
- <form id="register_form" action="#" method="POST">
- <table width="200" class="tableregister" cellpadding="7">
- <tr>
- <td valign="top"><input id="lastname" name="lastname" type="text" placeholder="Full Name" /></td>
- <td valign="top"><input id="email" class="email required" name="email" type="text" placeholder="Email Address" /></td>
- </tr>
- <tr>
- <td valign="top">
- <select id="List1" name='List1' onchange="fillSelect(this.value,this.form['List2'])" >
- <option value=''selected>Choose Region</option>
- </select>
- </td>
- <td valign="top"><input id="mobile" type="text" name="mobile" placeholder="Mobile Number"/></td>
- </tr>
- <tr>
- <td valign="top">
- <select id="List2" name='List2' onchange="fillSelect(this.value,this.form['List3'])">
- <option value=''selected>Choose Club</option>
- </select>
- </td>
- <td valign="top"><input id="password" name="password" type="password" placeholder="Password" /></td>
- </tr>
- <tr>
- <td valign="top">
- <select id="List3" name='List3' onchange="getValue(this.value, this.form['List2'].value, this.form['List1'].value)">
- <option value=''selected>Choose Club</option>
- </select>
- </td>
- <td valign="top"><input id="password2" name="password2" type="password" placeholder="Repeat Password" /></td>
- </tr>
- </table>
- </form>
Any help would be much appreciated. Thankyou so much.
Cheers