I have a select field and function to hide/show divs. Inside those divs are input fields that I want to reset each time a different selection is made.
This script clears fields as long as I specify each field ID.
<script>
$(document).ready(function(){
$("#Main_Connection").change(function(){
$('#InputFieldID').val("");
$(this).find("option:selected").each(function(){
var optionValue = $(this).attr("value");
if(optionValue){
$(".box").not("." + optionValue).hide();
$("." + optionValue).show();
} else{
$(".box").hide();
}
});
}).change();
});
</script>
But I also made this script to get all the field IDs, which I think works because it shows all the IDs in the browser debugger.
<script type="text/javascript">
$(document).ready(function ()
{
var AllFields = $("[id^=Main_] input");
console.log(i, "Hello, world!");
});
</script>
Simply changing $('#InputFieldID').val(""); to $('#AllFields').val(""); does not work. How can I get my first script to reset each field found by the second script?
<input>fields to be cleared, this should clear them:$("[id^=Main_] input").val('').