I want to create a function for the following:
<select name="journey_type">
<option value="1">One Way</option>
<option value="2">Return</option>
</select>
<div id="return_datetime_div" style="display:none;">
<input id="Enquiry_return_datetime" type="text">
</div>
The return_datetime_div is displayed when the user selects "Return". If the user then selects "One Way" the return_datetime_div gets hidden (this functionality is working):
$("select[name='journey_type']").change(function()
{
if($($(this)).val() == "2")
{
$("#return_datetime_div").slideDown();
}
else
{
$("#return_datetime_div").slideUp();
}
}
});
Now I want to extend this for the following scenario:
- User selects "Return"
- User enters some text in to #Enquiry_return_datetime
- User then selects "One Way"
- A 'confirm' popup should be displayed informing the user of the change of journey type
- If the user accepts then the text in #Enquiry_return_datetime should be erased and the div gets hidden as per normal
- If the user does not accept then the text remains AND the journey_type option should not change and div does not get hidden