Running a code script on form submission

I am trying to use 3 different thank you pages based on the option selected in the dropdown.

I tried using the code form

But not getting the desired result. It occasionally works.

window.ub.hooks.afterFormSubmit.push(function() {
var valueNew = $( "#which_kind_of_selfdefense_videos_do_you_want_to_watch" ).val()

if(valueNew == "Reality-Based Self Defense"){
   window.history.pushState('', 'New Page Title', ''); 
if(valueNew == "Pressure-Points Based Self-Defense"){
 window.history.pushState('', 'New Page Title', ''); 
if(valueNew == "Chinese/Mystical Self-Defense"){
   window.history.pushState('', 'New Page Title', '');

@Zaid_Nazir there is an easier and simpler way “sil vous plait” ;).
Rather than using the hooks, you can create an intermediate page and redirect your form submission to this page. On the intermediate page, you can capture form data and use redirect scripts based on the response. If you need captured data on the final thank you page - you can add that into your redirect script too. The only downside is you will be using 1 extra page but it’ll be much simpler. Hope this helps.