Reputation: 223
I can't to redirect to page X to page Y according to user choice after selected a radio button. The console write me:
Uncaught ReferenceError: onClickGo is not defined
I declared the pages in my-app.json
routes: [
{
name: 'home',
path: '/home/',
url: './pages/home/home.html'
},
{
name: 'travel',
path: '/travel/',
url: './pages/travel/travel.html',
routes: [
{
name: 'travel-ny',
path: ' ny/',
url: './pages/travel/ny.html',
},
{
name: 'travel-la',
path: ' la/',
url: './pages/travel/la.html',
},
{
name: 'travel-milan',
path: ' milan/',
url: './pages/travel/milan.html',
},
]
}
The users's choice is taken in travel.html
<div data-name="travel" class="page">
<div class="page-content pg-no-padding">
<div class="row">
<div class="col-100 tablet-100 desktop-100">
<form class="list" id="travel-form">
<ul>
<li>
<label class="item-radio item-content">
<input type="radio" name="travel" value="ny" checked="checked"/>
<i class="icon icon-radio"></i>
<div class="item-inner">
<div class="item-title">New York</div>
</div>
</label>
</li>
<li>
<label class="item-radio item-content">
<input type="radio" name="travel" value="la"/>
<i class="icon icon-radio"></i>
<div class="item-inner">
<div class="item-title">Los Angeles</div>
</div>
</label>
</li>
<li>
<label class="item-radio item-content">
<input type="radio" name="travel" value="milan" />
<i class="icon icon-radio"></i>
<div class="item-inner">
<div class="item-title">Milan</div>
</div>
</label>
</li>
</form> <!--list-->
<div class="block">
<a class="button button-fill travelChoice" onclick="onClickGo()">Go</a>
</div>
</div><!--col-100-->
</div><!--row-->
I put the onClickGo function in travel.js that I included its inside home.html in this way
<script type="text/javascript" src="js/travel.js"></script>
The travel.js
const onClickGo = () => {
$$('.travelChoice').on('click', function(){
//retrieve the value selected
var selectedValue = $$('.list input:checked').val();
//go to the page
router.navigate('/travel/'+ selectedValue +'/');
}
Thank you in advance
Upvotes: 3
Views: 900
Reputation: 3560
I think you need to try this since html load before find your function:
$$('.travelChoice').on('click', function(){
//retrieve the value selected
var selectedValue = $$('.list input:checked').val();
//go to the page
router.navigate('/travel/'+ selectedValue +'/');
}
Without wrapping it by onClickGo Variable, and remove on click event from button too
<a class="button button-fill travelChoice">Go</a>
...I think its will be work.....also try to use this to navigate:
self.app.router.navigate('/travel/'+ selectedValue, {reloadCurrent: true});
By adding reloadCurrent you can open page without fair from cashed html page
Upvotes: 1