I'm quite new with web development. I have a register modal in register.php that is able to return a check function from the submit button, to submit an API call.
But when I run this it from my index page, the function does not seem to be called.
header.php
<?php
include ('includes/login.php');
include ('includes/register.php');
?>
register.php
<button class="regsubmit" type="submit" style="float:left;" id="submitButton" onclick="return chk()">Submit</button>
<button class="regcancel" type="button" id="cancelButton"
onclick="window.location='#';return false;">Cancel</button>
</form>
</div>
</div>
</div>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
function chk() {
var fname=document.getElementById('fname').value;
var lname=document.getElementById('lname').value;
var emailAddress = document.getElementById('emailAddress').value;
var bdayMonth = document.getElementById('bdayMonth').value;
var bdayDay = document.getElementById('bdayDay').value;
var bdayYear = document.getElementById('bdayYear').value;
var regPassword = document.getElementById('regPassword').value;
var confirmPassword = document.getElementById('confirmPassword').value;
var gender = document.getElementById('gender').value;
var dataString='fname='+ fname+'&lname='+lname+'&emailAddress='+emailAddress+'&bdayMonth='+bdayMonth+'&bdayDay='+bdayDay+'&bdayYear='+bdayYear+'&confirmPassword='+confirmPassword+'®Password='+regPassword+'&gender='+gender;
$.ajax({
type:"post",
url: "processRegister.php",
data:dataString,
cache:false,
success: function(data){
if (/^\s*SUCCESS\s*$/.test(data)) {
window.location = '<?php echo $base_url; ?>index.php?success=true';
}
else{
alert(data);
}
}
});
return false;
}
</script>
edit: i ran an alert() at the start of the function and tried to run in on my index again, the alert was able to show but not the function.