0

I have a simple doubt over here, in below code I am trying to open different pages to my target frame according to the values selected in select option menu. But the pages are not redirecting to the frame , I know have done some silly error somewhere , can anybody please help me ?

<script type="text/javascript">

function showcity(select){


    if(select.value == 'maha')
    {
        show();
        }
    else
    {
        hide();
    }   

    }

function show(){
    var city=document.getElementById('city');
    city.style.display ='inline';
}

function hide(){
    var cityhide =document.getElementById('city');
    cityhide.style.display ='none';
}



function changemap(select){

    var maps=document.getElementById('city');
    if(maps.select.value == 'mumbai'){
        window.location = 'bank_atm_locator_mumbai.html';
    }
    else if(maps.select.value == 'aura'){
        window.location == 'bank_atm_locator_aurangabad.html'
    }
    else if(maps.select.value == 'pune'){
        window.location == 'bank_atm_locator_pune.html'
    }
}

</script>
</head>
<body>
<div data-role="page" id="pageone" data-theme="b" onload="hide(this)">


<div data-role="main" style="padding-top: 4em">
<div class="ui-field-contain" align="center" data-theme="a">
<form>
<select name="state" onchange="showcity(this)">

        <option value="1" selected="selected">Select State</option>
        <option value="maha">Maharashtra</option>
        <option value="3">Karnataka</option>
        <option value="4">Kerala</option>
        </select></form>
</div>
<div class="ui-field-contain" align="center" data-theme="a">
<form><select name="city" id="city" >

        <option value="1" selected="selected">Select City</option>
        <option value="mumbai" >Mumbai</option>
        <option value="aura">Aurangabad</option>
        <option value="pune">Pune</option>
        </select> </form>
</div>
<a href="#" target="mapview" data-role="button" data-theme="a" onclick="changemap(this)">Go</a> 

</div>
</div>

</body>

2 Answers 2

1

use window.location.href to redirect

function changemap(select){
 event.preventDefault();
var maps=document.getElementById('city');
if(maps.value == 'mumbai'){
    window.location.href = 'bank_atm_locator_mumbai.html';
}
else if(maps.value == 'aura'){
    window.location.href == 'bank_atm_locator_aurangabad.html'
}
else if(maps.value == 'pune'){
    window.location.href == 'bank_atm_locator_pune.html'
}
}
Sign up to request clarification or add additional context in comments.

4 Comments

it would be better to use window.location.assign because location.href is also used in returning url value, just suggesting.. :)
is there any change in the syntax of button to call function?
@Code_Man I have edited the answer. as you are calling change(select) through anchor tag you have to use preventDefault()
@Code_Man I have edited it again. it's a maps.value not maps.select.value
0

start by keeping the var city out of the show and hide scope as so

function showCity(select)
{
    //code
    var city = document.getElementById('city');

    function show()
    {
        city.style.display = 'inline';
    }

    function hide()
    {
        city.style.display = 'none';
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.