If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

using If else if else statement getting error

I am newbie to javascript I trying to code conditions for currency change based on shipping country but getting error for all conditions.

Conditions

if the country is India and currency is Indian Rupees - Proceed to next page
if the country is India and currency is not India Rupees - alert as "Change currency as Indian Rupees"
if the country is not India and currency is India Rupees - alert as "Change currency as other than Indian Rupees"
if the country is not India and currency is not Indian Rupees - Proceed to next page

there exist other (more flexible) ways of that check. if you have several countries and several currencies you can, for example, create the array which every member will look like:

['country',['currency_1','currency_2',etc.'currency_n']]

and then you'll run two loops. the first loop finds 'country' looking over the first members of each member. if it doesn't match the loop skips the member (continue), but if it matches the first member the second loop which looks over the second member (the array of acceptable currencies) starts. if the second loop finds the given currency it breaks and submits the form.

anyway, you must understand that the better check is done at the server-side

Just a small point. The above code works, but the test for "country != 'India'" is redundant. This is because, if the country IS 'India', one or other of the previous two tests MUST be true. So it can be simplified to:

else if(currency == 'INR'){alert("Change the currency as other than Indian Rupee ");}

Also, I'd echo the view that this test should be done server-side, as it is too easy for client-side validation to be bypassed. So you will NEED to validate server-side anyway. Validating both client and server-side is not a good idea because, if/when the criteria change, its very easy to forget that you need to amend two places! So you can get obscure errors because the client and server side validations differ.