1

I'm trying to make WHOIS script that can display the availability of a domain name. I already have the PHP done. All I want is the jQuery part that could detect the change of the content of an input, send a POST request to a page and display the content of the page in a certain div.

Here's my HTML

<div class="input">
    <input type="text" name="domain" placeholder="monsiteweb.com"/>
</div>
<div id="result">
</div>

The jQuery I have right now (not working)

<script>
$(document).ready(function(){
    $("input[name=domain]").change(function () { 
        alert("Changed!"); 
});
</script>

Thanks a lot

jpmonette
  • 926
  • 1
  • 15
  • 30

3 Answers3

2

You are missing one close brackets there:

<script>
$(document).ready(function(){
    $("input[name=domain]").change(function () { 
        alert("Changed!"); 
    });
});
</script>

Also, do not forget that you only get the alert after leaving the field.

samura
  • 4,375
  • 1
  • 19
  • 26
2

basically:

$("input[name=domain]").change(function () { 
    $.post('script.php', { query: $(this).val() }, function(data) {
          $('#result').html(data);
    });
});

then have your PHP script check $_POST['query'] for the user's input.

Marc B
  • 356,200
  • 43
  • 426
  • 500
1

You have opened some brackets, that are not closed:

<script>
$(document).ready(function(){
    $("input[name=domain]").change(function () { 
        alert("Changed!"); 
    });
});
</script>
Dmitrii Tarasov
  • 414
  • 2
  • 13