Form Action and Javascript Conflict

need some help on this one…

I’m working with a form and a script to show alert…

I’m using this code to achieve this and its working fine:

        <input id="autocomplete" class="input_message" type="text" name="message" autocomplete="off" placeholder="...type your message" ><br/>                              
        <input id="input_send" class="input_send" type="submit" name="send" value="SEND">

but if i put some form method, the alert on my script is not working..

    <form enctype="multipart/form-data" method="post">
        <input id="autocomplete" class="input_message" type="text" name="message" autocomplete="off" placeholder="...type your message" ><br/>                              
        <input id="input_send" class="input_send" type="submit" name="send" value="SEND">
    </form> 

here is my script:

<div id="alertbox">
<script>
$(document).ready(function(){
    $('#input_send').click(function(){
        var post = $('#autocomplete').val();
        if(post==""){   
            alert('Enter Message Please');  
        }else{
        $('#loader').fadeIn(400).html('<img src="./loader.gif" align="absmiddle">&nbsp;<span class="loading">sending</span>');
        var datasend = "alert";
        $.ajax({
            type:'post',
            url:'./includes/alerts.php',
            data:datasend,
            cache:false,
            success:function(msg__){    
                $('#autocomplete').val('');
                $('#loader').hide();
                $('#alertbox').fadeIn('slow').prepend(msg__);
                $('#alerts').delay(5000).fadeOut('slow');   
            }
        });
        }
    })          
});
</script>
</div>

thanks in advance..


Source: forms

Leave a Reply