Redirect to pre-defined URL as soon as dropbox is selected

Nuvelle 17 Jan, 2013
I have a dropdown box with 4 options (Plus 1 default option)

I would like to force a redirect as soon as a specific dropdown option is chosen, but alow the other 3 to continue on with the form as normal.

Is this do-able?
GreyHead 22 Jan, 2013
Hi nuvelle,

Yes I think that you can do this with JavaScript. Listen to the onChange event for the drop-down and redirect if that value of the drop-down is selected. The code will be something like this:
window.addEvent('domready', function() {
  $('drop_down_id').addEvent('change', function() {
    if ( $('drop_down_id').value == 'redirect' ) {
      window.location = 'http://some_domain.com';
    }
  });
});

Bob
marklaudens 27 Feb, 2013
Please forgive my newbieness.
My scenario is to trigger a redirect to a URL http://www.yahoo.com
upon a drop down value of 'Irvine' being selected.
The drop down menu field id is called 'input_select_2'

I created a new action called on Change and pasted your code below in it.
I assume this is the appropriate step. If not please advise.
Because I am new to code and syntax, what exactly should my code look like in the on Change action?
Thank You

your example:
window.addEvent('domready', function() {
  $('drop_down_id').addEvent('change', function() {
    if ( $('drop_down_id').value == 'redirect' ) {
      window.location = 'http://some_domain.com';
    }
  });
});
GreyHead 27 Feb, 2013
Hi marklaudens,

You don't need a new event; just drag a Load JS action into the On Load event of your form.

The code I posted should work but you need to update the specific details for your form:
window.addEvent('domready', function() {
  $('input_select_2').addEvent('change', function() {
    if ( $('input_select_2').value == 'Irvine' ) {
      window.location = 'http://www.yahoo.com';
    }
  });
});

Bob

PS Why would you redirect to Yahoo?? just curious.
marklaudens 02 Mar, 2013
GreyHead, A big thank You!!
I just used Yahoo as an example. Ultimately I want to redirect to any URL I choose, but needed to understand the syntax mechanics.
Cheers
marklaudens
This topic is locked and no more replies can be posted.