1337hovie
10-01-2010, 05:04 PM
Very new to jquery, i have a dropdown that changes what DIV's to show. but my problem is that the dropdowns will retain their value as i switch between divs. trying to clear values when the dropdown changes.
change divs onchage:
$(document).ready(function(){
$('#3_form').hide();
$('#4_form').hide();
$('#axd_form').hide();
$('#ht_form').hide();
$("#thechoices").change(function(){
if(this.value == 'all')
{$("#boxes").children().show();}
else
{$("#" + this.value).show().siblings().hide();}
});
$("#thechoices").change();
});
This is what i have so far, i just need to check if the dropdown has been changed:
$.fn.clearForm = function() {
return this.each(function() {
var type = this.type, tag = this.tagName.toLowerCase();
if (tag == 'form')
return $(':input',this).clearForm();
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = '';
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = -1;
});
};
$(document).ready(function(){
function clearFields() {
// if ..check dropdown
$('.form3').clearForm();
// else if dropdown value
$('.form4').clearForm();//clear these fields
}
});
If you select form4, clear the other 2, same for other forms. OR just clear all div's (not entire form!) anything its changed. As long as these div's change, and rest of my form doesnt.
Advice, tutorials, suggestions, code snippets, ANYTHING WILL HELP!
Thanks again,
JT
change divs onchage:
$(document).ready(function(){
$('#3_form').hide();
$('#4_form').hide();
$('#axd_form').hide();
$('#ht_form').hide();
$("#thechoices").change(function(){
if(this.value == 'all')
{$("#boxes").children().show();}
else
{$("#" + this.value).show().siblings().hide();}
});
$("#thechoices").change();
});
This is what i have so far, i just need to check if the dropdown has been changed:
$.fn.clearForm = function() {
return this.each(function() {
var type = this.type, tag = this.tagName.toLowerCase();
if (tag == 'form')
return $(':input',this).clearForm();
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = '';
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = -1;
});
};
$(document).ready(function(){
function clearFields() {
// if ..check dropdown
$('.form3').clearForm();
// else if dropdown value
$('.form4').clearForm();//clear these fields
}
});
If you select form4, clear the other 2, same for other forms. OR just clear all div's (not entire form!) anything its changed. As long as these div's change, and rest of my form doesnt.
Advice, tutorials, suggestions, code snippets, ANYTHING WILL HELP!
Thanks again,
JT