Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- <script type="text/javascript">
- $('#idcat').change(function(){
- var val = $(this).val();
- $('#idcat2').html('');
- $.ajax({
- type: 'POST',
- url: 'templates/megawebshop/html/com_virtuemart/category/show.php',
- data: {'model': val, 'url': val},
- success: function(data) {
- var obj = JSON.parse(data);
- obj.forEach(function(item) {
- $('#idcat2').append($("<option></option>").attr("value",item).text(item));
- })
- }
- });
- });
- $('#idcat2').change(function(){
- var val = $(this).val();
- $('#redirect').attr("value", $url)
- });
- </script>
- <input id="redirect" type="submit" name="submit" value="Кнопка" />
- // файл show.php
- $MODEL = $_POST['model'];
- $URL = $_POST['url'];
- if (isset($MODEL) && !empty($MODEL)) {
- $query = "SELECT model FROM filtr_db WHERE marka='$MODEL'";
- $DB = mysql_query($query);
- // Обработаем
- $JSON = array();
- while ($row = mysql_fetch_assoc($DB)) {
- $JSON[] = $row['model'];
- }
- // Выводим
- echo json_encode($JSON);
- } else {
- echo '[]';
- };
- if (isset($URL) && !empty($URL)) {
- $query = "SELECT url FROM filtr_db WHERE model='$URL'";
- $DB = mysql_query($query);
- $url = array();
- while ($row=mysql_fetch_assoc($DB))
- {
- $url = $row['url'];
- }
- }
- $hostname = "localhost";
- $username = "root";
- $password = "";
- $dbName = "";
- mysql_connect($hostname, $username, $password) or die ("Не могу создать соединение");
- mysql_query('SET NAMES utf8') or header('Location: Error');
- mysql_select_db($dbName) or die (mysql_error());
- $MODEL = $_POST['model'];
- if (isset($MODEL) && !empty($MODEL)) {
- $query = "SELECT model, url FROM filtr_db WHERE marka='$MODEL'";
- $DB = mysql_query($query);
- $JSON = array();
- while ($row = mysql_fetch_assoc($DB)) {
- $JSON[$row['model']] = $row['url'];
- }
- echo json_encode($JSON);
- } else {
- echo '[]';
- }
- success: function(data) {
- var obj = JSON.parse(data);
- $.each(obj, function( index, value ) {
- $('#idcat2').append($("<option></option>").attr("value",index).text(value));
- });
- }
- <script type="text/javascript">
- $('#idcat2').change(function(){
- var val = $(this).val();
- window.location.href = val;
- });
- </script>
Add Comment
Please, Sign In to add comment