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,038

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


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

 
Topic : 047991

Guest



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



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

Code (PHP)
1.<form id="myForm" name="myForm" method="post" onsubmit="return check();" action="poolAdd_script.php">
2.<table>
3.<tr>
4.      <td width="20%" class="TD_title">ชื่อ: </td>
5.      <td align="left" width="80%"><input type="text" name="name" value="" id="name" class="textboxlong" /></td>
6.    </tr>
7.</table>
8.</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 : 4212 Reply : 14
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 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)
01.<?
02.include_once '../includes/connect.php';
03.?>
04.<script src="../includes/js/jquery/jquery.form.js" type="text/javascript"></script>
05.<script type="text/javascript">
06.       $(document).ready(function() {
07.            $('#myForm').ajaxForm({
08.                dataType:  'json',
09.                success:   function processJson(resPonse) {
10.                            if(resPonse==1){
11.                                $('#Loading').hide();
12.                                $('#Loading1').show();
13.                                $('#Loading1').fadeOut(1500);
14.                                $('#myForm').reset();
15.                            } else {
16.                                $('#Loading1').hide();
17.                                $('#Loading').show();
18.                                $('#Loading1').show(1500);
19.                            }
20.                        }
21.            });
22.        });
23.        
24.function check(){
25.       if(document.myForm.name.value == ''){
26.            alert("คุณยังไม่ได้กรอกข้อมูล ชื่อบ่อ");
27.            document.myForm.note.focus();
28.            return false;
29.        }     
30.}
31.</script>
32. 
33.<form id="myForm" name="myForm" method="post" onsubmit="return check();" action="poolAdd_script.php"  enctype="multipart/form-data">
34.  <table width="100%" cellpadding="9" cellspacing="0" border="0">
35.    <tr>
36.      <td colspan="2" class="title2">เพิ่มข้อมูลบ่อใหม่</td>
37.    </tr>
38.    <tr>
39.      <td width="20%" class="TD_title">ชื่อบ่อ: </td>
40.      <td align="left" width="80%"><input type="text" name="name" value="" id="name" class="textboxlong" /></td>
41.    </tr>
42.    <tr>
43.      <td width="20%" class="TD_title">สถานะ: </td>
44.      <td align="left" width="80%"><input name="status" type="radio" value="y" checked="checked" />เปิดใช้ &nbsp;&nbsp;<input name="status" type="radio" value="n" />ไม่เปิดใช้</td>
45.    </tr>
46.    <tr>
47.      <td width="20%" class="TD_title">Note: </td>
48.      <td align="left" width="80%"><label>
49.        <textarea name="note" id="note" cols="60" rows="5" class="textarea"></textarea>
50.      </label></td>
51.    </tr>
52.    <tr>
53.      <td>&nbsp;</td>
54.      <td align="left" width="80%"><div id="buttonDiv">
55.        <input type="submit" name="button1" value="บันทึก" class="button" />
56.        <input type="button" name="button2" value="ย้อนกลับ" onClick="javascript:LoadContentDIV('poolData.php');" class="button" />
57.      </div>
58.        <div id="Loading" style="padding: 10px; text-align: center; display:none;  color: red;"><img src="../images/loader_twt.gif" alt="" /> กำลังบันทึกข้อมูล..</div></td>
59.    </tr>
60.  </table>
61.</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)
001./*!
002. * jQuery Form Plugin
003. * version: 2.45 (09-AUG-2010)
004. * @requires jQuery v1.3.2 or later
005. *
006. * Examples and documentation at: http://malsup.com/jquery/form/
007. * Dual licensed under the MIT and GPL licenses:
010. */
011.;(function($) {
012. 
013./*
014.    Usage Note:
015.    -----------
016.    Do not use both ajaxSubmit and ajaxForm on the same form.  These
017.    functions are intended to be exclusive.  Use ajaxSubmit if you want
018.    to bind your own submit handler to the form.  For example,
019. 
020.    $(document).ready(function() {
021.        $('#myForm').bind('submit', function() {
022.            $(this).ajaxSubmit({
023.                target: '#output'
024.            });
025.            return false; // <-- important!
026.        });
027.    });
028. 
029.    Use ajaxForm when you want the plugin to manage all the event binding
030.    for you.  For example,
031. 
032.    $(document).ready(function() {
033.        $('#myForm').ajaxForm({
034.            target: '#output'
035.        });
036.    });
037. 
038.    When using ajaxForm, the ajaxSubmit function will be invoked for you
039.    at the appropriate time.
040.*/
041. 
042./**
043. * ajaxSubmit() provides a mechanism for immediately submitting
044. * an HTML form using AJAX.
045. */
046.$.fn.ajaxSubmit = function(options) {
047.    // fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
048.    if (!this.length) {
049.        log('ajaxSubmit: skipping submit process - no element selected');
050.        return this;
051.    }
052. 
053.    if (typeof options == 'function') {
054.        options = { success: options };
055.    }
056. 
057.    var url = $.trim(this.attr('action'));
058.    if (url) {
059.        // clean url (don't include hash vaue)
060.        url = (url.match(/^([^#]+)/)||[])[1];
061.    }
062.    url = url || window.location.href || '';
063. 
064.    options = $.extend(true, {
065.        url:  url,
066.        type: this.attr('method') || 'GET',
067.        iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
068.    }, options);
069. 
070.    // hook for manipulating the form data before it is extracted;
071.    // convenient for use with rich editors like tinyMCE or FCKEditor
072.    var veto = {};
073.    this.trigger('form-pre-serialize', [this, options, veto]);
074.    if (veto.veto) {
075.        log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
076.        return this;
077.    }
078. 
079.    // provide opportunity to alter form data before it is serialized
080.    if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
081.        log('ajaxSubmit: submit aborted via beforeSerialize callback');
082.        return this;
083.    }
084. 
085.    var n,v,a = this.formToArray(options.semantic);
086.    if (options.data) {
087.        options.extraData = options.data;
088.        for (n in options.data) {
089.            if(options.data[n] instanceof Array) {
090.                for (var k in options.data[n]) {
091.                    a.push( { name: n, value: options.data[n][k] } );
092.                }
093.            }
094.            else {
095.                v = options.data[n];
096.                v = $.isFunction(v) ? v() : v; // if value is fn, invoke it
097.                a.push( { name: n, value: v } );
098.            }
099.        }
100.    }
101. 
102.    // give pre-submit callback an opportunity to abort the submit
103.    if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
104.        log('ajaxSubmit: submit aborted via beforeSubmit callback');
105.        return this;
106.    }
107. 
108.    // fire vetoable 'validate' event
109.    this.trigger('form-submit-validate', [a, this, options, veto]);
110.    if (veto.veto) {
111.        log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
112.        return this;
113.    }
114. 
115.    var q = $.param(a);
116. 
117.    if (options.type.toUpperCase() == 'GET') {
118.        options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
119.        options.data = null;  // data is null for 'get'
120.    }
121.    else {
122.        options.data = q; // data is the query string for 'post'
123.    }
124. 
125.    var $form = this, callbacks = [];
126.    if (options.resetForm) {
127.        callbacks.push(function() { $form.resetForm(); });
128.    }
129.    if (options.clearForm) {
130.        callbacks.push(function() { $form.clearForm(); });
131.    }
132. 
133.    // perform a load on the target only if dataType is not provided
134.    if (!options.dataType && options.target) {
135.        var oldSuccess = options.success || function(){};
136.        callbacks.push(function(data) {
137.            var fn = options.replaceTarget ? 'replaceWith' : 'html';
138.            $(options.target)[fn](data).each(oldSuccess, arguments);
139.        });
140.    }
141.    else if (options.success) {
142.        callbacks.push(options.success);
143.    }
144. 
145.    options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
146.        var context = options.context || options;   // jQuery 1.4+ supports scope context
147.        for (var i=0, max=callbacks.length; i < max; i++) {
148.            callbacks[i].apply(context, [data, status, xhr || $form, $form]);
149.        }
150.    };
151. 
152.    // are there files to upload?
153.    var fileInputs = $('input:file', this).length > 0;
154.    var mp = 'multipart/form-data';
155.    var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
156. 
157.    // options.iframe allows user to force iframe mode
158.    // 06-NOV-09: now defaulting to iframe mode if file input is detected
159.   if (options.iframe !== false && (fileInputs || options.iframe || multipart)) {
160.       // hack to fix Safari hang (thanks to Tim Molendijk for this)
162.       if (options.closeKeepAlive) {
163.           $.get(options.closeKeepAlive, fileUpload);
164.        }
165.       else {
166.           fileUpload();
167.        }
168.   }
169.   else {
170.       $.ajax(options);
171.   }
172. 
173.    // fire 'notify' event
174.    this.trigger('form-submit-notify', [this, options]);
175.    return this;
176. 
177. 
178.    // private function for handling file uploads (hat tip to YAHOO!)
179.    function fileUpload() {
180.        var form = $form[0];
181. 
182.        if ($(':input[name=submit],:input[id=submit]', form).length) {
183.            // if there is an input with a name or id of 'submit' then we won't be
184.            // able to invoke the submit fn on the form (at least not x-browser)
185.            alert('Error: Form elements must not have name or id of "submit".');
186.            return;
187.        }
188. 
189.        var s = $.extend(true, {}, $.ajaxSettings, options);
190.        s.context = s.context || s;
191.        var id = 'jqFormIO' + (new Date().getTime());
192.        var $io = $('<iframe id="' + id + '" name="' + id + '" src="'+ s.iframeSrc +'" onload="var f = jQuery(this).data(\'form-plugin-onload\'); if (f) f();" />');
193.        var io = $io[0];
194. 
195.        $io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
196. 
197.        var xhr = { // mock object
198.            aborted: 0,
199.            responseText: null,
200.            responseXML: null,
201.            status: 0,
202.            statusText: 'n/a',
203.            getAllResponseHeaders: function() {},
204.            getResponseHeader: function() {},
205.            setRequestHeader: function() {},
206.            abort: function() {
207.                this.aborted = 1;
208.                $io.attr('src', s.iframeSrc); // abort op in progress
209.            }
210.        };
211. 
212.        var g = s.global;
213.        // trigger ajax global events so that activity/block indicators work like normal
214.        if (g && ! $.active++) {
215.            $.event.trigger("ajaxStart");
216.        }
217.        if (g) {
218.            $.event.trigger("ajaxSend", [xhr, s]);
219.        }
220. 
221.        if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
222.            if (s.global) {
223.                $.active--;
224.            }
225.            return;
226.        }
227.        if (xhr.aborted) {
228.            return;
229.        }
230. 
231.        var cbInvoked = false;
232.        var timedOut = 0;
233. 
234.        // add submitting element to data if we know it
235.        var sub = form.clk;
236.        if (sub) {
237.            var n = sub.name;
238.            if (n && !sub.disabled) {
239.                s.extraData = s.extraData || {};
240.                s.extraData[n] = sub.value;
241.                if (sub.type == "image") {
242.                    s.extraData[n+'.x'] = form.clk_x;
243.                    s.extraData[n+'.y'] = form.clk_y;
244.                }
245.            }
246.        }
247. 
248.        // take a breath so that pending repaints get some cpu time before the upload starts
249.        function doSubmit() {
250.            // make sure form attrs are set
251.            var t = $form.attr('target'), a = $form.attr('action');
252. 
253.            // update form attrs in IE friendly way
254.            form.setAttribute('target',id);
255.            if (form.getAttribute('method') != 'POST') {
256.                form.setAttribute('method', 'POST');
257.            }
258.            if (form.getAttribute('action') != s.url) {
259.                form.setAttribute('action', s.url);
260.            }
261. 
262.            // ie borks in some cases when setting encoding
263.            if (! s.skipEncodingOverride) {
264.                $form.attr({
265.                    encoding: 'multipart/form-data',
266.                    enctype:  'multipart/form-data'
267.                });
268.            }
269. 
270.            // support timout
271.            if (s.timeout) {
272.                setTimeout(function() { timedOut = true; cb(); }, s.timeout);
273.            }
274. 
275.            // add "extra" data to form if provided in options
276.            var extraInputs = [];
277.            try {
278.                if (s.extraData) {
279.                    for (var n in s.extraData) {
280.                        extraInputs.push(
281.                            $('<input type="hidden" name="'+n+'" value="'+s.extraData[n]+'" />')
282.                                .appendTo(form)[0]);
283.                    }
284.                }
285. 
286.                // add iframe to doc and submit the form
287.                $io.appendTo('body');
288.                $io.data('form-plugin-onload', cb);
289.                form.submit();
290.            }
291.            finally {
292.                // reset attrs and remove "extra" input elements
293.                form.setAttribute('action',a);
294.                if(t) {
295.                    form.setAttribute('target', t);
296.                } else {
297.                    $form.removeAttr('target');
298.                }
299.                $(extraInputs).remove();
300.            }
301.        }
302. 
303.        if (s.forceSync) {
304.            doSubmit();
305.        }
306.        else {
307.            setTimeout(doSubmit, 10); // this lets dom updates render
308.        }
309.     
310.        var data, doc, domCheckCount = 100;
311. 
312.        function cb() {
313.            if (cbInvoked) {
314.                return;
315.            }
316. 
317.            $io.removeData('form-plugin-onload');
318.             
319.            var ok = true;
320.            try {
321.                if (timedOut) {
322.                    throw 'timeout';
323.                }
324.                // extract the server response from the iframe
325.                doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
326.                 
327.                var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
328.                log('isXml='+isXml);
329.                if (!isXml && (doc.body == null || doc.body.innerHTML == '')) {
330.                    if (--domCheckCount) {
331.                        // in some browsers (Opera) the iframe DOM is not always traversable when
332.                        // the onload callback fires, so we loop a bit to accommodate
333.                        log('requeing onLoad callback, DOM not available');
334.                        setTimeout(cb, 250);
335.                        return;
336.                    }
337.                    log('Could not access iframe DOM after 100 tries.');
338.                    throw 'DOMException: not available';
339.                }
340. 
341.                log('response detected');
342.                cbInvoked = true;
343.                xhr.responseText = doc.documentElement ? doc.documentElement.innerHTML : null;
344.                xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
345.                xhr.getResponseHeader = function(header){
346.                    var headers = {'content-type': s.dataType};
347.                    return headers[header];
348.                };
349. 
350.                var scr = /(json|script)/.test(s.dataType);
351.                if (scr || s.textarea) {
352.                    // see if user embedded response in textarea
353.                    var ta = doc.getElementsByTagName('textarea')[0];
354.                    if (ta) {
355.                        xhr.responseText = ta.value;
356.                    }
357.                    else if (scr) {
358.                        // account for browsers injecting pre around json response
359.                        var pre = doc.getElementsByTagName('pre')[0];
360.                        if (pre) {
361.                            xhr.responseText = pre.innerHTML;
362.                        }
363.                    }            
364.                }
365.                else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
366.                    xhr.responseXML = toXml(xhr.responseText);
367.                }
368.                data = $.httpData(xhr, s.dataType);
369.            }
370.            catch(e){
371.                log('error caught:',e);
372.                ok = false;
373.                xhr.error = e;
374.                $.handleError(s, xhr, 'error', e);
375.            }
376. 
377.            // ordering of these callbacks/triggers is odd, but that's how $.ajax does it
378.            if (ok) {
379.                s.success.call(s.context, data, 'success');
380.                if (g) {
381.                    $.event.trigger("ajaxSuccess", [xhr, s]);
382.                }
383.            }
384.            if (g) {
385.                $.event.trigger("ajaxComplete", [xhr, s]);
386.            }
387.            if (g && ! --$.active) {
388.                $.event.trigger("ajaxStop");
389.            }
390.            if (s.complete) {
391.                s.complete.call(s.context, xhr, ok ? 'success' : 'error');
392.            }
393. 
394.            // clean up
395.            setTimeout(function() {
396.                $io.removeData('form-plugin-onload');
397.                $io.remove();
398.                xhr.responseXML = null;
399.            }, 100);
400.        }
401. 
402.        function toXml(s, doc) {
403.            if (window.ActiveXObject) {
404.                doc = new ActiveXObject('Microsoft.XMLDOM');
405.                doc.async = 'false';
406.                doc.loadXML(s);
407.            }
408.            else {
409.                doc = (new DOMParser()).parseFromString(s, 'text/xml');
410.            }
411.            return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
412.        }
413.    }
414.};
415. 
416./**
417. * ajaxForm() provides a mechanism for fully automating form submission.
418. *
419. * The advantages of using this method instead of ajaxSubmit() are:
420. *
421. * 1: This method will include coordinates for <input type="image" /> elements (if the element
422. *  is used to submit the form).
423. * 2. This method will include the submit element's name/value data (for the element that was
424. *  used to submit the form).
425. * 3. This method binds the submit() method to the form for you.
426. *
427. * The options argument for ajaxForm works exactly as it does for ajaxSubmit.  ajaxForm merely
428. * passes the options argument along after properly binding events for submit elements and
429. * the form itself.
430. */
431.$.fn.ajaxForm = function(options) {
432.    // in jQuery 1.3+ we can fix mistakes with the ready state
433.    if (this.length === 0) {
434.        var o = { s: this.selector, c: this.context };
435.        if (!$.isReady && o.s) {
436.            log('DOM not ready, queuing ajaxForm');
437.            $(function() {
438.                $(o.s,o.c).ajaxForm(options);
439.            });
440.            return this;
441.        }
442.        // is your DOM ready?  http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
443.        log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
444.        return this;
445.    }
446.     
447.    return this.ajaxFormUnbind().bind('submit.form-plugin', function(e) {
448.        if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
449.            e.preventDefault();
450.            $(this).ajaxSubmit(options);
451.        }
452.    }).bind('click.form-plugin', function(e) {
453.        var target = e.target;
454.        var $el = $(target);
455.        if (!($el.is(":submit,input:image"))) {
456.            // is this a child element of the submit el?  (ex: a span within a button)
457.            var t = $el.closest(':submit');
458.            if (t.length == 0) {
459.                return;
460.            }
461.            target = t[0];
462.        }
463.        var form = this;
464.        form.clk = target;
465.        if (target.type == 'image') {
466.            if (e.offsetX != undefined) {
467.                form.clk_x = e.offsetX;
468.                form.clk_y = e.offsetY;
469.            } else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
470.                var offset = $el.offset();
471.                form.clk_x = e.pageX - offset.left;
472.                form.clk_y = e.pageY - offset.top;
473.            } else {
474.                form.clk_x = e.pageX - target.offsetLeft;
475.                form.clk_y = e.pageY - target.offsetTop;
476.            }
477.        }
478.        // clear form vars
479.        setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
480.    });
481.};
482. 
483.// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
484.$.fn.ajaxFormUnbind = function() {
485.    return this.unbind('submit.form-plugin click.form-plugin');
486.};
487. 
488./**
489. * formToArray() gathers form element data into an array of objects that can
490. * be passed to any of the following ajax functions: $.get, $.post, or load.
491. * Each object in the array has both a 'name' and 'value' property.  An example of
492. * an array for a simple login form might be:
493. *
494. * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
495. *
496. * It is this array that is passed to pre-submit callback functions provided to the
497. * ajaxSubmit() and ajaxForm() methods.
498. */
499.$.fn.formToArray = function(semantic) {
500.    var a = [];
501.    if (this.length === 0) {
502.        return a;
503.    }
504. 
505.    var form = this[0];
506.    var els = semantic ? form.getElementsByTagName('*') : form.elements;
507.    if (!els) {
508.        return a;
509.    }
510.     
511.    var i,j,n,v,el;
512.    for(i=0, max=els.length; i < max; i++) {
513.        el = els[i];
514.        n = el.name;
515.        if (!n) {
516.            continue;
517.        }
518. 
519.        if (semantic && form.clk && el.type == "image") {
520.            // handle image inputs on the fly when semantic == true
521.            if(!el.disabled && form.clk == el) {
522.                a.push({name: n, value: $(el).val()});
523.                a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
524.            }
525.            continue;
526.        }
527. 
528.        v = $.fieldValue(el, true);
529.        if (v && v.constructor == Array) {
530.            for(j=0, jmax=v.length; j < jmax; j++) {
531.                a.push({name: n, value: v[j]});
532.            }
533.        }
534.        else if (v !== null && typeof v != 'undefined') {
535.            a.push({name: n, value: v});
536.        }
537.    }
538. 
539.    if (!semantic && form.clk) {
540.        // input type=='image' are not found in elements array! handle it here
541.        var $input = $(form.clk), input = $input[0];
542.        n = input.name;
543.        if (n && !input.disabled && input.type == 'image') {
544.            a.push({name: n, value: $input.val()});
545.            a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
546.        }
547.    }
548.    return a;
549.};
550. 
551./**
552. * Serializes form data into a 'submittable' string. This method will return a string
553. * in the format: name1=value1&amp;name2=value2
554. */
555.$.fn.formSerialize = function(semantic) {
556.    //hand off to jQuery.param for proper encoding
557.    return $.param(this.formToArray(semantic));
558.};
559. 
560./**
561. * Serializes all field elements in the jQuery object into a query string.
562. * This method will return a string in the format: name1=value1&amp;name2=value2
563. */
564.$.fn.fieldSerialize = function(successful) {
565.    var a = [];
566.    this.each(function() {
567.        var n = this.name;
568.        if (!n) {
569.            return;
570.        }
571.        var v = $.fieldValue(this, successful);
572.        if (v && v.constructor == Array) {
573.            for (var i=0,max=v.length; i < max; i++) {
574.                a.push({name: n, value: v[i]});
575.            }
576.        }
577.        else if (v !== null && typeof v != 'undefined') {
578.            a.push({name: this.name, value: v});
579.        }
580.    });
581.    //hand off to jQuery.param for proper encoding
582.    return $.param(a);
583.};
584. 
585./**
586. * Returns the value(s) of the element in the matched set.  For example, consider the following form:
587. *
588. *  <form><fieldset>
589. *    <input name="A" type="text" />
590. *    <input name="A" type="text" />
591. *    <input name="B" type="checkbox" value="B1" />
592. *    <input name="B" type="checkbox" value="B2"/>
593. *    <input name="C" type="radio" value="C1" />
594. *    <input name="C" type="radio" value="C2" />
595. *  </fieldset></form>
596. *
597. *  var v = $(':text').fieldValue();
598. *  // if no values are entered into the text inputs
599. *  v == ['','']
600. *  // if values entered into the text inputs are 'foo' and 'bar'
601. *  v == ['foo','bar']
602. *
603. *  var v = $(':checkbox').fieldValue();
604. *  // if neither checkbox is checked
605. *  v === undefined
606. *  // if both checkboxes are checked
607. *  v == ['B1', 'B2']
608. *
609. *  var v = $(':radio').fieldValue();
610. *  // if neither radio is checked
611. *  v === undefined
612. *  // if first radio is checked
613. *  v == ['C1']
614. *
615. * The successful argument controls whether or not the field element must be 'successful'
616. * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
617. * The default value of the successful argument is true.  If this value is false the value(s)
618. * for each element is returned.
619. *
620. * Note: This method *always* returns an array.  If no valid value can be determined the
621. *     array will be empty, otherwise it will contain one or more values.
622. */
623.$.fn.fieldValue = function(successful) {
624.    for (var val=[], i=0, max=this.length; i < max; i++) {
625.        var el = this[i];
626.        var v = $.fieldValue(el, successful);
627.        if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
628.            continue;
629.        }
630.        v.constructor == Array ? $.merge(val, v) : val.push(v);
631.    }
632.    return val;
633.};
634. 
635./**
636. * Returns the value of the field element.
637. */
638.$.fieldValue = function(el, successful) {
639.    var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
640.    if (successful === undefined) {
641.        successful = true;
642.    }
643. 
644.    if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
645.        (t == 'checkbox' || t == 'radio') && !el.checked ||
646.        (t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
647.        tag == 'select' && el.selectedIndex == -1)) {
648.            return null;
649.    }
650. 
651.    if (tag == 'select') {
652.        var index = el.selectedIndex;
653.        if (index < 0) {
654.            return null;
655.        }
656.        var a = [], ops = el.options;
657.        var one = (t == 'select-one');
658.        var max = (one ? index+1 : ops.length);
659.        for(var i=(one ? index : 0); i < max; i++) {
660.            var op = ops[i];
661.            if (op.selected) {
662.                var v = op.value;
663.                if (!v) { // extra pain for IE...
664.                    v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
665.                }
666.                if (one) {
667.                    return v;
668.                }
669.                a.push(v);
670.            }
671.        }
672.        return a;
673.    }
674.    return $(el).val();
675.};
676. 
677./**
678. * Clears the form data.  Takes the following actions on the form's input fields:
679. *  - input text fields will have their 'value' property set to the empty string
680. *  - select elements will have their 'selectedIndex' property set to -1
681. *  - checkbox and radio inputs will have their 'checked' property set to false
682. *  - inputs of type submit, button, reset, and hidden will *not* be effected
683. *  - button elements will *not* be effected
684. */
685.$.fn.clearForm = function() {
686.    return this.each(function() {
687.        $('input,select,textarea', this).clearFields();
688.    });
689.};
690. 
691./**
692. * Clears the selected form elements.
693. */
694.$.fn.clearFields = $.fn.clearInputs = function() {
695.    return this.each(function() {
696.        var t = this.type, tag = this.tagName.toLowerCase();
697.        if (t == 'text' || t == 'password' || tag == 'textarea') {
698.            this.value = '';
699.        }
700.        else if (t == 'checkbox' || t == 'radio') {
701.            this.checked = false;
702.        }
703.        else if (tag == 'select') {
704.            this.selectedIndex = -1;
705.        }
706.    });
707.};
708. 
709./**
710. * Resets the form data.  Causes all form elements to be reset to their original value.
711. */
712.$.fn.resetForm = function() {
713.    return this.each(function() {
714.        // guard against an input with the name of 'reset'
715.        // note that IE reports the reset function as an 'object'
716.        if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
717.            this.reset();
718.        }
719.    });
720.};
721. 
722./**
723. * Enables or disables any matching elements.
724. */
725.$.fn.enable = function(b) {
726.    if (b === undefined) {
727.        b = true;
728.    }
729.    return this.each(function() {
730.        this.disabled = !b;
731.    });
732.};
733. 
734./**
735. * Checks/unchecks any matching checkboxes or radio buttons and
736. * selects/deselects and matching option elements.
737. */
738.$.fn.selected = function(select) {
739.    if (select === undefined) {
740.        select = true;
741.    }
742.    return this.each(function() {
743.        var t = this.type;
744.        if (t == 'checkbox' || t == 'radio') {
745.            this.checked = select;
746.        }
747.        else if (this.tagName.toLowerCase() == 'option') {
748.            var $sel = $(this).parent('select');
749.            if (select && $sel[0] && $sel[0].type == 'select-one') {
750.                // deselect all other options
751.                $sel.find('option').selected(false);
752.            }
753.            this.selected = select;
754.        }
755.    });
756.};
757. 
758.// helper fn for console logging
759.// set $.fn.ajaxSubmit.debug to true to enable debug logging
760.function log() {
761.    if ($.fn.ajaxSubmit.debug) {
762.        var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
763.        if (window.console && window.console.log) {
764.            window.console.log(msg);
765.        }
766.        else if (window.opera && window.opera.postError) {
767.            window.opera.postError(msg);
768.        }
769.    }
770.};
771. 
772.})(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)
01.ก็ตามกระทู้ข้างบนบอก ควรจะหา เอกสาร หรือ เข้าใจ code ajax ก่อน แต่ผมเขียนมาให้คุณดูและ ลองดูละกัน
02. 
03.<?
04.//include_once '../includes/connect.php';
05.?>
06.<script src="jquery.form.js" type="text/javascript"></script>
07.<script type="text/javascript">
08.     
09.    $(document).ready(function() {
10.        $("#myForm").submit(function () {
11. 
12.            if($("#name").val() == ''){
13.                alert("ชื่อบ่อ ยังเป็นค่าว่าง !!");
14.                return false;              
15.            }
16.        });
17.    });
18.</script>
19.<form id="myForm" name="myForm" method="post" action="poolAdd_script.php"  enctype="multipart/form-data">
20.  <table width="100%" cellpadding="9" cellspacing="0" border="0">
21.    <tr>
22.      <td colspan="2" class="title2">เพิ่มข้อมูลบ่อใหม่</td>
23.    </tr>
24.    <tr>
25.      <td width="20%" class="TD_title">ชื่อบ่อ: </td>
26.      <td align="left" width="80%"><input type="text" name="name" value="" id="name" class="textboxlong" /></td>
27.    </tr>
28.    <tr>
29.      <td width="20%" class="TD_title">สถานะ: </td>
30.      <td align="left" width="80%"><input name="status" type="radio" value="y" checked="checked" />เปิดใช้ &nbsp;&nbsp;<input name="status" type="radio" value="n" />ไม่เปิดใช้</td>
31.    </tr>
32.    <tr>
33.      <td width="20%" class="TD_title">Note: </td>
34.      <td align="left" width="80%"><label>
35.        <textarea name="note" id="note" cols="60" rows="5" class="textarea"></textarea>
36.      </label></td>
37.    </tr>
38.    <tr>
39.      <td>&nbsp;</td>
40.      <td align="left" width="80%"><div id="buttonDiv">
41.        <input type="submit" value="บันทึก" class="button" />
42.        <input type="button" name="button2" value="ย้อนกลับ" onClick="javascript:LoadContentDIV('poolData.php');" class="button" />
43.      </div>
44.        <div id="Loading" style="padding: 10px; text-align: center; display:none;  color: red;"><img src="../images/loader_twt.gif" alt="" /> กำลังบันทึกข้อมูล..</div></td>
45.    </tr>
46.  </table>
47.</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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





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