jquery page URL load on select strange behavior
I have a select box on a page that, when you choose a value it will automatically go to that page using the id parameter set in the URL string. The form works well, until I try to add to it the code that brings in and matches the URL parameter to automatically be selected. Now, when you choose a new value, it redirects to --selected-- instead of the page URL with the new value.
If I manually load the page, i.e. vbijjaar.php?id=2017, the page loads just fine, the select menu displays 2017. But now, when I choose, 2018 or 2016 or other in the menu, as I've indicated above, it just goes to --select-- instead of vbijjaar.php?id=xxx
I'm not seeing any errors, either.
<form >
<select class="js-example-basic-single js-states form-control" name="jaar" id="urlSelect" onchange="window.location = jQuery('#urlSelect option:selected').val();">
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$conn = new mysqli('localhost', 'xxx', 'xxxx', 'xxx');
$result = mysqli_query($conn, "SELECT YEAR(vertrekdatum2) AS year FROM tbl_vluchtgegevens GROUP BY YEAR(vertrekdatum2) ORDER BY YEAR(vertrekdatum2) DESC ");
while($row2 = mysqli_fetch_array($result))
{
$id = mysqli_real_escape_string($conn, $_GET['id']);
$j = $row2['year'];
?>
<option value="vbijjaar.php?id=<?php echo $j ?>" <?php echo ($j == $id) ? 'selected' : '' ?>> <?php echo $j; ?> </option>
<?php
}mysqli_close($conn);
?>
</select>
<script>
$(function(){
// bind change event to select
$('#urlSelect').bind('change', function () {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
<br />
</form>
Generated HTML code:
<form class="px-4 py-3">
<div class="form-group">
<label for="statsbyyear">Stats by Year</label>
<select class="js-example-basic-single js-states form-control form-control-sm" width="100px" name="jaar" id="urlSelect" onchange="window.location = jQuery('#urlSelect option:selected').val();">
<option>--Select--</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2019'>2019</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2018'>2018</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2017'>2017</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2016'>2016</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2015'>2015</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2014'>2014</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2013'>2013</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2012'>2012</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2011'>2011</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2010'>2010</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2009'>2009</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2008'>2008</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2007'>2007</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2006'>2006</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2005'>2005</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2004'>2004</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2003'>2003</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2002'>2002</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2001'>2001</option> </select>
<script>
$(function(){
// bind change event to select
$('#dynamic_select').bind('change', function () {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
</div>
</form>
php jquery select
add a comment |
I have a select box on a page that, when you choose a value it will automatically go to that page using the id parameter set in the URL string. The form works well, until I try to add to it the code that brings in and matches the URL parameter to automatically be selected. Now, when you choose a new value, it redirects to --selected-- instead of the page URL with the new value.
If I manually load the page, i.e. vbijjaar.php?id=2017, the page loads just fine, the select menu displays 2017. But now, when I choose, 2018 or 2016 or other in the menu, as I've indicated above, it just goes to --select-- instead of vbijjaar.php?id=xxx
I'm not seeing any errors, either.
<form >
<select class="js-example-basic-single js-states form-control" name="jaar" id="urlSelect" onchange="window.location = jQuery('#urlSelect option:selected').val();">
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$conn = new mysqli('localhost', 'xxx', 'xxxx', 'xxx');
$result = mysqli_query($conn, "SELECT YEAR(vertrekdatum2) AS year FROM tbl_vluchtgegevens GROUP BY YEAR(vertrekdatum2) ORDER BY YEAR(vertrekdatum2) DESC ");
while($row2 = mysqli_fetch_array($result))
{
$id = mysqli_real_escape_string($conn, $_GET['id']);
$j = $row2['year'];
?>
<option value="vbijjaar.php?id=<?php echo $j ?>" <?php echo ($j == $id) ? 'selected' : '' ?>> <?php echo $j; ?> </option>
<?php
}mysqli_close($conn);
?>
</select>
<script>
$(function(){
// bind change event to select
$('#urlSelect').bind('change', function () {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
<br />
</form>
Generated HTML code:
<form class="px-4 py-3">
<div class="form-group">
<label for="statsbyyear">Stats by Year</label>
<select class="js-example-basic-single js-states form-control form-control-sm" width="100px" name="jaar" id="urlSelect" onchange="window.location = jQuery('#urlSelect option:selected').val();">
<option>--Select--</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2019'>2019</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2018'>2018</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2017'>2017</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2016'>2016</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2015'>2015</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2014'>2014</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2013'>2013</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2012'>2012</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2011'>2011</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2010'>2010</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2009'>2009</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2008'>2008</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2007'>2007</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2006'>2006</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2005'>2005</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2004'>2004</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2003'>2003</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2002'>2002</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2001'>2001</option> </select>
<script>
$(function(){
// bind change event to select
$('#dynamic_select').bind('change', function () {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
</div>
</form>
php jquery select
1
Can you delete thisonchange="window.location = jQuery('#urlSelect option:selected').val();"
and addconsole.log(url)
to your bind function and check value in console panel also removereturn false;
it is not needed also check your '$id' it will be always the same from$_GET
after first selection you should change it to$j
like jeroen wrote
– Oleksandr Pobuta
Nov 26 '18 at 13:18
add a comment |
I have a select box on a page that, when you choose a value it will automatically go to that page using the id parameter set in the URL string. The form works well, until I try to add to it the code that brings in and matches the URL parameter to automatically be selected. Now, when you choose a new value, it redirects to --selected-- instead of the page URL with the new value.
If I manually load the page, i.e. vbijjaar.php?id=2017, the page loads just fine, the select menu displays 2017. But now, when I choose, 2018 or 2016 or other in the menu, as I've indicated above, it just goes to --select-- instead of vbijjaar.php?id=xxx
I'm not seeing any errors, either.
<form >
<select class="js-example-basic-single js-states form-control" name="jaar" id="urlSelect" onchange="window.location = jQuery('#urlSelect option:selected').val();">
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$conn = new mysqli('localhost', 'xxx', 'xxxx', 'xxx');
$result = mysqli_query($conn, "SELECT YEAR(vertrekdatum2) AS year FROM tbl_vluchtgegevens GROUP BY YEAR(vertrekdatum2) ORDER BY YEAR(vertrekdatum2) DESC ");
while($row2 = mysqli_fetch_array($result))
{
$id = mysqli_real_escape_string($conn, $_GET['id']);
$j = $row2['year'];
?>
<option value="vbijjaar.php?id=<?php echo $j ?>" <?php echo ($j == $id) ? 'selected' : '' ?>> <?php echo $j; ?> </option>
<?php
}mysqli_close($conn);
?>
</select>
<script>
$(function(){
// bind change event to select
$('#urlSelect').bind('change', function () {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
<br />
</form>
Generated HTML code:
<form class="px-4 py-3">
<div class="form-group">
<label for="statsbyyear">Stats by Year</label>
<select class="js-example-basic-single js-states form-control form-control-sm" width="100px" name="jaar" id="urlSelect" onchange="window.location = jQuery('#urlSelect option:selected').val();">
<option>--Select--</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2019'>2019</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2018'>2018</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2017'>2017</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2016'>2016</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2015'>2015</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2014'>2014</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2013'>2013</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2012'>2012</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2011'>2011</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2010'>2010</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2009'>2009</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2008'>2008</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2007'>2007</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2006'>2006</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2005'>2005</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2004'>2004</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2003'>2003</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2002'>2002</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2001'>2001</option> </select>
<script>
$(function(){
// bind change event to select
$('#dynamic_select').bind('change', function () {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
</div>
</form>
php jquery select
I have a select box on a page that, when you choose a value it will automatically go to that page using the id parameter set in the URL string. The form works well, until I try to add to it the code that brings in and matches the URL parameter to automatically be selected. Now, when you choose a new value, it redirects to --selected-- instead of the page URL with the new value.
If I manually load the page, i.e. vbijjaar.php?id=2017, the page loads just fine, the select menu displays 2017. But now, when I choose, 2018 or 2016 or other in the menu, as I've indicated above, it just goes to --select-- instead of vbijjaar.php?id=xxx
I'm not seeing any errors, either.
<form >
<select class="js-example-basic-single js-states form-control" name="jaar" id="urlSelect" onchange="window.location = jQuery('#urlSelect option:selected').val();">
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$conn = new mysqli('localhost', 'xxx', 'xxxx', 'xxx');
$result = mysqli_query($conn, "SELECT YEAR(vertrekdatum2) AS year FROM tbl_vluchtgegevens GROUP BY YEAR(vertrekdatum2) ORDER BY YEAR(vertrekdatum2) DESC ");
while($row2 = mysqli_fetch_array($result))
{
$id = mysqli_real_escape_string($conn, $_GET['id']);
$j = $row2['year'];
?>
<option value="vbijjaar.php?id=<?php echo $j ?>" <?php echo ($j == $id) ? 'selected' : '' ?>> <?php echo $j; ?> </option>
<?php
}mysqli_close($conn);
?>
</select>
<script>
$(function(){
// bind change event to select
$('#urlSelect').bind('change', function () {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
<br />
</form>
Generated HTML code:
<form class="px-4 py-3">
<div class="form-group">
<label for="statsbyyear">Stats by Year</label>
<select class="js-example-basic-single js-states form-control form-control-sm" width="100px" name="jaar" id="urlSelect" onchange="window.location = jQuery('#urlSelect option:selected').val();">
<option>--Select--</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2019'>2019</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2018'>2018</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2017'>2017</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2016'>2016</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2015'>2015</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2014'>2014</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2013'>2013</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2012'>2012</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2011'>2011</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2010'>2010</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2009'>2009</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2008'>2008</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2007'>2007</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2006'>2006</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2005'>2005</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2004'>2004</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2003'>2003</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2002'>2002</option>
<option value='http://globe-trekking.com/vg/en/vluchtinfo/jaar/vbijjaar.php?id=2001'>2001</option> </select>
<script>
$(function(){
// bind change event to select
$('#dynamic_select').bind('change', function () {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
</div>
</form>
php jquery select
php jquery select
edited Nov 26 '18 at 17:01
Shahnewaz
394312
394312
asked Nov 26 '18 at 13:01
Daniël CronkDaniël Cronk
255
255
1
Can you delete thisonchange="window.location = jQuery('#urlSelect option:selected').val();"
and addconsole.log(url)
to your bind function and check value in console panel also removereturn false;
it is not needed also check your '$id' it will be always the same from$_GET
after first selection you should change it to$j
like jeroen wrote
– Oleksandr Pobuta
Nov 26 '18 at 13:18
add a comment |
1
Can you delete thisonchange="window.location = jQuery('#urlSelect option:selected').val();"
and addconsole.log(url)
to your bind function and check value in console panel also removereturn false;
it is not needed also check your '$id' it will be always the same from$_GET
after first selection you should change it to$j
like jeroen wrote
– Oleksandr Pobuta
Nov 26 '18 at 13:18
1
1
Can you delete this
onchange="window.location = jQuery('#urlSelect option:selected').val();"
and add console.log(url)
to your bind function and check value in console panel also remove return false;
it is not needed also check your '$id' it will be always the same from $_GET
after first selection you should change it to $j
like jeroen wrote– Oleksandr Pobuta
Nov 26 '18 at 13:18
Can you delete this
onchange="window.location = jQuery('#urlSelect option:selected').val();"
and add console.log(url)
to your bind function and check value in console panel also remove return false;
it is not needed also check your '$id' it will be always the same from $_GET
after first selection you should change it to $j
like jeroen wrote– Oleksandr Pobuta
Nov 26 '18 at 13:18
add a comment |
1 Answer
1
active
oldest
votes
In your loop you have a logical error:
<?php echo $id ?>
should be:
<?php echo $j; ?>
$j
is the year and $id
is fixed and the previous value in the url, so once it is wrong, it will not change.
Edit: Additionally, you need the value of the selected option, not the value of the select box.
So this:
var url = $(this).val();
Should be something like:
var url = $(this).find(':selected').val();
It would, still be the same value. This change does not affect the behavior of the script and it still redirects me to /--Select--
– Daniël Cronk
Nov 26 '18 at 13:12
@DaniëlCronk What does the generated html look like? After this change of course.
– jeroen
Nov 26 '18 at 13:13
I get the following page: Not Found The requested URL /vg/en/vluchtinfo/jaar/--Select-- was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Daniël Cronk
Nov 26 '18 at 13:16
sorry. i think the cold has gotten to my brain. I've added the generated html code to my original post.
– Daniël Cronk
Nov 26 '18 at 13:25
@DaniëlCronk No problem, I have added a change in the javascript as well.
– jeroen
Nov 26 '18 at 13:35
|
show 4 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53481707%2fjquery-page-url-load-on-select-strange-behavior%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your loop you have a logical error:
<?php echo $id ?>
should be:
<?php echo $j; ?>
$j
is the year and $id
is fixed and the previous value in the url, so once it is wrong, it will not change.
Edit: Additionally, you need the value of the selected option, not the value of the select box.
So this:
var url = $(this).val();
Should be something like:
var url = $(this).find(':selected').val();
It would, still be the same value. This change does not affect the behavior of the script and it still redirects me to /--Select--
– Daniël Cronk
Nov 26 '18 at 13:12
@DaniëlCronk What does the generated html look like? After this change of course.
– jeroen
Nov 26 '18 at 13:13
I get the following page: Not Found The requested URL /vg/en/vluchtinfo/jaar/--Select-- was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Daniël Cronk
Nov 26 '18 at 13:16
sorry. i think the cold has gotten to my brain. I've added the generated html code to my original post.
– Daniël Cronk
Nov 26 '18 at 13:25
@DaniëlCronk No problem, I have added a change in the javascript as well.
– jeroen
Nov 26 '18 at 13:35
|
show 4 more comments
In your loop you have a logical error:
<?php echo $id ?>
should be:
<?php echo $j; ?>
$j
is the year and $id
is fixed and the previous value in the url, so once it is wrong, it will not change.
Edit: Additionally, you need the value of the selected option, not the value of the select box.
So this:
var url = $(this).val();
Should be something like:
var url = $(this).find(':selected').val();
It would, still be the same value. This change does not affect the behavior of the script and it still redirects me to /--Select--
– Daniël Cronk
Nov 26 '18 at 13:12
@DaniëlCronk What does the generated html look like? After this change of course.
– jeroen
Nov 26 '18 at 13:13
I get the following page: Not Found The requested URL /vg/en/vluchtinfo/jaar/--Select-- was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Daniël Cronk
Nov 26 '18 at 13:16
sorry. i think the cold has gotten to my brain. I've added the generated html code to my original post.
– Daniël Cronk
Nov 26 '18 at 13:25
@DaniëlCronk No problem, I have added a change in the javascript as well.
– jeroen
Nov 26 '18 at 13:35
|
show 4 more comments
In your loop you have a logical error:
<?php echo $id ?>
should be:
<?php echo $j; ?>
$j
is the year and $id
is fixed and the previous value in the url, so once it is wrong, it will not change.
Edit: Additionally, you need the value of the selected option, not the value of the select box.
So this:
var url = $(this).val();
Should be something like:
var url = $(this).find(':selected').val();
In your loop you have a logical error:
<?php echo $id ?>
should be:
<?php echo $j; ?>
$j
is the year and $id
is fixed and the previous value in the url, so once it is wrong, it will not change.
Edit: Additionally, you need the value of the selected option, not the value of the select box.
So this:
var url = $(this).val();
Should be something like:
var url = $(this).find(':selected').val();
edited Nov 26 '18 at 13:34
answered Nov 26 '18 at 13:08
jeroenjeroen
82.9k18100124
82.9k18100124
It would, still be the same value. This change does not affect the behavior of the script and it still redirects me to /--Select--
– Daniël Cronk
Nov 26 '18 at 13:12
@DaniëlCronk What does the generated html look like? After this change of course.
– jeroen
Nov 26 '18 at 13:13
I get the following page: Not Found The requested URL /vg/en/vluchtinfo/jaar/--Select-- was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Daniël Cronk
Nov 26 '18 at 13:16
sorry. i think the cold has gotten to my brain. I've added the generated html code to my original post.
– Daniël Cronk
Nov 26 '18 at 13:25
@DaniëlCronk No problem, I have added a change in the javascript as well.
– jeroen
Nov 26 '18 at 13:35
|
show 4 more comments
It would, still be the same value. This change does not affect the behavior of the script and it still redirects me to /--Select--
– Daniël Cronk
Nov 26 '18 at 13:12
@DaniëlCronk What does the generated html look like? After this change of course.
– jeroen
Nov 26 '18 at 13:13
I get the following page: Not Found The requested URL /vg/en/vluchtinfo/jaar/--Select-- was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Daniël Cronk
Nov 26 '18 at 13:16
sorry. i think the cold has gotten to my brain. I've added the generated html code to my original post.
– Daniël Cronk
Nov 26 '18 at 13:25
@DaniëlCronk No problem, I have added a change in the javascript as well.
– jeroen
Nov 26 '18 at 13:35
It would, still be the same value. This change does not affect the behavior of the script and it still redirects me to /--Select--
– Daniël Cronk
Nov 26 '18 at 13:12
It would, still be the same value. This change does not affect the behavior of the script and it still redirects me to /--Select--
– Daniël Cronk
Nov 26 '18 at 13:12
@DaniëlCronk What does the generated html look like? After this change of course.
– jeroen
Nov 26 '18 at 13:13
@DaniëlCronk What does the generated html look like? After this change of course.
– jeroen
Nov 26 '18 at 13:13
I get the following page: Not Found The requested URL /vg/en/vluchtinfo/jaar/--Select-- was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Daniël Cronk
Nov 26 '18 at 13:16
I get the following page: Not Found The requested URL /vg/en/vluchtinfo/jaar/--Select-- was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
– Daniël Cronk
Nov 26 '18 at 13:16
sorry. i think the cold has gotten to my brain. I've added the generated html code to my original post.
– Daniël Cronk
Nov 26 '18 at 13:25
sorry. i think the cold has gotten to my brain. I've added the generated html code to my original post.
– Daniël Cronk
Nov 26 '18 at 13:25
@DaniëlCronk No problem, I have added a change in the javascript as well.
– jeroen
Nov 26 '18 at 13:35
@DaniëlCronk No problem, I have added a change in the javascript as well.
– jeroen
Nov 26 '18 at 13:35
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53481707%2fjquery-page-url-load-on-select-strange-behavior%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Can you delete this
onchange="window.location = jQuery('#urlSelect option:selected').val();"
and addconsole.log(url)
to your bind function and check value in console panel also removereturn false;
it is not needed also check your '$id' it will be always the same from$_GET
after first selection you should change it to$j
like jeroen wrote– Oleksandr Pobuta
Nov 26 '18 at 13:18