2

Ok dokey, got a bit of jquery up and running, lovely stuff.

  
$(document).ready(function() { 
    $inputs = $("#tbxProdAC, #ddlBuyer, #txtbxHowMany, radTopx");
    $.each($inputs, function() { 
        $(this).focus(function() { 
              $.each($inputs, function() { 
                  $(this).val('');
                  $(this).attr('checked', false); 
              }) 
        }); 
    }) 
}); 

However, in my drop down list, I wish to retain the orignal value rather than clear it altogether.

Is there a way I can specify the individual values i.e. tbxProdAC ='', ddlBuyer = Original Value, txtbxHowMany='', radTopx =unchecked, etc?

4
  • 1
    please, edit your code, it's really messy :/ Commented Nov 27, 2009 at 14:30
  • Sorry about that onodrowan..I was being dense and should have used the html properly! Commented Nov 27, 2009 at 14:44
  • i don't get it too, which of those elements is the select box? all those elements you specified seems to be checkboxes. Commented Nov 27, 2009 at 14:47
  • Hello Paulo. Essentially I have three searches going on in one page. A textbox search (tbxProdAC) a dropdownlist (ddlBuyer) and a textbox/radio button list. What I am trying to achieve is a process whereby if a user selects one of these searches, the content of the others is cleared i.e. essentially removing the need for a general "Reset all" button or equivalent. Commented Nov 27, 2009 at 14:51

5 Answers 5

6

have you tryed:

document.getElementById('formId').reset(); 

try it this way:

$(document).ready(function() { 
    $("#tbxProdAC, #ddlBuyer, #txtbxHowMany, radTopx").focus(function() { 
              document.getElementById('formId').reset(); 
        }); 
}); 
Sign up to request clarification or add additional context in comments.

2 Comments

Hello TeKapa I tried your method above but on the "document.getElementById('formId').reset();" line I get an error - "is null or or not an object." Thanks for looking into this for me.
Sorry - I was being a tool and still left that line in i.e. document.getElementById('formId').reset(); That has worked a dream...thank you very very much.
5

You'll have to go through each one separately to do that.

i.e.

$('#tbxProcAC').val('');
$('#ddlBuyer').val($('#ddlBuyer')[0].defaultValue);
$('#txtbxHowMany').val('');
$('#radTopx').attr('checked',false);

Perhaps the second line there may be of most intrest to you - it shows how to access the original 'default' value.

Comment if you've any questions, good luck!

3 Comments

Thanks Gausie - I am assuming just remove the original $(this).val(''); line and replace with your suggestion? As you can probably tell, newbie here willing to learn but only being two weeks into knowing anything about creating a web app, I'm struggling with the amount to learn!
All you need is what I've given you! (with $(document).ready(function() { and } wrapped around of course). Read about selectors on the jQuery site for more info (docs.jquery.com/Selectors). Also, could you mark mine as answered, if it helped you with the problem? I like rep :-)
$('#ddlBuyer')[0].defaultValue gives me undefined so $('#ddlBuyer').val(undefined); is the simplest way to reset dropdown ;)
0

You can use the data function in JQuery - you can store all the existing values and call them again when you need them

Comments

0

in JQuery can select First Option <option value="0" > </option> first option value is zero and text is empty. now

$('#DropDown').find('option:first').attr('selected', 'selected');

$('#DropDown')[0].selectedIndex = 0;

$('#DropDown') -> select dropdown

find('option:first') -> find first option

attr('selected', 'selected') -> set attribute selected.

Comments

0

Try this simple way

 document.getElementById(‘drpFruits’).options.length=0;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.