I am trying to verify if phone number exists in database when user fills in a number into the form field. I am using Ajax for post and return confirmation.
Everything seems fine except for an error when returning value from external file.
I am not able to pinpoint the exact error reason
The code is as follows
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
// check if input data is number
$('#phone').keyup(function(){isNumber(this);});
//Check the min chars for phone
var min_chars = 10;
//result texts
var characters_error = 'Has to be 10 digits only';
var checking_html = 'Checking...';
//when button is clicked
$('#phone').keyup(function(){
//run the character number check
if($('#phone').val().length != min_chars){
//if it's bellow the minimum show characters_error text '
$('#phone_availability_result').html(characters_error);
}else{
//else show the checking_text and run the function to check
$('#phone_availability_result').html(checking_html);
check_availabilityp();
}
});
});
//function to check phone availability
function check_availabilityp(){
//get the phone
var phone = $('#phone').val();
//use ajax to run the check
$.post("check_phone.php", { phone: phone },
function(resultp){
//if the result is 1
if(resultp == 1){
//show that the phone is available
$('#phone_availability_result').html(phone + ' is Available');
}else if (resultp == 0){
//show that the phone is NOT available
$('#phone_availability_result').html(phone + ' is not Available');
}else{//show that the phone is NOT available
$('#phone_availability_result').html('Something Wrong');}
});
};
//function to check whether input is number
function isNumber(field) {
var re = /^[0-9]*$/;
if (!re.test(field.value)) {
alert('Must be all numeric charcters. Non numerics will be removed from field!');
field.value = field.value.replace(/[^0-9]/g,"");
}
}
</script>
HTML
<input type='text' id='phone' name="phone" maxlength="10">
<div id='phone_availability_result'></div>
PHP Code 'check_phone.php'
<?php
include('connnew.php');
//$phone = mysql_real_escape_string($_POST['phone']);
$resultp = $usersdb->query("SELECT * FROM users WHERE Phone = '$phone'") or die($usersdb->error);
//if number of rows fields is bigger them 0 that means it's NOT available '
if($resultp->num_rows>0){
//and we send 0 to the ajax request
echo 1;
}else{
//and we send 1 to the ajax request
echo 0;
}
?>
I am constantly getting the error "Something Wrong". Though when I independently run the check_phone.php file, it works fine. I guess it is in the return value function that there is some error.
Maybe somebody can help identify the bug.
trim the response values before compare
$.post("check_phone.php", { phone: phone },
function(resultp){
//if the result is 1
if($.trim(resultp) == 1){
//show that the phone is available
$('#phone_availability_result').html(phone + ' is Available');
}else if ($.trim(resultp) == 0){
//show that the phone is NOT available
$('#phone_availability_result').html(phone + ' is not Available');
}else{//show that the phone is NOT available
$('#phone_availability_result').html('Something Wrong');}
});
$phone is commented in this code
$resultp = $usersdb->query("SELECT * FROM users WHERE Phone = '$phone'") or die($usersdb->error);
if($resultp->num_rows>0){
echo 1;
}else{
echo 0;
}
?>
May be you are getting response as string, Try this :
if(resultp == '1' || resultp == 1) {
//show that the phone is available
$('#phone_availability_result').html(phone + ' is Available');
}else if (resultp == '0' || resultp == 0){
//show that the phone is NOT available
$('#phone_availability_result').html(phone + ' is not Available');
}else{//show that the phone is NOT available
$('#phone_availability_result').html('Something Wrong');
}
Related
Good day, ive been reading all the possible questions and answers here in this site all day, i know im almost getting the right answer but it seems some of the suggestions here doesnt work for me.
I have a dynamic form where the user can add and remove text fields and submit the request through ajax and php. The form consist of two required text field and buttons to add and remove another field(aside from the two required fields). The user can submit the form even not using another extra field.
My problem is if I press the add button and later on decide to remove it, I am getting a '0' value in corresponding table in database even after pressing the remove button.
Here is my HTML:
<form method="POST">
<span class="text-label">Subject:</span>
<input type="text" name="subject" id="subject-field" placeholder="Subject name here" maxlength="10" class="record-input-forms" /> <span class="text-label">Section:</span>
<input type="text" name="section" id="section-field" placeholder="Subject section here" maxlength="3" class="record-input-forms" /> + <a class="remove-field" href="#" title="Remove student field">×</a> →
<div id="student-box-wrap"></div> <span id="status-message"></span> </form>
Here is my AJAX
$(document).ready(function() {
$("#save-button").click(function() {
var subject = $("input#subject-field").val();
if (subject == "") {
$('#status-message').css({
"color": "#ec3f8c"
});
$('#status-message').html('Please fill the subject fields');
return false;
}
var section = $("input#section-field").val();
if (section == "") {
$('#status-message').css({
"color": "#ec3f8c"
});
$('#status-message').html('Please fill the section fields');
return false;
}
var studid = [];
$('input[name="studid[]"]').map(function() {
studid.push($(this).val());
});
var dataString = 'subject=' + subject + '§ion=' + section + '&studid=' + studid;
$.ajax({
type: "POST",
url: 'save.php',
data: dataString,
dataType: "html",
success: function(data) {
$("input#subject-field").val('');
$("input#section-field").val('');
$("input#field-wrap").remove();
$("#status-message").css({
"color": "#39b1c6"
});
$("#status-message").html('Save successfully');
$("#status-message").fadeOut(2000);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
});
return false;
});
});
my Jquery counter
$(document).ready(function() {
var counter = 0;
$(".add-field").click(function() {
counter += 1;
$("#student-box-wrap").append('<div class="field-wrap-' + counter + '"><span id="number-' + counter + '">' + counter + '.</span> Student ID: <input type="text" name="studid[]" class="record-input-forms" /></div>');
});
$(".remove-field").click(function() {
if (counter == 0) {
alert("Nothing to remove!");
} else {
$(".field-wrap-" + counter + "").remove();
counter--;
}
});
});
And my PHP
<?php
require 'connection.php';
session_start();
$studid = (explode(",", $_POST['studid']));
$subject = mysql_real_escape_string(strtoupper($_POST['subject']));
$section = mysql_real_escape_string(strtoupper($_POST['section']));
$adminid = $_SESSION['AdminID'];
mysqli_query($con, "INSERT INTO tbl_subjects(SubjectName, SubjectSection, AdminID) VALUES ('$subject', '$section', '$adminid')");
if (!empty($studid) && !empty($name)) {
foreach ($studid as $new) {
$sql_1 = "INSERT INTO tbl_student(StudentID, SubjectID) VALUES ('$new', LAST_INSERT_ID())";
mysqli_query($con, $sql_1);
}
}
if (!mysqli_query($con, $sql)) {
die('Error: ' . mysqli_error($con));
}
?>
i used !empty in my php and im getting same result. If i dont press the add button at all, im not getting any issue. Its just about when pressing it and even after removing it the variable in ajax seems to carry an empty data to database.
I think your issue issue is that, in your PHP, you call $studid = (explode(",", $_POST['studid'])); before you check if the value is set.
From the docs for explode()
If delimiter is an empty string (""), explode() will return FALSE. If delimiter contains a value that is not contained in string and a negative limit is used, then an empty array will be returned, otherwise an array containing string will be returned.
Effectively, you are calling explode() on an empty string and getting back your empty string.
In your PHP, try moving explode() inside the if statement, after you check if it is set like:
<?php
require 'connection.php';
session_start();
$subject = mysql_real_escape_string(strtoupper($_POST['subject']));
$section = mysql_real_escape_string(strtoupper($_POST['section']));
$adminid = $_SESSION['AdminID'];
mysqli_query($con, "INSERT INTO tbl_subjects(SubjectName, SubjectSection, AdminID) VALUES ('$subject', '$section', '$adminid')");
if ( isset( $_POST['studid'] )) {
$studid = (explode(",", $_POST['studid']));
foreach ($studid as $new) {
$sql_1 = "INSERT INTO tbl_student(StudentID, SubjectID) VALUES ('$new', LAST_INSERT_ID())";
mysqli_query($con, $sql_1);
}
}
if (!mysqli_query($con, $sql)) {
die('Error: ' . mysqli_error($con));
}
?>
Also, in your jquery, change:
var dataString = 'subject=' + subject + '§ion=' + section + '§ion=' + section;
To:
// only add `studid` if there is one or more present
var studidStr = studid != '' ? '&studid=' + studid : '';
var dataString = 'subject=' + subject + '§ion=' + section + studidStr;
First, let me say that I've looked through other similar questions on this site and the jQuery documentation. So far I haven't found something that fixes my issue.
I'm trying to setup a login form for logging in using an email address and password. I have a PHP-only solution that works just fine, but I'm trying to add AJAX functionality as well.
The code I'm using now returns the whole page that's making the AJAX call. Just for some extra info, I'm using jQuery 1.10.2 and PHP 5.4.12. This is also my first time setting up a site to use a PHP script for deciding what other scripts to use based on what data is sent to it, so please bear with me.
Here's my form:
<form id="employee_login" name="employee_login" action="portal.php" method="post">
<input type="text" name="email" placeholder="Email address">
<input type="password" name="password" placeholder="Password">
<button id="login" type="submit" name="submit">Submit</button>
</form>
<div id="error_box">
<?php if(isset($GLOBALS['loginError']) && $GLOBALS['loginError'] != '') { ?>
<p class="error"><?php echo $GLOBALS['loginError']; ?></p>
<?php } ?>
</div>
Here's my AJAX function:
function ajaxValidate(email, pass, error) {
if($(email).val() == '' || $(pass).val() == '') {
$(error).html('<p class="error">You must enter your email address and password!</p>');
}
else {
$.ajax({
type: 'POST',
url: '/php-modules/ajax_filter.php',
dataType: 'text',
data: { emailAddr: $(email).val(), password: $(pass).val()},
success: function(text, textStatus, jqXHR)
{
console.log(Date() + ': ' + text);
try{
if( IsType(text, 'json') ) {
var ajaxData = $.parseJSON(text);
if(ajaxData['error'] != null && ajaxData['error'] != 'undefined')
$(error).html('<p class="error">' + ajaxData['error'] + '</p>');
else if(ajaxData['is_email'] != 1)
$(error).html('<p class="error">You must enter a <strong>VALID</strong> email address.</p>');
else if(ajaxData['is_email'] == 1)
document.location = jqXHR.getResponseHeader('Location');
else
$(error).html('<p class="error">You must enter your email address and password!</p>');
}
else if( IsType(text, 'html') ) $(error).html( $.parseHTML(text) );
else if( IsType(text, 'xml') ) alert('Data is XML.');
}
catch(e) {
$(error).html('<p class="error">' + e.description + '</p>');
console.debug(e);
}
},
error: function(jqXHR, textStatus, errorThrown)
{
$(error).html('<p class="error">' + jqXHR.status + ' ' + errorThrown + ' ' + jqXHR.responseText + '</p>');
}
});
}
}
The script I'm sending the AJAX call to is only setup for 1 request so far. I intend to add more later. I'm not sure if I've setup too many checks either, but I wanted to be safe since I'm not very familiar with something like this. And the "unidentified error" thing I added just today was a replacement for a "return false" that I thought could've been causing the problem. Here's the code:
<?php
// a filter for all AJAX requests
// for email checking
if( isset($_POST['emailAddr']) ) {
require_once('login.php');
if(isset($GLOBALS['loginError']) && $GLOBALS['loginError'] != '') {
echo '{"error":"' . $GLOBALS['loginError'] . '"}';
} else echo '{"error":"Unidentified error"}';
}
// if $_POST isn't set, isn't an array, or has a length less than 1, return an error
else if(!isset($_POST) || !is_array($_POST) || count($_POST) < 1) {
echo '{"error":"No data sent"}';
}
// if the previous check fails, invalid or insuficient data was sent
else {
echo '{"error":"Could not process request"}';
}
?>
The last piece is my login checking script. I've omitted the actual query and table fields because those parts work fine when using my PHP-only solution.
<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {
// halt execution if the login fields are empty
if((!isset($_POST['emailAddr']) || $_POST['emailAddr'] == "") && (!isset($_POST['password']) || $_POST['password'] == "")) {
$GLOBALS['loginError'] = 'You must enter your email and password!';
}
else {// check for valid email
require_once('is_email.php');
if( !is_email($_POST['emailAddr']) ) $GLOBALS['loginError'] = 'You must enter a valid email address!';
else if($_POST['emailAddr'] != "" && $_POST['password'] != "") {
try{
// PDO setup
include('pdo.php');
$con = createPDO();
// PDO statement preparation and execution
$query = $con->prepare("[query code];");
$email = $_POST['emailAddr'];
$password = $_POST['password'];
// returned PDO query data
if($query->execute( array($email) ) ) {
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
if(strtolower($email) == strtolower($row['email']) && $password == $row['password']) {
// set session data
$_SESSION['user_id'] = $row['[id field]'];
$_SESSION['name'] = ucfirst($row['[name field]']);
$_SESSION['email'] = $row['[email field]'];
session_regenerate_id();
header("location: /");
}
else $GLOBALS['loginError'] = 'ID or password incorrect!';
}
}
} catch(Exception $e) {
$GLOBALS['loginError'] = $e->getMessage();
}
}
else $GLOBALS['loginError'] = 'You must enter your email and password!';
}
}
?>
I've cut out an unnecessary function and return false; lines, added the console.log(); method, changed the email: value name in the ajax data: option to emailAddr: (in my PHP code too) in case of a name conflict between it and my email variable, and changed my code to parse for HTML in case of PHP generating HTML error messages. My parentheses, braces, and brackets seem to be matched ok (I checked using Sublime Text's parenthesis/brace/bracket highlighting to check), the form checking portion of the script works fine.
I'm honestly at a loss...
Also, thanks to everyone who reads through this long-winded post.
Question updates:
I just realized that parsing code in the try is working correctly. Since the $.parseJSON doesn't work, it's skipping down to the if statement for parsing HTML and that one is working.
Code changes:
I replaced some return statements with echo, per Morganster.
When you are going to return data across an ajax call, you must print your data.
For example,
$var['error']="Could not process request";
echo json_encode($var);
The problem is fixed. Someone named Scott Sawyer said header("Location: /") would cause the $.ajax() method to return the whole current page. The redirect seems to be working now. Thanks for the input everyone.
Hi I am creating a wordpress plugin and i am a little bit stack here. there's text box number 1 which is the order number and number 2 which is the order name. This is what i want. If the customer enters a number in textbox number 1 which is order number, the value he or she entered will check into the database and get the corresponding order name of that order number. Its realtime. No need to submit before it appears. Everytime they input something it will immediate check to the database and display it in text box number 2(order name). I research this and try using ajax in wordpress but i dont know how to use. Thanks.
Here's some boilerplate code to get you started....
<script type="text/javascript" charset="utf-8">
var req;
function handler_orderNumberField_onchange(fld) {
var text = fld.value;
if (text.length == 8) {
queryForOrderName(text);
}
}
function queryForOrderName(orderNumber) {
document.getElementById('orderNameField').value = "Please wait..."
req = new XMLHttpRequest();
var url = "http://www.mydomain.com/getordername.php?ordernumber=" + orderNumber;
req.onreadystatechange = function() {
var field = document.getElementById('orderNameField');
var rs = this.readyState;
var status = this.status;
if (rs == 4 && status == 200) {
field.value = req.responseText;
}
};
req.ontimeout = function() {
document.getElementById('orderNameField').value = 'Timeout.';
}
req.timeout = 10000;
req.open("GET", url, true);
req.send();
}
</script>
<p>Order Number: <input type="text" name="orderNumber" value="" id="orderNumberField" onchange="handler_orderNumberField_onchange(this)"></p>
<p>Order Name: <input type="text" name="orderName" value="" id="orderNameField"></p>
Note that you need to implement a getordername.php script yourself; example:
<?php
$ordernr = (int) $_GET["ordernumber"];
$result = sprintf("Testorder - Order Number %d", $ordernr);
header("Content-type: text/plain; charset=UTF-8");
echo $result;
exit;
?>
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
JQuery validate e-mail address regex
hi i have an input filed in a form referencing to an email input field , and when the user clicked the submit button i want to ensure that the email input field value has the formal like this
example#hotmail.com
or
example#gmail.com
or
example#yahoo.com
and the input field is this
<p>
<label>Email</label>
<input type="text" name="Email"/>
<span class="errorMessage"></span>
</p>
jquery code
$(document).ready(function(){
$('#suform').on('submit', function(e){
e.preventDefault();
var errorCount = 0;
$('span.errorMessage').text(''); // reset all error mesaage
$('input').each(function(){
var $this = $(this);
if($this.val() === ''){
var error = 'Please fill ' + $this.prev('label').text(); // take the input field from label
$this.next('span').text(error);
errorCount = errorCount + 1;
}
});
if(errorCount === 0){
var mobileNumber = $('input[name=MNumber]');
var email = $('input[name=Email]');
if(isNaN(parseFloat(mobileNumber )) && !isFinite(mobileNumber )) {
var error = 'Mobile number incorect.';
$('input[name=MNumber]').next('span').text(error);
errorCount = errorCount + 1;
}else{
var password= $('input[name="Password"]').val();
var repass= $('input[name="RePassword"]').val();
if(password!=repass){ // ensrue the two passwords are the same
var error2 = 'Password not matching';
$('input[name="RePassword"]').next('span').text(error2)
errorCount = errorCount + 1;
}else{
$(this)[0].submit(); // submit form if no error
}
}
}
});
});
my html , css and jquery code is here
code
If I understand you correctly, you want to validate the email address filled on the form:
ADD TO YOUR FUNCTION
// validate proper email address
var reg = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))#((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
if (reg.test(value) == false) {
// email invalid, do stuff
} else {
// email valid, do stuff
}
This Regular expression checks the email provided for many many many issues!
EDITED:
You're function had some typos, here it is fully functional: and a working Fiddle!
$(document).ready(function(){
// form submit
$('#suform').on('submit', function(e){
// prevent default behavior
e.preventDefault();
// reset errors counter
var errorCount = 0;
// clear error message
$('span.errorMessage').text('');
// run by each input field to check if they are filled
$('input').each(function(){
var $this = $(this);
if($this.val() === ''){
// take the input field from label
var error = 'Please fill ' + $this.prev('label').text();
$this.next('span').text(error);
errorCount = errorCount + 1;
}
});
// no errors so far, let continue and validate the contents
if(errorCount === 0){
// get mobile number
var mobileNumber = $('input[name=MNumber]').val();
// get email address
var email = $('input[name=Email]').val();
// get password and password repeat
var password= $('input[name="Password"]').val();
var repass= $('input[name="RePassword"]').val();
// regular expression to validate the email address
var reg = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))#((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
// try to validate the email
if (reg.test(email) == false) {
$('input[name=Email]').next('span').text('Email address is invalid!');
errorCount = errorCount + 1;
} else {
if(isNaN(parseFloat(mobileNumber )) && !isFinite(mobileNumber )) {
var error = 'Mobile number incorect.';
$('input[name=MNumber]').next('span').text(error);
errorCount = errorCount + 1;
} else {
// ensrue the two passwords are the same
if(password!=repass){
var error2 = 'Password not matching';
$('input[name="RePassword"]').next('span').text(error2);
errorCount = errorCount + 1;
}else{
$(this)[0].submit(); // submit form if no error
}
}
}
}
});
});
Regular expression is one way to validate :
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\
".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA
-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
Pass a user entered email to this function it will check its formate and return true or false accordingly
You can use this function:
function validateEmail(email) {
var emailReg = /^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/;
if( !emailReg.test( email ) ) {
return false;
} else {
return true;
}
}
I am trying to use fancybox iframe to call a PHP program for payment processing from a javascript program as part of a landing page. The page also calls another PHP program that writes date to a file. I tried to simulate a click to start the fancybox function but never got it to work. I keep getting this error - $("a.hiddenclicker").fancybox is not a function. I'm not sure whether to attempt to just add this logic to the PHP file or figure out how to get fancybox to work. Here is my page. The call to fancybox is in ProcessForm().
function WriteData(url) {
var j1 = document.getElementById("hiddenclicker");
var Request2 = false;
if (window.XMLHttpRequest) {
Request2 = new XMLHttpRequest();
} else if (window.ActiveXObject) {
Request2 = new ActiveXObject("Microsoft.XMLHTTP");
}
if (Request2) {
Request2.open("GET", url, true);
Request2.onreadystatechange = function() {
if (Request2.readyState == 4 && Request2.status == 200) {
}
}
Request2.send(null);
}
}
function ProcessForm(form) {
var j1 = document.getElementById("hiddenclicker");
var firstname = "";
var lastname = "";
var payment = "";
var email = "";
var phone = "";
var donation = "";
firstname = form.firstname.value;
lastname = form.lastname.value;
email = form.email.value;
phone = form.phone.value;
donation = form.donation.value;
if (firstname == "") {
alert("You must fill in the first name");
form.firstname.focus();
return false;
}
else {
if (lastname == "") {
alert("You must fill in last name");
form.lastname.focus();
return false;
}
else {
if (email == "") {
alert("You must fill in email address");
form.email.focus();
return false; }
}
}
WriteData("writedata.php?firstname=" + firstname + "&lastname=" + lastname + "&email=" + email + "&phone=" + phone + "&donation=" + donation);
if (donation == "now") {
jQuery(document).ready(function(){
$("a.hiddenclicker").fancybox(
{
'width' : 600,
'height' : 400,
'hideOnContentClick' : false,
'type' : 'iframe'
});
});
j1.href = "http://www.ccyakids.org/donation_logic/donation_start.php#form";
$('#hiddenclicker').trigger('click');
}
}
// End hiding JavaScript statements -->
HTML needed to trigger hiddenclicker
Hidden Clicker
After looking at your code you reference your link 2 different ways:
$("a.hiddenclicker") // class
$('#hiddenclicker') // ID
Which is it? Make them both the same and i am sure your problem goes away.
Hope this helps