Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > เรียกใช้ java script แล้วสั่ง return false; แต่ form มันไม่หยุดคำสั่ง action มันก็เลย add data เปล่า ๆ



 

เรียกใช้ java script แล้วสั่ง return false; แต่ form มันไม่หยุดคำสั่ง action มันก็เลย add data เปล่า ๆ

 



Topic : 047991

Guest




java script ของผมเป็นแบบนี้ครับ
Code (JavaScript)
<script type="text/javascript">
function check(){
       if(document.myForm.name.value == ''){
            alert("คุณยังไม่ได้กรอก  ชื่อ");
            document.myForm.name.focus();
            return false;
        }	   
}
</script>



ในฟอร์มก็ปกติครับ เรียกใช้ java ข้างบน

Code (PHP)
<form id="myForm" name="myForm" method="post" onsubmit="return check();" action="poolAdd_script.php">
<table> 
<tr>
      <td width="20%" class="TD_title">ชื่อ: </td>
      <td align="left" width="80%"><input type="text" name="name" value="" id="name" class="textboxlong" /></td>
    </tr>
</table>
</form>


แต่ form มันไม่หยุดคำสั่ง action มันก็เลย add data เปล่า ๆ ลงไปอ่ะครับ สาเหตุเกิดจากอะไรได้บ้างครับ



Tag : PHP, MySQL, JavaScript







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-08-31 17:35:10 By : dev View : 4095 Reply : 14
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

เป็นไปได้ว่า javascript error






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 17:38:45 By : webmaster
 


 

No. 2



โพสกระทู้ ( 3,468 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter

ไม่น่าผิดนะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 17:39:05 By : pjgunner
 

 

No. 3

Guest


เอาแบบหน้าเต็มๆ มาดูครับ เพราะเท่าที่ลอง code ด้านบนก็ okay
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 17:51:20 By : ิburn
 


 

No. 4

Guest


มันมี Ajax อยู่นิดหน่อยครับ ผมก็งง เพราะต้องแก้งานของคนอื่นอีกที
Code (PHP)
<?
include_once '../includes/connect.php';
?>
<script src="../includes/js/jquery/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript">
       $(document).ready(function() { 
			$('#myForm').ajaxForm({ 
				dataType:  'json', 
				success:   function processJson(resPonse) { 
							if(resPonse==1){
								$('#Loading').hide();
								$('#Loading1').show();
								$('#Loading1').fadeOut(1500);
								$('#myForm').reset();
							} else {
								$('#Loading1').hide();
								$('#Loading').show();
								$('#Loading1').show(1500);
							}
						} 
			}); 
		});
	   
function check(){
       if(document.myForm.name.value == ''){
            alert("คุณยังไม่ได้กรอกข้อมูล ชื่อบ่อ");
            document.myForm.note.focus();
            return false;
        }	   
}
</script> 

<form id="myForm" name="myForm" method="post" onsubmit="return check();" action="poolAdd_script.php"  enctype="multipart/form-data">
  <table width="100%" cellpadding="9" cellspacing="0" border="0">
    <tr>
      <td colspan="2" class="title2">เพิ่มข้อมูลบ่อใหม่</td>
    </tr>
    <tr>
      <td width="20%" class="TD_title">ชื่อบ่อ: </td>
      <td align="left" width="80%"><input type="text" name="name" value="" id="name" class="textboxlong" /></td>
    </tr>
    <tr>
      <td width="20%" class="TD_title">สถานะ: </td>
      <td align="left" width="80%"><input name="status" type="radio" value="y" checked="checked" />เปิดใช้ &nbsp;&nbsp;<input name="status" type="radio" value="n" />ไม่เปิดใช้</td>
    </tr>
    <tr>
      <td width="20%" class="TD_title">Note: </td>
      <td align="left" width="80%"><label>
        <textarea name="note" id="note" cols="60" rows="5" class="textarea"></textarea>
      </label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="left" width="80%"><div id="buttonDiv">
        <input type="submit" name="button1" value="บันทึก" class="button" />
        <input type="button" name="button2" value="ย้อนกลับ" onClick="javascript:LoadContentDIV('poolData.php');" class="button" />
      </div>
        <div id="Loading" style="padding: 10px; text-align: center; display:none;  color: red;"><img src="../images/loader_twt.gif" alt="" /> กำลังบันทึกข้อมูล..</div></td>
    </tr>
  </table>
</form>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 18:08:24 By : dev
 


 

No. 5

Guest


เป็นปัญหาของ ajax ที่เรียกมา เอางี้ ให้เอา code jquery.form.js มาดูหน่อยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 18:28:00 By : ิburn
 


 

No. 6

Guest


ยาวหน่อยนะครับ

Code (PHP)
/*!
 * jQuery Form Plugin
 * version: 2.45 (09-AUG-2010)
 * @requires jQuery v1.3.2 or later
 *
 * Examples and documentation at: http://malsup.com/jquery/form/
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
;(function($) {

/*
	Usage Note:
	-----------
	Do not use both ajaxSubmit and ajaxForm on the same form.  These
	functions are intended to be exclusive.  Use ajaxSubmit if you want
	to bind your own submit handler to the form.  For example,

	$(document).ready(function() {
		$('#myForm').bind('submit', function() {
			$(this).ajaxSubmit({
				target: '#output'
			});
			return false; // <-- important!
		});
	});

	Use ajaxForm when you want the plugin to manage all the event binding
	for you.  For example,

	$(document).ready(function() {
		$('#myForm').ajaxForm({
			target: '#output'
		});
	});

	When using ajaxForm, the ajaxSubmit function will be invoked for you
	at the appropriate time.
*/

/**
 * ajaxSubmit() provides a mechanism for immediately submitting
 * an HTML form using AJAX.
 */
$.fn.ajaxSubmit = function(options) {
	// fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
	if (!this.length) {
		log('ajaxSubmit: skipping submit process - no element selected');
		return this;
	}

	if (typeof options == 'function') {
		options = { success: options };
	}

	var url = $.trim(this.attr('action'));
	if (url) {
		// clean url (don't include hash vaue)
		url = (url.match(/^([^#]+)/)||[])[1];
	}
	url = url || window.location.href || '';

	options = $.extend(true, {
		url:  url,
		type: this.attr('method') || 'GET',
		iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
	}, options);

	// hook for manipulating the form data before it is extracted;
	// convenient for use with rich editors like tinyMCE or FCKEditor
	var veto = {};
	this.trigger('form-pre-serialize', [this, options, veto]);
	if (veto.veto) {
		log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
		return this;
	}

	// provide opportunity to alter form data before it is serialized
	if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
		log('ajaxSubmit: submit aborted via beforeSerialize callback');
		return this;
	}

	var n,v,a = this.formToArray(options.semantic);
	if (options.data) {
		options.extraData = options.data;
		for (n in options.data) {
			if(options.data[n] instanceof Array) {
				for (var k in options.data[n]) {
					a.push( { name: n, value: options.data[n][k] } );
				}
			}
			else {
				v = options.data[n];
				v = $.isFunction(v) ? v() : v; // if value is fn, invoke it
				a.push( { name: n, value: v } );
			}
		}
	}

	// give pre-submit callback an opportunity to abort the submit
	if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
		log('ajaxSubmit: submit aborted via beforeSubmit callback');
		return this;
	}

	// fire vetoable 'validate' event
	this.trigger('form-submit-validate', [a, this, options, veto]);
	if (veto.veto) {
		log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
		return this;
	}

	var q = $.param(a);

	if (options.type.toUpperCase() == 'GET') {
		options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
		options.data = null;  // data is null for 'get'
	}
	else {
		options.data = q; // data is the query string for 'post'
	}

	var $form = this, callbacks = [];
	if (options.resetForm) {
		callbacks.push(function() { $form.resetForm(); });
	}
	if (options.clearForm) {
		callbacks.push(function() { $form.clearForm(); });
	}

	// perform a load on the target only if dataType is not provided
	if (!options.dataType && options.target) {
		var oldSuccess = options.success || function(){};
		callbacks.push(function(data) {
			var fn = options.replaceTarget ? 'replaceWith' : 'html';
			$(options.target)[fn](data).each(oldSuccess, arguments);
		});
	}
	else if (options.success) {
		callbacks.push(options.success);
	}

	options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
		var context = options.context || options;   // jQuery 1.4+ supports scope context 
		for (var i=0, max=callbacks.length; i < max; i++) {
			callbacks[i].apply(context, [data, status, xhr || $form, $form]);
		}
	};

	// are there files to upload?
	var fileInputs = $('input:file', this).length > 0;
	var mp = 'multipart/form-data';
	var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);

	// options.iframe allows user to force iframe mode
	// 06-NOV-09: now defaulting to iframe mode if file input is detected
   if (options.iframe !== false && (fileInputs || options.iframe || multipart)) {
	   // hack to fix Safari hang (thanks to Tim Molendijk for this)
	   // see:  http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
	   if (options.closeKeepAlive) {
		   $.get(options.closeKeepAlive, fileUpload);
		}
	   else {
		   fileUpload();
		}
   }
   else {
	   $.ajax(options);
   }

	// fire 'notify' event
	this.trigger('form-submit-notify', [this, options]);
	return this;


	// private function for handling file uploads (hat tip to YAHOO!)
	function fileUpload() {
		var form = $form[0];

		if ($(':input[name=submit],:input[id=submit]', form).length) {
			// if there is an input with a name or id of 'submit' then we won't be
			// able to invoke the submit fn on the form (at least not x-browser)
			alert('Error: Form elements must not have name or id of "submit".');
			return;
		}

		var s = $.extend(true, {}, $.ajaxSettings, options);
		s.context = s.context || s;
		var id = 'jqFormIO' + (new Date().getTime());
		var $io = $('<iframe id="' + id + '" name="' + id + '" src="'+ s.iframeSrc +'" onload="var f = jQuery(this).data(\'form-plugin-onload\'); if (f) f();" />');
		var io = $io[0];

		$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });

		var xhr = { // mock object
			aborted: 0,
			responseText: null,
			responseXML: null,
			status: 0,
			statusText: 'n/a',
			getAllResponseHeaders: function() {},
			getResponseHeader: function() {},
			setRequestHeader: function() {},
			abort: function() {
				this.aborted = 1;
				$io.attr('src', s.iframeSrc); // abort op in progress
			}
		};

		var g = s.global;
		// trigger ajax global events so that activity/block indicators work like normal
		if (g && ! $.active++) {
			$.event.trigger("ajaxStart");
		}
		if (g) {
			$.event.trigger("ajaxSend", [xhr, s]);
		}

		if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
			if (s.global) { 
				$.active--;
			}
			return;
		}
		if (xhr.aborted) {
			return;
		}

		var cbInvoked = false;
		var timedOut = 0;

		// add submitting element to data if we know it
		var sub = form.clk;
		if (sub) {
			var n = sub.name;
			if (n && !sub.disabled) {
				s.extraData = s.extraData || {};
				s.extraData[n] = sub.value;
				if (sub.type == "image") {
					s.extraData[n+'.x'] = form.clk_x;
					s.extraData[n+'.y'] = form.clk_y;
				}
			}
		}

		// take a breath so that pending repaints get some cpu time before the upload starts
		function doSubmit() {
			// make sure form attrs are set
			var t = $form.attr('target'), a = $form.attr('action');

			// update form attrs in IE friendly way
			form.setAttribute('target',id);
			if (form.getAttribute('method') != 'POST') {
				form.setAttribute('method', 'POST');
			}
			if (form.getAttribute('action') != s.url) {
				form.setAttribute('action', s.url);
			}

			// ie borks in some cases when setting encoding
			if (! s.skipEncodingOverride) {
				$form.attr({
					encoding: 'multipart/form-data',
					enctype:  'multipart/form-data'
				});
			}

			// support timout
			if (s.timeout) {
				setTimeout(function() { timedOut = true; cb(); }, s.timeout);
			}

			// add "extra" data to form if provided in options
			var extraInputs = [];
			try {
				if (s.extraData) {
					for (var n in s.extraData) {
						extraInputs.push(
							$('<input type="hidden" name="'+n+'" value="'+s.extraData[n]+'" />')
								.appendTo(form)[0]);
					}
				}

				// add iframe to doc and submit the form
				$io.appendTo('body');
				$io.data('form-plugin-onload', cb);
				form.submit();
			}
			finally {
				// reset attrs and remove "extra" input elements
				form.setAttribute('action',a);
				if(t) {
					form.setAttribute('target', t);
				} else {
					$form.removeAttr('target');
				}
				$(extraInputs).remove();
			}
		}

		if (s.forceSync) {
			doSubmit();
		}
		else {
			setTimeout(doSubmit, 10); // this lets dom updates render
		}
	
		var data, doc, domCheckCount = 100;

		function cb() {
			if (cbInvoked) {
				return;
			}

			$io.removeData('form-plugin-onload');
			
			var ok = true;
			try {
				if (timedOut) {
					throw 'timeout';
				}
				// extract the server response from the iframe
				doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
				
				var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
				log('isXml='+isXml);
				if (!isXml && (doc.body == null || doc.body.innerHTML == '')) {
					if (--domCheckCount) {
						// in some browsers (Opera) the iframe DOM is not always traversable when
						// the onload callback fires, so we loop a bit to accommodate
						log('requeing onLoad callback, DOM not available');
						setTimeout(cb, 250);
						return;
					}
					log('Could not access iframe DOM after 100 tries.');
					throw 'DOMException: not available';
				}

				log('response detected');
				cbInvoked = true;
				xhr.responseText = doc.documentElement ? doc.documentElement.innerHTML : null; 
				xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
				xhr.getResponseHeader = function(header){
					var headers = {'content-type': s.dataType};
					return headers[header];
				};

				var scr = /(json|script)/.test(s.dataType);
				if (scr || s.textarea) {
					// see if user embedded response in textarea
					var ta = doc.getElementsByTagName('textarea')[0];
					if (ta) {
						xhr.responseText = ta.value;
					}
					else if (scr) {
						// account for browsers injecting pre around json response
						var pre = doc.getElementsByTagName('pre')[0];
						if (pre) {
							xhr.responseText = pre.innerHTML;
						}
					}			  
				}
				else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
					xhr.responseXML = toXml(xhr.responseText);
				}
				data = $.httpData(xhr, s.dataType);
			}
			catch(e){
				log('error caught:',e);
				ok = false;
				xhr.error = e;
				$.handleError(s, xhr, 'error', e);
			}

			// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
			if (ok) {
				s.success.call(s.context, data, 'success');
				if (g) {
					$.event.trigger("ajaxSuccess", [xhr, s]);
				}
			}
			if (g) {
				$.event.trigger("ajaxComplete", [xhr, s]);
			}
			if (g && ! --$.active) {
				$.event.trigger("ajaxStop");
			}
			if (s.complete) {
				s.complete.call(s.context, xhr, ok ? 'success' : 'error');
			}

			// clean up
			setTimeout(function() {
				$io.removeData('form-plugin-onload');
				$io.remove();
				xhr.responseXML = null;
			}, 100);
		}

		function toXml(s, doc) {
			if (window.ActiveXObject) {
				doc = new ActiveXObject('Microsoft.XMLDOM');
				doc.async = 'false';
				doc.loadXML(s);
			}
			else {
				doc = (new DOMParser()).parseFromString(s, 'text/xml');
			}
			return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
		}
	}
};

/**
 * ajaxForm() provides a mechanism for fully automating form submission.
 *
 * The advantages of using this method instead of ajaxSubmit() are:
 *
 * 1: This method will include coordinates for <input type="image" /> elements (if the element
 *	is used to submit the form).
 * 2. This method will include the submit element's name/value data (for the element that was
 *	used to submit the form).
 * 3. This method binds the submit() method to the form for you.
 *
 * The options argument for ajaxForm works exactly as it does for ajaxSubmit.  ajaxForm merely
 * passes the options argument along after properly binding events for submit elements and
 * the form itself.
 */
$.fn.ajaxForm = function(options) {
	// in jQuery 1.3+ we can fix mistakes with the ready state
	if (this.length === 0) {
		var o = { s: this.selector, c: this.context };
		if (!$.isReady && o.s) {
			log('DOM not ready, queuing ajaxForm');
			$(function() {
				$(o.s,o.c).ajaxForm(options);
			});
			return this;
		}
		// is your DOM ready?  http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
		log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
		return this;
	}
	
	return this.ajaxFormUnbind().bind('submit.form-plugin', function(e) {
		if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
			e.preventDefault();
			$(this).ajaxSubmit(options);
		}
	}).bind('click.form-plugin', function(e) {
		var target = e.target;
		var $el = $(target);
		if (!($el.is(":submit,input:image"))) {
			// is this a child element of the submit el?  (ex: a span within a button)
			var t = $el.closest(':submit');
			if (t.length == 0) {
				return;
			}
			target = t[0];
		}
		var form = this;
		form.clk = target;
		if (target.type == 'image') {
			if (e.offsetX != undefined) {
				form.clk_x = e.offsetX;
				form.clk_y = e.offsetY;
			} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
				var offset = $el.offset();
				form.clk_x = e.pageX - offset.left;
				form.clk_y = e.pageY - offset.top;
			} else {
				form.clk_x = e.pageX - target.offsetLeft;
				form.clk_y = e.pageY - target.offsetTop;
			}
		}
		// clear form vars
		setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
	});
};

// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
$.fn.ajaxFormUnbind = function() {
	return this.unbind('submit.form-plugin click.form-plugin');
};

/**
 * formToArray() gathers form element data into an array of objects that can
 * be passed to any of the following ajax functions: $.get, $.post, or load.
 * Each object in the array has both a 'name' and 'value' property.  An example of
 * an array for a simple login form might be:
 *
 * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
 *
 * It is this array that is passed to pre-submit callback functions provided to the
 * ajaxSubmit() and ajaxForm() methods.
 */
$.fn.formToArray = function(semantic) {
	var a = [];
	if (this.length === 0) {
		return a;
	}

	var form = this[0];
	var els = semantic ? form.getElementsByTagName('*') : form.elements;
	if (!els) {
		return a;
	}
	
	var i,j,n,v,el;
	for(i=0, max=els.length; i < max; i++) {
		el = els[i];
		n = el.name;
		if (!n) {
			continue;
		}

		if (semantic && form.clk && el.type == "image") {
			// handle image inputs on the fly when semantic == true
			if(!el.disabled && form.clk == el) {
				a.push({name: n, value: $(el).val()});
				a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
			}
			continue;
		}

		v = $.fieldValue(el, true);
		if (v && v.constructor == Array) {
			for(j=0, jmax=v.length; j < jmax; j++) {
				a.push({name: n, value: v[j]});
			}
		}
		else if (v !== null && typeof v != 'undefined') {
			a.push({name: n, value: v});
		}
	}

	if (!semantic && form.clk) {
		// input type=='image' are not found in elements array! handle it here
		var $input = $(form.clk), input = $input[0];
		n = input.name;
		if (n && !input.disabled && input.type == 'image') {
			a.push({name: n, value: $input.val()});
			a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
		}
	}
	return a;
};

/**
 * Serializes form data into a 'submittable' string. This method will return a string
 * in the format: name1=value1&amp;name2=value2
 */
$.fn.formSerialize = function(semantic) {
	//hand off to jQuery.param for proper encoding
	return $.param(this.formToArray(semantic));
};

/**
 * Serializes all field elements in the jQuery object into a query string.
 * This method will return a string in the format: name1=value1&amp;name2=value2
 */
$.fn.fieldSerialize = function(successful) {
	var a = [];
	this.each(function() {
		var n = this.name;
		if (!n) {
			return;
		}
		var v = $.fieldValue(this, successful);
		if (v && v.constructor == Array) {
			for (var i=0,max=v.length; i < max; i++) {
				a.push({name: n, value: v[i]});
			}
		}
		else if (v !== null && typeof v != 'undefined') {
			a.push({name: this.name, value: v});
		}
	});
	//hand off to jQuery.param for proper encoding
	return $.param(a);
};

/**
 * Returns the value(s) of the element in the matched set.  For example, consider the following form:
 *
 *  <form><fieldset>
 *	  <input name="A" type="text" />
 *	  <input name="A" type="text" />
 *	  <input name="B" type="checkbox" value="B1" />
 *	  <input name="B" type="checkbox" value="B2"/>
 *	  <input name="C" type="radio" value="C1" />
 *	  <input name="C" type="radio" value="C2" />
 *  </fieldset></form>
 *
 *  var v = $(':text').fieldValue();
 *  // if no values are entered into the text inputs
 *  v == ['','']
 *  // if values entered into the text inputs are 'foo' and 'bar'
 *  v == ['foo','bar']
 *
 *  var v = $(':checkbox').fieldValue();
 *  // if neither checkbox is checked
 *  v === undefined
 *  // if both checkboxes are checked
 *  v == ['B1', 'B2']
 *
 *  var v = $(':radio').fieldValue();
 *  // if neither radio is checked
 *  v === undefined
 *  // if first radio is checked
 *  v == ['C1']
 *
 * The successful argument controls whether or not the field element must be 'successful'
 * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
 * The default value of the successful argument is true.  If this value is false the value(s)
 * for each element is returned.
 *
 * Note: This method *always* returns an array.  If no valid value can be determined the
 *	   array will be empty, otherwise it will contain one or more values.
 */
$.fn.fieldValue = function(successful) {
	for (var val=[], i=0, max=this.length; i < max; i++) {
		var el = this[i];
		var v = $.fieldValue(el, successful);
		if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
			continue;
		}
		v.constructor == Array ? $.merge(val, v) : val.push(v);
	}
	return val;
};

/**
 * Returns the value of the field element.
 */
$.fieldValue = function(el, successful) {
	var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
	if (successful === undefined) {
		successful = true;
	}

	if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
		(t == 'checkbox' || t == 'radio') && !el.checked ||
		(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
		tag == 'select' && el.selectedIndex == -1)) {
			return null;
	}

	if (tag == 'select') {
		var index = el.selectedIndex;
		if (index < 0) {
			return null;
		}
		var a = [], ops = el.options;
		var one = (t == 'select-one');
		var max = (one ? index+1 : ops.length);
		for(var i=(one ? index : 0); i < max; i++) {
			var op = ops[i];
			if (op.selected) {
				var v = op.value;
				if (!v) { // extra pain for IE...
					v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
				}
				if (one) {
					return v;
				}
				a.push(v);
			}
		}
		return a;
	}
	return $(el).val();
};

/**
 * Clears the form data.  Takes the following actions on the form's input fields:
 *  - input text fields will have their 'value' property set to the empty string
 *  - select elements will have their 'selectedIndex' property set to -1
 *  - checkbox and radio inputs will have their 'checked' property set to false
 *  - inputs of type submit, button, reset, and hidden will *not* be effected
 *  - button elements will *not* be effected
 */
$.fn.clearForm = function() {
	return this.each(function() {
		$('input,select,textarea', this).clearFields();
	});
};

/**
 * Clears the selected form elements.
 */
$.fn.clearFields = $.fn.clearInputs = function() {
	return this.each(function() {
		var t = this.type, tag = this.tagName.toLowerCase();
		if (t == 'text' || t == 'password' || tag == 'textarea') {
			this.value = '';
		}
		else if (t == 'checkbox' || t == 'radio') {
			this.checked = false;
		}
		else if (tag == 'select') {
			this.selectedIndex = -1;
		}
	});
};

/**
 * Resets the form data.  Causes all form elements to be reset to their original value.
 */
$.fn.resetForm = function() {
	return this.each(function() {
		// guard against an input with the name of 'reset'
		// note that IE reports the reset function as an 'object'
		if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
			this.reset();
		}
	});
};

/**
 * Enables or disables any matching elements.
 */
$.fn.enable = function(b) {
	if (b === undefined) {
		b = true;
	}
	return this.each(function() {
		this.disabled = !b;
	});
};

/**
 * Checks/unchecks any matching checkboxes or radio buttons and
 * selects/deselects and matching option elements.
 */
$.fn.selected = function(select) {
	if (select === undefined) {
		select = true;
	}
	return this.each(function() {
		var t = this.type;
		if (t == 'checkbox' || t == 'radio') {
			this.checked = select;
		}
		else if (this.tagName.toLowerCase() == 'option') {
			var $sel = $(this).parent('select');
			if (select && $sel[0] && $sel[0].type == 'select-one') {
				// deselect all other options
				$sel.find('option').selected(false);
			}
			this.selected = select;
		}
	});
};

// helper fn for console logging
// set $.fn.ajaxSubmit.debug to true to enable debug logging
function log() {
	if ($.fn.ajaxSubmit.debug) {
		var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
		if (window.console && window.console.log) {
			window.console.log(msg);
		}
		else if (window.opera && window.opera.postError) {
			window.opera.postError(msg);
		}
	}
};

})(jQuery);

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 18:31:45 By : dev
 


 

No. 7



โพสกระทู้ ( 3,468 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter

ให้หา เอกสารมาดูครับ เรา อาจสามารถส่ง callback ไปได้ ไม่ก็ validate rule
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 18:58:56 By : pjgunner
 


 

No. 8

Guest


Code (PHP)
ก็ตามกระทู้ข้างบนบอก ควรจะหา เอกสาร หรือ เข้าใจ code ajax ก่อน แต่ผมเขียนมาให้คุณดูและ ลองดูละกัน

<?
//include_once '../includes/connect.php';
?>
<script src="jquery.form.js" type="text/javascript"></script>
<script type="text/javascript">
    
    $(document).ready(function() {
		$("#myForm").submit(function () {

			if($("#name").val() == ''){
				alert("ชื่อบ่อ ยังเป็นค่าว่าง !!");
				return false;				
			}
		});
    });
</script>
<form id="myForm" name="myForm" method="post" action="poolAdd_script.php"  enctype="multipart/form-data">
  <table width="100%" cellpadding="9" cellspacing="0" border="0">
    <tr>
      <td colspan="2" class="title2">เพิ่มข้อมูลบ่อใหม่</td>
    </tr>
    <tr>
      <td width="20%" class="TD_title">ชื่อบ่อ: </td>
      <td align="left" width="80%"><input type="text" name="name" value="" id="name" class="textboxlong" /></td>
    </tr>
    <tr>
      <td width="20%" class="TD_title">สถานะ: </td>
      <td align="left" width="80%"><input name="status" type="radio" value="y" checked="checked" />เปิดใช้ &nbsp;&nbsp;<input name="status" type="radio" value="n" />ไม่เปิดใช้</td>
    </tr>
    <tr>
      <td width="20%" class="TD_title">Note: </td>
      <td align="left" width="80%"><label>
        <textarea name="note" id="note" cols="60" rows="5" class="textarea"></textarea>
      </label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="left" width="80%"><div id="buttonDiv">
        <input type="submit" value="บันทึก" class="button" />
        <input type="button" name="button2" value="ย้อนกลับ" onClick="javascript:LoadContentDIV('poolData.php');" class="button" />
      </div>
        <div id="Loading" style="padding: 10px; text-align: center; display:none;  color: red;"><img src="../images/loader_twt.gif" alt="" /> กำลังบันทึกข้อมูล..</div></td>
    </tr>
  </table>
</form>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 19:18:39 By : burn
 


 

No. 9

Guest


ผมลองสคริปข้างบนแล้ว ใช้ได้นะครับ
แต่ บังเอิญว่า ผมมี สคริปสองอันด้วยกัน เหมือนมันจะชนกันครับ ทำไงดี
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 21:26:30 By : dev
 


 

No. 10

Guest


แล้วปกติตอนยังไม่เพิ่ม code เลยเนี่ยใช่ได้มั๊ย แบบมาแรกๆเลย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 22:11:28 By : burn
 


 

No. 11

Guest


ใช้ได้ถึงแค่ บอกว่า กรอกข้อมูลไม่ครบครับ แต่มันก็ยัง insert ข้อมูลอยู่

พอเอาของ Reply บนมาใช้ ได้นะครับ เพราะมี javascript อันเดียว


แต่พอใส่ javascript เข้าไปอีกอันเพื่อโหลด page มันก็กลับไปเป็นเหมือนเดิมคือ เตือนว่าไม่ได้กรอก แต่ก็ insert อีกเหมือนกัน
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 23:28:52 By : dev
 


 

No. 12

Guest


โอย ทำได้แล้วครับผม :) นั่งแก้อยู่นานมาก ขอบคุณสำหรับคอมเม็นท์นะครับ

ผมแค่สลับ javascript ให้มันเชคค่าว่างก่อน แล้วค่อย โหลด page แค่นั้นเอง ความโง่... มันบังตา อายจัง ขอบคุณครับ อิอิ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-01 11:05:10 By : dev
 


 

No. 13

Guest


ของผมไม่ทำงานครับ

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="DESCRIPTION" content="">
<meta name="KEYWORDS" content="">
<meta name="revisit-after" content="31 days">
<meta name="audience" content="all">
<meta name="expires" content="never">
<meta name="rating" content="general">
<meta name="classification" content="general">
<meta name="distribution" content="global">
<style type="text/css">
<!--
.style11 {color: #FF0000}
-->
</style>
</head>
<script type="text/javascript">
<!--
function new_captcha()
{
var c_currentTime = new Date();
var c_miliseconds = c_currentTime.getTime();

document.getElementById('captcha').src = 'image.php?x='+ c_miliseconds;
}
-->
</script>
<link href="style.css" rel="stylesheet" type="text/css" />
<body>
<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td align="center" valign="middle"><img src="images/bannner-new-condo-pattaya-property-for-sale.jpg" width="1011" height="332" /></td>
</tr>
<tr>
<td align="center" valign="middle"><table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr>
<td width="9%" align="center" valign="baseline"><span class="style2"><a href="index.html">Home</a></span></td>
<td width="17%" align="center" valign="bottom" class="style2"><a href="interior-perspectives-condo-for-sale.html">Interior Perpectives</a></td>
<td width="17%" align="center" valign="bottom"><span class="style2"><a href="facilities-perspectives-pattaya-condo-villas-for-sale.html">Facilities Perpectives</a></span></td>
<td width="15%" align="center" valign="bottom" class="style2"><a href="floor-unit-plan-pattaya-condo-villas-for-sale.html">Floor &amp; Unit Plan</a></td>
<td width="16%" align="center" valign="bottom" class="style2"><a href="price-pattaya-condo-villas-for-sale.html">Availability &amp; Prices</a></td>
<td width="12%" align="center" valign="bottom"><span class="style2"><a href="location-pattaya-condo-villas-for-sale.html">Location</a></span></td>
<td width="14%" align="center" valign="bottom" class="style2"><a href="contact-pattaya-condo-villas-for-sale.html">Contact us</a></td>
</tr>
</table></td>
</tr>
<tr>
<td align="center" valign="middle">&nbsp;</td>
</tr>
<tr>
<td align="center" valign="top"><table width="90%" border="0" align="center">
<tr>
<td align="left" valign="top"><p class="style9">CONTACT US</p></td>
</tr>
<tr>
<td align="center" valign="top">
<script language="JavaScript" type="text/javascript">
function formOk(){
var cemail = document.getElementById('Email');
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

if(document.form2.FirstName.value.length==""){
alert("Please enter first name");
document.form2.Name.focus();
return false;
}else if(document.form2.LastName.value.length==""){
alert("Please enter last name");
document.form2.LastName.focus();
return false;
}else if(document.form2.Address.value.length==""){
alert("Please enter address");
document.form2.Address.focus();
return false;
}else if(document.form2.Phone.value.length==""){
alert("Please enter phone");
document.form2.Phone.focus();
return false;
}else if(document.form2.Mobile.value.length==""){
alert("Please enter mobile");
document.form2.Mobile.focus();
return false;
}else if(!filter.test(cemail.value)){
alert("Please enter a valid email address");
document.form2.Email.focus();
return false;
}else if(document.form2.Comments.value.length==""){
alert("Please enter Specific Question");
document.form2.Comments.focus();
return false;
}else if(document.form2.security_code.value.length==""){
alert("Please enter the security code");
document.form2.security_code.focus();
return false;
}else{
form2.Submit2.disabled = true;
return true;
}
}
</script>
<form id="form2" name="form2" method="post" action="../../input.php" onsubmit="return formOk()">
<input type="hidden" name="TOFORM" value="CONTACT_DEVELOPMENT" />
<table width="100%" border="0">
<tr>
<td><br />
<table width="70%" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td width="32%" align="right" valign="top" class="style4">First name: </td>
<td width="68%" align="left" valign="top"><input name="FirstName" type="text" class="Box1" id="FirstName" value="" size="40" />
<span class="style11">*</span></td>
</tr>
<tr>
<td align="right" valign="top" class="style4">Last name: </td>
<td align="left" valign="top"><input name="LastName" type="text" class="Box1" id="LastName" value="" size="40" />
<span class="style11">*</span></td>
</tr>
<tr>
<td align="right" valign="top" class="style4">Address: </td>
<td align="left" valign="top"><textarea name="Address" cols="40" rows="3" class="Box1" id="Address"></textarea>
<span class="style11">*</span></td>
</tr>
<tr>
<td align="right" valign="top" class="style4">Phone: </td>
<td align="left" valign="top"><input name="Phone" type="text" class="Box1" id="Phone" size="40" />
<span class="style11">*</span></td>
</tr>
<tr>
<td align="right" valign="top" class="style4">Fax: </td>
<td align="left" valign="top"><input name="Fax" type="text" class="Box1" id="Phone4" size="40" /></td>
</tr>
<tr>
<td align="right" valign="top" class="style4">Mobile: </td>
<td align="left" valign="top"><input name="Mobile" type="text" class="Box1" id="Phone3" size="40" />
<span class="style11">*</span></td>
</tr>
<tr>
<td align="right" valign="top" class="style4">E-mail: </td>
<td align="left" valign="top"><input name="Email" type="text" class="Box1" id="Email" value="" size="40" />
<span class="style11">*</span></td>
</tr>
<tr>
<td align="right" valign="top" class="style4">Schedule to invest: </td>
<td align="left" valign="top"><input name="Schedule" type="text" class="Box1" id="Schedule" size="40" /></td>
</tr>
<tr>
<td align="right" valign="top" class="style4">Specific question:</td>
<td align="left" valign="top"><textarea name="Comments" cols="50" rows="15" class="Box1" id="Comments"></textarea></td>
</tr>
<tr>
<td colspan="2" class="TextBlack12Bold">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="left" valign="top" class="style12">Confirmation security code: * Enter the code exactly as you see it. The code is lowercase sensitive and zero has a diagonal line through it.</td>
</tr>
<tr>
<td colspan="2" align="center"><img src="image.php" alt="" name="captcha" border="0" id="captcha" /> &nbsp;<a href="JavaScript: new_captcha();"><img src="../../images/refresh.jpg" alt="" width="30" height="30" border="0" align="bottom" /></a></td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle"><span class="style4">Security Code (lowercase )</span><br />
<input name="security_code" type="text" class="Box1" id="security_code" size="30" /></td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle">&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle"><label>
<input name="Submit2" type="submit" class="Box1" value="Send" />
</label></td>
</tr>
</table></td>
</tr>
<tr>
<td align="right">&nbsp;</td>
</tr>
</table>
<br />
</form>
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-05-13 00:34:06 By : Suchart
 


 

No. 14

Guest


ตอบความคิดเห็นที่ : 13 เขียนโดย : Suchart เมื่อวันที่ 2012-05-13 00:34:06
รายละเอียดของการตอบ ::
... ทำได้แล้วครับ....................

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-05-13 01:57:22 By : Suchart
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : เรียกใช้ java script แล้วสั่ง return false; แต่ form มันไม่หยุดคำสั่ง action มันก็เลย add data เปล่า ๆ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่