SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2005
    Location
    London, UK
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    clear value from form field

    Hello all

    I have a function that shows/hides divs on my page.

    Code:
    function hidediv() {
       var div_num = $("#myformvalue").val();
       if (div_num == 1) {
       $("#mydiv").hide(); 
    	};
    
    
    }
    I would like to add a feature to this code. Basically if a div is hidden then I want the form values within that div to be wiped.

    Ideally it would look something like this:

    Code:
    function hidediv() {
       var div_num = $("#myformvalue").val();
       if (div_num == 1) {
       $("#mydiv").hide();
      AND ThisValue = ""
    	};
    
    
    }
    Is it this simple to do? Thanks.

    Also to the admin, the site is looking slick. Like it a lot.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    jQuery has a selector for all form fields, called ':input', so you can use that to clear all of the form fields that are within the context of the div, with:

    Code javascript:
    $(':input', '#mydiv').each(function () {
        this.value = '';
    });
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2005
    Location
    London, UK
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .

    thanks for that. let me give it a go

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2005
    Location
    London, UK
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that works perfectly thanks a lot paul as always.


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
  •