I have issued about submit button no function when is clicked.Anyone can help me to check which part I get wrong. Thanks.
<!-- contact form -->
<div class="col-lg-7 contact-right mt-lg-0 mt-5">
<div class="row">
<div class="col-lg-6 form-group pr-lg-2">
<input id="name" type="text" class="form-control" placeholder="Name" required="">
</div>
<div class="col-lg-6 form-group pl-lg-2">
<input id="email" type="email" class="form-control" placeholder="Email" required="">
</div>
</div>
<div class="form-group">
<input id="phone" type="text" class="form-control" placeholder="Phone" required="">
</div>
<div class="form-group">
<textarea id="message" class="form-control" placeholder="Message" required=""></textarea>
</div>
<button type="button" onclick="submit();" class="btn submit-contact-main ml-auto">Submit ok</button>
</div>
<!-- contact form -->
script function
<script>
function submit() {
//alert("Hello! I am an alert box!!");
var name = $('#name').val();
var email = $('#email').val();
var phone = $('#phone').val();
var message = $('#message').val();
if (name == '' || email == ''|| phone == ''){
alert("Please insert Full Name , Email and phone!");
}else{
$.ajax({
type: 'POST',
url: '?f=send_email',
data: {
name: name,
email: email,
phone: phone,
message: message
},
success: function (data) {
if(data=='1'){
alert("Send Successfull. We will reply you soon.");
location.reload();
}else{
alert("Error while processing data, please try again.");
}
}
});
}
}
</script>
I have using alert("Hello! I am an alert box!!");
to test submit button, it can be worked and will popup the message. But until this coding if (name == '' || email == ''|| phone == ''){alert("Please insert Full Name , Email and phone!");}
, it doesn't work and no popup the message. Hope anyone can help me find the problem. Thanks.
alert()
for debugging, usedebugger
and the browser tools orconsole.log(...)
.console.log($("#name").length, $("#email").length, $("#phone").length);
- if any of these are not1
then your code won't work as expected as you have duplicate IDs