Is setValidation in fact defined? What do you get if you enter setValidation
(just the name) into the Firebug console or do a Watch on it? Does it show
it being a function?

Suggest you find a way to post a test page, otherwise we could be playing 20
questions for a while... :-)

On Tue, Nov 24, 2009 at 7:47 PM, Dave Maharaj :: WidePixels.com <
d...@widepixels.com> wrote:

> Sorry its only local right now so I will try to add as much as I can here.
>
> Page with a form has:
>        <link rel="stylesheet" type="text/css" href="/css/styles.css" />
>        <link rel="stylesheet" type="text/css" href="/css/typography.css" />
>        <script type="text/javascript" src="/js/jquery.js"></script>
>        <script type="text/javascript" src="/js/jquery.form.js"></script>
>        <script type="text/javascript"
> src="/js/jquery.validate.js"></script>
>        <script type="text/javascript" src="/js/site.js"></script>
>
> Normal html code with my #newAward form, then at the bottom of the page
>
> <script type="text/javascript">
>        $(document).ready( function() {
>           setValidation('#newAward', validate_awards);
>        });
> </script>
>
> site.js has just the one function you provided
>
> function setValidation( selector, validator ) {
>
>    $(document).ready( function() {
>        var $form = $(selector);
>
>        $form.submit( function() {
>
>            $form.validate( validator );
>            var valid = $(this).valid();
>            if( valid ) {
>                var form_url = $form.attr('action');
>                var page_target = form_url.substr(1).replace(new RegExp("/",
> "g"), "_");
>                var queryString = $form.formSerialize();
>                $form.ajaxSubmit({
>                    type: 'post',
>                    url: form_url + '/',
>                    data: queryString,
>                    resetForm: true,
>                    success: function( response ) {
>                        alert( response );
>                        $( '#' + page_target ).slideToggle('slow',
> function() {
>
> $(response).hide().prependTo('#sortable').slideDown('slow');
>                        });
>                    }
>                });
>            }
>            return false;
>
>        });
>    });
>
> }
>
> I checked with firebug that all the scripts do infact load.
>
> Thanks again,
>
> Dave
>
> -----Original Message-----
> From: Michael Geary [mailto:m...@mg.to]
> Sent: November-24-09 11:44 PM
> To: jquery-en@googlegroups.com
> Subject: Re: [jQuery] Create a function?
>
> Do you have a <script> tag to load your external .js file?
>
> Post a link to a test page and I can tell you for sure what's wrong.
>
> -Mike
>
>
> On Tue, Nov 24, 2009 at 6:33 PM, Dave Maharaj :: WidePixels.com
> <d...@widepixels.com> wrote:
>
>
>        Sorry. I cant seem to get it to go.
>
>        Maybe I did not clearly explain the problem.
>
>        I want to put the function like you have below in my external js,
> then on my
>        html pages that have a form just set it up so all I have to do is
> include
>        the setValidation( '#newAward', validate_awards ); on those pages so
> 1
>        function gets called for every form.
>
>        I put your  function setValidation( selector, validator ) {
>        ....
>        }
>        In my external js
>
>
>        On the page with a form I put
>
>        <script type="text/javascript">
>        $(document).ready( function() {
>           setValidation( '#newAward', validate_awards );
>        });
>        </script>
>
>        But when I load the page I get:
>        setValidation is not defined
>
>        Ideas where I screwed up?
>
>        Thanks again.
>
>
>        Dave
>
>        -----Original Message-----
>        From: Michael Geary [mailto:m...@mg.to]
>        Sent: November-24-09 10:02 PM
>        To: jquery-en@googlegroups.com
>        Subject: Re: [jQuery] Create a function?
>
>
>        Your code could end up looking something like this:
>
>        function setValidation( selector, validator ) {
>
>           $(document).ready( function() {
>               var $form = $(selector);
>
>               $form.submit( function() {
>
>                   $form.validate( validator );
>                   var valid = $(this).valid();
>                   if( valid ) {
>                       var form_url = $form.attr('action');
>                       var page_target = form_url.substr(1).replace(new
> RegExp("/",
>        "g"), "_");
>                       var queryString = $form.formSerialize();
>                       $form.ajaxSubmit({
>                           type: 'post',
>                           url: form_url + '/',
>                           data: queryString,
>                           resetForm: true,
>                           success: function( response ) {
>                               alert( response );
>                               $( '#' + page_target ).slideToggle('slow',
>        function() {
>
>        $(response).hide().prependTo('#sortable').slideDown('slow');
>                               });
>                           }
>                       });
>                   }
>                   return false;
>
>               });
>           });
>
>        }
>
>        And for the case you listed, you would call it like this:
>
>        setValidation( '#newAward', validate_awards );
>
>        I threw a $(document).ready() block into that code. You don't need
> that if
>        your call to the setValidation() function is already inside a
> document ready
>        callback, but it doesn't do any harm either.
>
>        -Mike
>
>
>        On Tue, Nov 24, 2009 at 3:48 PM, Dave Maharaj :: WidePixels.com
>        <d...@widepixels.com> wrote:
>
>
>               I have the exact same code on every page where a form gets
>        submitted. How
>               can i turn that into a simple function?
>
>               The only thing that changes is the
> $(this).validate(validate_awards)
>        and the
>               form ID;
>
>               It would be so much easier if the function was in one place
> and
>        called where
>               needed but I cant figure this out.
>
>               Something like:
>
>
>               $('#newAward').submit(function({
>                      myFormFunction(validate_awards, '#newAward');
>               });
>
>
>               where I could put in the formID and the validation rules to
> use
>
>
>               CURRENTLY HAVE THIS ON EVERY PAGE: Only the "validate_awards"
> and
>               "#newAward" changes
>
>               $('#newAward').submit(function() {
>
>
>                 $(this).validate(validate_awards);
>                 var valid = $(this).valid();
>                 if (valid) {
>
>                 var form_url =  $(this).attr('action');
>                 var page_target = form_url.substr(1).replace( new RegExp(
> "/"
>        ,"g"), "_"
>               );
>                 var queryString = $('#newAward').formSerialize();
>                  $(this).ajaxSubmit({
>                   type:    'post',
>                   url:      form_url+'/',
>                   data:      queryString,
>                   resetForm:   true,
>                   success:    function(response){
>                          alert(response);
>                           $('#'+page_target).slideToggle('slow', function
> (){
>
>        $(response).hide().prependTo('#sortable').slideDown('slow');
>
>                           });
>                           }
>
>
>                  });
>                 }
>                 return false;
>
>                });
>
>               Any help would be greatly appreciated.
>               Thanks,
>
>               Dave
>
>
>
>
>
>        No virus found in this incoming message.
>        Checked by AVG - www.avg.com
>        Version: 9.0.709 / Virus Database: 270.14.76/2519 - Release Date:
> 11/24/09
>        04:16:00
>
>
>
>
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.709 / Virus Database: 270.14.76/2519 - Release Date: 11/24/09
> 04:16:00
>
>
>
>

Reply via email to