Issue
How do I get the option to return to the targeted value ID after loading the page and the alert “cancel”? But also to the former current value after a value is chosen?
Right now it selects the "current value" if I chose a value before I chose to "cancel" the alert.
But if I load a fresh page it will not go to the selected "current value" or to a targeted value ID either. It will go to a "disabled" option of no use. How do I fix this?
How do I make it to go to a targeted value ID (id="ger") option of my choice if I chose to "cancel" the alert directly after loading the page?
JavaScript
<script type="text/javascript">
$(function(){
$('#optFu').change(function() {
var selected = $(this).val();
if (selected == 'auto') {
if (!confirm('The ´´Automatic system´´ is limited. \n Are you sure you want to use this?')) {
$(this).val($.data(this, 'current'));
return false;
}
}
$.data(this, 'current', $(this).val());
});
});
</script>
HTML
<select name="LangFu" id="optFu">
<option value="" disabled>Common Languages:</option>
<option value="zh-CN">Chinese (Simplified)</option>
<option selected value="en">English</option>
<option value="fr">French</option>
<option value="de" id="ger">German</option>
<option value="ru">Russian</option>
<option value="es">Spanish</option>
<option value="" disabled>—</option>
<option value="auto" data-confirm=" The ´´Automatic Language Detection´´ does not detect laguadges in frames / sandbox. Are you sure you want to select this option? ">Auto Detect</option>
</select>
Solution
try this
$(function() {
$('#optFu').val("de");
$('#optFu').change(function() {
var selected = $(this).val();
if (selected == 'auto') {
if (!confirm('The ´´Automatic system´´ is limited. \n Are you sure you want to use this?')) {
$(this).val("de");
return false;
}
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<select name="LangFu" id="optFu">
<option value="" disabled>Common Languages:</option>
<option value="zh-CN">Chinese (Simplified)</option>
<option selected value="en">English</option>
<option value="fr">French</option>
<option value="de">German</option>
<option value="ru">Russian</option>
<option value="es">Spanish</option>
<option value="" disabled>—</option>
<option value="auto" data-confirm=" The ´´Automatic Language Detection´´ does not detect laguadges in frames / sandbox. Are you sure you want to select this option? ">Auto Detect</option>
</select>
Answered By - ewwink
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.