Reputation: 37
Would like to ask you how I can change include link by selected value.
Select form:
<select>
<option value="folder1">1</option>
<option value="folder2">2</option>
<option value="folder3">3</option>
</select>
If i selected 3 value include link should be like this:
<?php include '/folder3/firstpage.php' ?>
<?php include '/folder3/secondpage.php' ?>
<?php include '/folder3/thirdpage.php' ?>
Link to JSFiddle demo
Thank you for your answers.
Upvotes: 0
Views: 737
Reputation: 6524
below is to show the .php
file content using jQuery Ajax
note: in client side (browser) you can't get/include .php
file without iframe or XHR (ajax)
function getContent(selector, url) {
$.ajax({
url: url,
success: function(data) {
$(selector).text(data.responseText)
},
error: function(err) {
console.log(err)
alert(err.statusText)
}
})
}
$("#test").on("change", function() {
var firstpage = '/' + $("#test").val() + '/firstpage.php';
var secondpage = '/' + $("#test").val() + '/secondpage.php';
var thirdpage = '/' + $("#test").val() + '/thirdpage.php';
getContent("#debug", firstpage);
getContent("#debug1", secondpage);
getContent("#debug2", thirdpage);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="test">
<option disabled selected value> -- select an option -- </option>
<option value="folder1">Folder1</option>
<option value="folder2">Folder2</option>
<option value="folder3">Folder3</option>
</select>
<br><br>
firstpage: <span id="debug"></span><br>
secondpage: <span id="debug1"></span><br>
thirdpage: <span id="debug2"></span><br>
Upvotes: 1