Page 1 of 1

Form drop down hidden field issue

Posted: Fri Jan 02, 2009 11:51 pm
by ethangj
I have a form that uses a dropdown list to select a member type, and from there it displays the div with the necessary fields for that member type using this script

<script>
var activeID = false;
function showHide(objID){
if(activeID){
document.getElementById(activeID).style.display='none';
}
document.getElementById(objID).style.display='inline';
activeID = objID;

}


and then on my dropdown


<select name="MEMTYPE" onchange="showHide(this.options[this.selectedIndex].value)" >


after submit it uses a switch to run validation

my issue is if validation fails and it kicks up an error and reloads the page, the dropdown list is defaulted back and thus the fields are all missing, so i have the error displayed (ie please enter a valid phone number) but to get the fields back they have to select the option from the dropdown again

ive tried two methods to fix this, echoing selected on the membership option in the dropdown if the membership type == that particular value, and while that DOES default the list to the correct option, it does not run the script as the script runs on change

i also tried to have a seperate IF that ran the script independently of the dropdown if the membership type == that value, but it did not work, im assuming due to the coding of the script (i know almost no JS)

any ideas?

Re: Form drop down hidden field issue

Posted: Sat Jan 03, 2009 7:48 am
by sergio-pro
Hi

After submit you know on the server the ID of the selected DIV.
So, after all DIVs, output to browser: <script type="text/javascript">showHide(SELECTED_DIV_ID)</script>

Also would be nice to show selected option in select control after page reload.