I have been working on a website and run into a problem. In my FAQ, I have a drop-down menu and a submit button to link to different parts of the FAQ. This works perfectly. The submit button triggers a javascript function which dynamically links to the appropriate anchor on the page. In addition, I want the question chosen by the drop down menu to be highlighted orange. I got the highlight to show up, but only for a split second before it flashes away. I am wondering how to make the highlight stay, instead of flash away? I am not certain why this is happening. In addition, how could I make the highlight fade in using jQuery? I know how to do it through hiding the div then using .fade(), but that results in all of the text disappearing. Thanks so much!
heres a fiddle: http://jsfiddle.net/UjPtv/ but it doesn’t work fully because when you submit it comes up with an error. I think this is because jsfiddle doesn’t allow submit’s, even though this submit is simply running some javascript. If you know a way around please let me know so I can update the link! Thanks!
javascript:
var toggled = 0;
function jump_to (location) {
if(toggled == 0){
toggled = 1;
window.location.href = "#" + location;
$("#wrap"+location).toggleClass("wraps_active");
}
}
html:
<div id = "main">
<h2 class = "center">FACTS YOU NEED</h2>
<h3>The Core Facts You Want To Know</h3>
<div class = "border">
<p>
Jump To:
<form onsubmit = "jump_to(jump_list.value)">
<select name = "jump_list">
<option value="1">Who can go to the camp?</option>
<option value="2"><a href = "contact_information.html">When do we check in and out?</a></option>
</select>
<input type = "submit" value = "Go"/>
</form>
</p>
</div>
<div id = "wrap1" class = "wraps">
<h4><a name = "1"></a>Who can go to the camp? </h4>
<p>
The camp is for kids ages 9 to 17 years old who have been diagnosed with celiac disease, a condition that requires life-long adherence to a gluten-free diet. Given limited space, we are unable to accommodate kids on gluten-free diets for other reasons (such as autism spectrum disorders). Campers ages 16-17 years may choose to volunteer as junior counselors. Junior counselors assist the adult volunteers, and for first session junior counselors need to arrive a day early (on Monday) for the staff orientation and training. If there are more junior counselor applicants than there is available space, priority is given based on age, gender-need, and prior camp experience.
</p>
</div>
<div id = "wrap2" class = "wraps">
<h4><a name = "2"></a>When do we check in and out?</h4>
<p>
Check-in: Please see the "Calendar" on the left hand side of the website for details about each camp.Please do not arrive early.
</br><br/>
Check-out: All campers must be checked out by the stated time so camp can be prepared for the next group, see the "Calendar" for date information.
</p>
</div>
</div>
css:
.wraps{
border-bottom:1px dashed #C3C3C3;
}
.wraps_active{
border-bottom:1px dashed #C3C3C3;
background:#FFB280;
}
Everytime the form is submitted, clean all of the active wrap classes and add it only for the selected one.
Here is Fiddle.