0 Replies - 1656 Views - Last Post: 27 February 2013 - 04:59 PM

#1 glenotzmanuel2407   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 25-February 13

Problem about ajax

Posted 27 February 2013 - 04:59 PM

Great day!!

I have a problem about my code.


Database:
order_no order_name
23532 House of Glass BC
32532 Inner Weather
53254 Fernwood Fitness
53253 Aspect Joinery
more.. more..


Picture:http://i.imgur.com/yQAErOk.jpg
let say that: i have a 2 textbox as you see the image..
ORDER NUMBER 1. <input name="order_numbr"type="text" class="textbox" id="order_numbr" value="">
ORDER NAME 2. <input name="ur_name1" type="text" class="textbox" id="ur_name1" value="">

Ive already finished the 2 case but the 3rd case not yet done kindly help me please
case 1: If the order number is empty says "this field is required".
case 2: If you enter invalid order number says "This order number does not exists".


case 3: When If you enter valid order number automatically display order name in the textbox ORDER NAME without clicking a button..

function.php

/**
 * @dont remove
 *	check if order number is exist in db
 */
 
add_action('wp_ajax_nopriv_checkOrdrNum','checkOrdrNum');
add_action('wp_ajax_checkOrdrNum','checkOrdrNum');
function checkOrdrNum(){
	global $wpdb,$current_user;
	$orderno= $_POST['orderno'];
	if ($_POST['id']==0) {
		$ordr_num=$wpdb->get_var('SELECT COUNT(*) FROM art_work_history WHERE cus_id = ' . $current_user->ID . ' AND (status="Pending" || status="In Progress") AND isweb = 0 AND order_no = '.$orderno);
	} else {
		$ordr_num=$wpdb->get_var('SELECT COUNT(*) FROM art_work_history a JOIN art_work_proof b ON a.order_no = b.order_no  WHERE a.cus_id=' . $current_user->ID . ' AND isweb = 0 AND (a.status="Customer Proof" || a.status="Alterations" || a.status = "Alteration Pending") AND b.order_no='.$orderno);
	}

	echo json_encode(array('order_no' => $ordr_num));
	exit;
}



add_action('wp_ajax_nopriv_checkOrdrName','checkOrdrName');
add_action('wp_ajax_checkOrdrName','checkOrdrName');

function checkOrdrName(){

$order_no = $_GET["order_no"];
	
$qr = "SELECT * FROM art_work_history WHERE id = $order_no";

$res= mysql_query($qr);
$row = mysql_fetch_array($res);
$order_arr["order_name"] = $row["order_name"];
  echo json_encode($order_arr);
}







validateForm.js


jQuery.validator.addMethod("ordrNum",function(value,element){
	var isExist=false;
		$.ajax({
			type : "POST",
			async: false,
            data : "action=checkOrdrNum&id=0&orderno=" + value,
            url  : ajaxurl,
			dataType:"json",
            success: function (data) {
			//console.log(data["order_no"]);
			   if (data["order_no"] >0) {
					isExist=true;
				} 
			}
		});
		//console.log(isExist);
		return isExist;//true;

	},"This order number does not exist");
	
	
$(document).on('keyup', '#order_numbr', function() {
      if( $('form').valid() ) {
                  $.post( ajaxurl, {"action":"checkOrdrNum","id":0,"orderno": $(this).val()},
                              function( data ) {
                  $('#ur_name1').val('Order ' + data.order_no);
                        },
                              'json'
                        );
      }
});





I want that the output of the order name is in default value. It is impossible to do that sir ?
thanks!

Is This A Good Question/Topic? 0
  • +

Page 1 of 1