redirect page select tag onchange

Published 1 week ago by kapitan

I have this route:

Route::get('/register/business/{id}/edit', 'RegistrationsControl[email protected]')->name('register.edit.get');

on the home page, i have this select tag:

Form One Form Two Form Three

I need to redirect the page to my route name register.edit.get on the onchange event of my select tag.

please help!!!

Best Answer (As Selected By kapitan)
RamjithAp

Try this

<select id="dynamic_select">
  <option value="" selected>Select</option>
  <option value="1">Form one</option>
  <option value="2">Form two</option>
  <option value="3">Form three</option>
</select>

<script>
    $(function(){
      $('#dynamic_select').on('change', function () {
          var id = $(this).val(); // get selected value
          if (id) { 
              window.location = "/register/business/"+id+"/edit"; 
          }
          return false;
      });
    });
</script>
RamjithAp

Try this

<select id="dynamic_select">
  <option value="" selected>Select</option>
  <option value="1">Form one</option>
  <option value="2">Form two</option>
  <option value="3">Form three</option>
</select>

<script>
    $(function(){
      $('#dynamic_select').on('change', function () {
          var id = $(this).val(); // get selected value
          if (id) { 
              window.location = "/register/business/"+id+"/edit"; 
          }
          return false;
      });
    });
</script>
RamjithAp

Just replace this

window.location = "{{ url('/') }}register/business/"+id+"/edit"; 
kapitan

your first answer worked! im sure, im doing this earlier. thank you so much. apologies for bothering you with a basic stuff. take care! (please delete your second answer)

rumm.an
rumm.an
1 week ago (21,850 XP)

Try this one,


window.location.replace("{{ route('register.edit.get', id) }}");
kapitan

i knew now what i have missed, the "/" at the beginning. lesson learned.

Please sign in or create an account to participate in this conversation.