SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JQuery get target in a preview form.

    Hi.
    Is there a way to get the buttom submitted
    in a form like this:
    PHP Code:
    <form action="" method="post" class="frm-medium" id="frm-new-tickets">
    <
    input type="text" name="subject" title="Subject" value="" maxlength="255" tabindex="1" class="input-medium" id="ticket-subject" />
    <
    input type="submit" name="insert_ticket" title="Preview" value="Preview" tabindex="2" class="buttom buttom-small" id="insert-ticket-preview" />
    <
    input type="submit" name="insert_ticket" title="Insert" value="Insert" tabindex="3" class="buttom buttom-small" id="insert-ticket-submit" /> 
    </
    form
    I tried this but I only get the form tag:
    PHP Code:
    $(document).ready(function () {
        $(
    '#frm-new-tickets').bind("submit", function(e){
                
    alert(e.target.tagName);//FORM
                
    return false
        });
        
    }); 
    I'd like to avoid putting a click event on
    #insert-ticket-preview
    and
    #insert-ticket-submit
    so as not to decouple code (validation).

    Bye.
    Last edited by whisher; Sep 12, 2008 at 13:19.

  2. #2
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By now I managed this

    PHP Code:
    function Tickets(){
        function 
    checkForm(){
            var 
    i18n= new I18n();
            
    i18n.load('items>tickets>new');
            var 
    validator = new Validator();
            
    validator.add(new isEmptyV('#ticket-subject',i18n.get('errorsubject'))); 
            
    validator.add(new isEmptyV('#ticket-content',i18n.get('errorcontent')));
            
    validator.add(new isEmptyV('#ticket-submit',''));
            return 
    validator;
        }
        
    this.formReset= function(){
            if ($(
    '#preview-new-ticket').length 0){
                $(
    '#preview-new-ticket').remove();
            }
            $(
    'form')[0].reset();
        }
        
    this.formPreview= function(){
            var 
    validatorcheckForm();
            if(!
    validator.isValid()){
                
    validator.showError($('#frm-new-tickets ol:eq(0)'));
                return 
    false;
            }
            var 
    ul = $('<ul id="preview-new-ticket"></ul>');
            var 
    subject= $('<li>'+strip_tags(validator.values.subject)+'</li>');
            var 
    content= $('<li>'+strip_tags(validator.values.content)+'</li>');
            
    ul.append(subject);
            
    ul.append(content);
            if ($(
    '#preview-new-ticket').length 0){
                $(
    '#preview-new-ticket').remove();
            }
            $(
    '#frm-new-tickets').before(ul);
            return 
    false;
        }
        
    this.formSubmit= function(){
            var 
    validatorcheckForm();
            if(!
    validator.isValid()){
                
    validator.showError($('#frm-new-tickets ol:eq(0)'));
                return 
    false;
            }
            return 
    true;
        }
    }
    $(
    document).ready(function () {
        var 
    tickets= new Tickets();
        $(
    '#ticket-reset').click(function(e){
            return 
    tickets.formReset(); 
        });
        $(
    '#ticket-preview').click(function(e){
            return 
    tickets.formPreview(); 
        });
        $(
    '#ticket-submit').click(function(){
                return 
    tickets.formSubmit(); 
        });
    }); 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •