SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Remove Specific Input From Submitting

    Hi guys,

    I'm trying to figure out a way to stop specific form inputs from submitting. The only way I know how to do this is by removing its name in a javascript onsubmit event. However, in Safari, it still submits the input as a blank variable (i.e. index.php?&=5). I'm trying to find a proper way to do this. Any suggestions?

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    :

    Code JavaScript:
    form.onsubmit = function() {
      return false;
    }
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JimmyP View Post
    :

    Code JavaScript:
    form.onsubmit = function() {
      return false;
    }
    I still want some of the inputs to submit.. just not a certain few.

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean by 'specific form inputs'? Do you mean to submit some of the fields and not others?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rajug View Post
    What do you mean by 'specific form inputs'? Do you mean to submit some of the fields and not others?
    Right.. I want to be able to clean up the URL by not submitting optional inputs that have blank values.. it seems like it's completely feasible to me

  6. #6
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're submitting using the GET method then the following should work:

    Code JavaScript:
    document.getElementById('FORM-ID').onsubmit = function() {
        formElems = this.getElementsByTagName('input');
        var returnValue = '?';
        for(var i = 0; i < formElems.length; i++) {
            if(formElems[i].value.length!==0&&formElems[i].type!=='submit') {
                returnValue += formElems[i].name+'='+formElems[i].value;
                var next = formElems[i+1];
                if(next.value.length!==0&&next.type!=='submit') returnValue += '&';
            }
        }
        window.location = this.action+returnValue;
        return false;
    }

    Although, you will have to modify it so it includes "select" menus and "textareas" ...
    Last edited by JimmyP; Jul 20, 2008 at 14:10.
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)


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
  •