Kontinent Land Auswahl verbessert Ajax

This commit is contained in:
aschwarz 2024-01-25 10:27:11 +01:00
parent 3282e34713
commit 3097670cab
7 changed files with 96 additions and 334 deletions

193
ajax.js
View File

@ -1,193 +0,0 @@
/* Simple AJAX Code-Kit (SACK) v1.6.1 */
/* ©2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence,
see documentation or authors website for more details */
function sack(file) {
this.xmlhttp = null;
this.resetData = function() {
this.method = "POST";
this.queryStringSeparator = "?";
this.argumentSeparator = "&";
this.URLString = "";
this.encodeURIString = true;
this.execute = false;
this.element = null;
this.elementObj = null;
this.requestFile = file;
this.vars = new Object();
this.responseStatus = new Array(2);
};
this.resetFunctions = function() {
this.onLoading = function() { };
this.onLoaded = function() { };
this.onInteractive = function() { };
this.onCompletion = function() { };
this.onError = function() { };
this.onFail = function() { };
};
this.reset = function() {
this.resetFunctions();
this.resetData();
};
this.createAJAX = function() {
try {
this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
try {
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
this.xmlhttp = null;
}
}
if (! this.xmlhttp) {
if (typeof XMLHttpRequest != "undefined") {
this.xmlhttp = new XMLHttpRequest();
} else {
this.failed = true;
}
}
};
this.setVar = function(name, value){
this.vars[name] = Array(value, false);
};
this.encVar = function(name, value, returnvars) {
if (true == returnvars) {
return Array(encodeURIComponent(name), encodeURIComponent(value));
} else {
this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
}
}
this.processURLString = function(string, encode) {
encoded = encodeURIComponent(this.argumentSeparator);
regexp = new RegExp(this.argumentSeparator + "|" + encoded);
varArray = string.split(regexp);
for (i = 0; i < varArray.length; i++){
urlVars = varArray[i].split("=");
if (true == encode){
this.encVar(urlVars[0], urlVars[1]);
} else {
this.setVar(urlVars[0], urlVars[1]);
}
}
}
this.createURLString = function(urlstring) {
if (this.encodeURIString && this.URLString.length) {
this.processURLString(this.URLString, true);
}
if (urlstring) {
if (this.URLString.length) {
this.URLString += this.argumentSeparator + urlstring;
} else {
this.URLString = urlstring;
}
}
// prevents caching of URLString
this.setVar("rndval", new Date().getTime());
urlstringtemp = new Array();
for (key in this.vars) {
if (false == this.vars[key][1] && true == this.encodeURIString) {
encoded = this.encVar(key, this.vars[key][0], true);
delete this.vars[key];
this.vars[encoded[0]] = Array(encoded[1], true);
key = encoded[0];
}
urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
}
if (urlstring){
this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
} else {
this.URLString += urlstringtemp.join(this.argumentSeparator);
}
}
this.runResponse = function() {
eval(this.response);
}
this.runAJAX = function(urlstring) {
if (this.failed) {
this.onFail();
} else {
this.createURLString(urlstring);
if (this.element) {
this.elementObj = document.getElementById(this.element);
}
if (this.xmlhttp) {
var self = this;
if (this.method == "GET") {
totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
this.xmlhttp.open(this.method, totalurlstring, true);
} else {
this.xmlhttp.open(this.method, this.requestFile, true);
try {
this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
} catch (e) { }
}
this.xmlhttp.onreadystatechange = function() {
switch (self.xmlhttp.readyState) {
case 1:
self.onLoading();
break;
case 2:
self.onLoaded();
break;
case 3:
self.onInteractive();
break;
case 4:
self.response = self.xmlhttp.responseText;
self.responseXML = self.xmlhttp.responseXML;
self.responseStatus[0] = self.xmlhttp.status;
self.responseStatus[1] = self.xmlhttp.statusText;
if (self.execute) {
self.runResponse();
}
if (self.elementObj) {
elemNodeName = self.elementObj.nodeName;
elemNodeName.toLowerCase();
if (elemNodeName == "input"
|| elemNodeName == "select"
|| elemNodeName == "option"
|| elemNodeName == "textarea") {
self.elementObj.value = self.response;
} else {
self.elementObj.innerHTML = self.response;
}
}
if (self.responseStatus[0] == "200") {
self.onCompletion();
} else {
self.onError();
}
self.URLString = "";
break;
}
};
this.xmlhttp.send(this.URLString);
}
}
};
this.reset();
this.createAJAX();
}

View File

@ -50,54 +50,26 @@ h1
-->
</style>
<script type='text/javascript' src='ajax.js'></script>
<script src='jquery-3.4.1.min.js'></script>
<script type='text/javascript'>
/************************************************************************************************************
Ajax chained select
Copyright (C) 2006 DTHMLGoodies.com, Alf Magne Kalleland
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
written by Alf Magne Kalleland.
Alf Magne Kalleland, 2006
Owner of DHTMLgoodies.com
************************************************************************************************************/
var ajax = new sack();
function getCityList(sel)
{
var countryCode = sel.options[sel.selectedIndex].value;
document.getElementById('dhtmlgoodies_city').options.length = 0; // Empty city select box
if(countryCode.length>0){
ajax.requestFile = 'getSubCat.php?countryCode='+countryCode; // Specifying which file to get
ajax.onCompletion = createCities; // Specify function that will be executed after file has been found
ajax.runAJAX(); // Execute AJAX function
}
function fetch_select(){
var kontinent = document.getElementById('kontinent').options[document.getElementById('kontinent').options.selectedIndex].value;
$.ajax({
type: 'POST',
url: 'get_land.php',
data: {
'function': 'fetch_select',
'kontinent': kontinent
},
success: function(result) { //we got the response
document.getElementById('land').innerHTML=result;
},
error: function(xhr, status, exception) {
console.log(xhr);
}
});
}
function createCities()
{
var obj = document.getElementById('dhtmlgoodies_city');
eval(ajax.response); // Executing the response from Ajax as Javascript code
}
</script>
@ -106,7 +78,7 @@ function createCities()
<link rel=\"stylesheet\" href=\"styles_pc.css\" type=\"text/css\">
</head>
<body onload=\"if(document.auswert)document.auswert.dhtmlgoodies_country.focus();if(document.auswert)document.auswert.uberschrift.focus();return false;\">
<body onload='fetch_select();'>
<h2>Fragebogen zum Auslandspraktikum</h2>
<p align='center'>
@ -126,8 +98,8 @@ function createCities()
<tr>
<td colspan='4' style='border-left-style: solid; border-left-width: 2px; border-right-style: solid; border-right-width: 2px; border-top-style: solid; border-top-width: 2px'>
<p style='margin-left: 3px; margin-right: 3px'>
<b>Pers&oul,;nliche Angaben<br>
</b> Deine pers&oul,;nlichen Daten
<b>Pers&ouml;nliche Angaben<br>
</b> Deine pers&ouml;nlichen Daten
werden streng vertraulich behandelt und dienen in erster Linie nur
uns, um dir eventuelle R&uuml;ckfragen zu stellen!
</td>
@ -216,7 +188,7 @@ function createCities()
<td width='82%' colspan='3' style='border-right-style: solid; border-right-width: 2px'>
<p style='margin-left: 3px; margin-right: 3px'>
<input type='checkbox' name='eiver_rueckfr' value='Y'"; if($row_einver['einverst'] == 'Y'){ echo " checked "; } echo">
Ich bin damit einverstanden, dass meine <u>Emailadresse</u> f&uuml;r eventuelle Nachfragen ver&oul,;ffentlicht wird.
Ich bin damit einverstanden, dass meine <u>Emailadresse</u> f&uuml;r eventuelle Nachfragen ver&ouml;ffentlicht wird.
</td>
</tr>
<tr>
@ -251,7 +223,7 @@ function createCities()
$query2 = "SELECT kid, kontinent FROM aesp_kontinent ORDER BY kontinent ASC";
$result2 = $db->query ($query2)
or die ("Cannot execute query");
echo "<select id='dhtmlgoodies_country' name='dhtmlgoodies_country' onchange='getCityList(this)' onfocus='getCityList(this)'>
echo "<select id='kontinent' name='kontinent' onchange='fetch_select();'>
<option value=''>Select</option>";
#echo "<option value='%'";if($row3[kontinent] == '%'){echo " selected";} echo">Alle&nbsp;&nbsp;&nbsp;</option>\n";
while ($row2 = $result2->fetch_array()){
@ -267,7 +239,8 @@ function createCities()
Land </td>
<td width='82%' style='border-right-style: solid; border-right-width: 2px'>
<p style='margin-left: 3px; margin-right: 3px'>
<select id='dhtmlgoodies_city' name='dhtmlgoodies_city'>
<select id='land' name='land'>
</select>
</p>
</td>
</tr>
@ -466,8 +439,8 @@ function createCities()
<input type='radio' value='OPI' name='modul' "; if($row['modul'] == 'OPI'){ echo " checked "; } echo">Organisation, Personal, Informationsverarbeitung,<br>
<input type='radio' value='OV' name='modul' "; if($row['modul'] == 'OV'){ echo " checked "; } echo">Ordnungsverwaltung<br>
<input type='radio' value='LV' name='modul' "; if($row['modul'] == 'LV'){ echo " checked "; } echo">Leistungsverwaltung<br>
<input type='radio' value='WFB' name='modul' "; if($row['modul'] == 'WFB'){ echo " checked "; } echo">Wirtschaft und Finanzen, &oul,;ffentliche Betriebe<br>
<input type='radio' value='KFS' name='modul' "; if($row['modul'] == 'KFS'){ echo " checked "; } echo">Kommunalpolitik, F&uuml;hrung im &oul,;ffentlichen Sektor
<input type='radio' value='WFB' name='modul' "; if($row['modul'] == 'WFB'){ echo " checked "; } echo">Wirtschaft und Finanzen, &ouml;ffentliche Betriebe<br>
<input type='radio' value='KFS' name='modul' "; if($row['modul'] == 'KFS'){ echo " checked "; } echo">Kommunalpolitik, F&uuml;hrung im &ouml;ffentlichen Sektor
</td>
</tr>
@ -665,7 +638,7 @@ function createCities()
<td width='43%' style='border-left-style: solid; border-left-width: 2px'>
<p style='margin-left: 3px; margin-right: 3px'>
Ich habe
etwas dazulernen k&oul,;nnen </td>
etwas dazulernen k&ouml;nnen </td>
<td width='56%' style='border-right-style: solid; border-right-width: 2px'>
<input type='radio' name='dazulernen' value='1'"; if($row['dazulernen'] == '1'){ echo " checked "; } echo">1&nbsp;&nbsp;&nbsp;&nbsp;
@ -815,7 +788,7 @@ function createCities()
<p style='margin-left: 3px; margin-right: 3px'>
<b>Deine abschließenden Worte</b><br>
<span style='font-size: 8pt'>Was du einem
Studenten mit auf den langen Weg ins Ausland geben m&oul,;chtest! Ein
Studenten mit auf den langen Weg ins Ausland geben m&ouml;chtest! Ein
paar gute Tipps vielleicht? <br>
&nbsp;</h1>
</td>
@ -887,8 +860,8 @@ if(!$sql){
}
## Bewerbung ##
$kontinent=$_POST['dhtmlgoodies_country'];
$land=$_POST['dhtmlgoodies_city'];
$kontinent=$_POST['kontinent'];
$land=$_POST['land'];
$stadt=$_POST['stadt'];
$stelle=$_POST['stelle'];
$adresse=$_POST['kontaktadresse'];
@ -1037,7 +1010,7 @@ echo"
<td colspan=\"2\"><br>
<p align=\"center\"><b>Herzlichen Dank!</b>
<br>
Wir m&oul,;chten uns ganz herzlich bei Dir daf&uuml;r bedanken, dass Du die M&uuml;he auf
Wir m&ouml;chten uns ganz herzlich bei Dir daf&uuml;r bedanken, dass Du die M&uuml;he auf
dich genommen hast, diesen Bogen auszuf&uuml;llen und somit allen
Studierenden nach dir einiges an Sorgen und Ängsten genommen
hast!<br>

View File

@ -1,31 +0,0 @@
<?php
include("aespa/datenbankanbindung.php"); // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php
header("Content-Type: text/html;charset=utf-8");
$lid = $_COOKIE["ck_lid"];
$kid=$_GET['countryCode'];
$db = dbconnect();
$query = "SELECT lid, land FROM aesp_land WHERE kid LIKE '$kid' ORDER BY land ASC";
$result = $db->query ($query);
##$query1 = $db->query("SELECT ukid FROM quelle WHERE lid='$lid'");
##$result1 = $query1->fetch_array();
if(isset($_GET['countryCode'])){
#echo "obj.options[obj.options.length] = new Option('[alle]','%');\n";
while ($row = $result->fetch_array()){
##echo "obj.options[obj.options.length] = new Option('$row[bezeichnung]','$row[ukid]'";if($result1[ukid] == $row[ukid]){echo ",'selected'";}echo");\n";
echo "obj.options[obj.options.length] = new Option('$row[land]','$row[lid]'";if($row['lid'] == $lid){echo ",'selected'";}echo");\n";
}
}
?>

38
get_land.php Normal file
View File

@ -0,0 +1,38 @@
<?php
include("aespa/datenbankanbindung.php"); // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php
$function = $_POST['function'];
if ($function == 'fetch_select') {
$db = dbconnect();
if (isset($_COOKIE['uid1'])) {
$uid1 = $_COOKIE['uid1'];
}
if(isset($_COOKIE['ck_uid1'])){
$uid1 = $_COOKIE['ck_uid1'];
}else{
$uid1 = '';
}
if (isset($_POST['kontinent'])) {
$kid = $_POST['kontinent'];
}
$result1 = $db->query("SELECT land FROM aesp_bewerbung WHERE uid='$uid1'");
$row1 = $result1->fetch_array();
$db = dbconnect();
$query = "SELECT lid, land FROM aesp_land WHERE kid LIKE '$kid' ORDER BY land ASC";
$result = $db->query($query);
while ($row = $result->fetch_array()) {
echo "<option value='$row[lid]'";
if ($row1['land'] == $row['lid']) {
echo " selected ";
}
echo ">" . $row['land'] . "</option>";
}
exit;
}
?>

2
jquery-3.4.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,8 @@ include("aespa/datenbankanbindung.php"); // f&uuml;gt die Datenbankanbindung
session_start();
if(isset($_SESSION["uid1"])){
$uid=$_SESSION["uid1"];
}elseif(isset($_COOKIE['uid1'])){
$uid=$_COOKIE['uid1'];
}else{
$uid='';
}

View File

@ -208,58 +208,29 @@ h1
-->
</style>
<link rel=\"stylesheet\" href=\"styles_pc.css\" type=\"text/css\">
<script type='text/javascript' src='ajax.js'></script>
<script src='jquery-3.4.1.min.js'></script>
<script type='text/javascript'>
/************************************************************************************************************
Ajax chained select
Copyright (C) 2006 DTHMLGoodies.com, Alf Magne Kalleland
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
written by Alf Magne Kalleland.
Alf Magne Kalleland, 2006
Owner of DHTMLgoodies.com
************************************************************************************************************/
var ajax = new sack();
function getCityList(sel)
{
var countryCode = sel.options[sel.selectedIndex].value;
document.getElementById('dhtmlgoodies_city').options.length = 0; // Empty city select box
if(countryCode.length>0){
ajax.requestFile = 'getSubCat.php?countryCode='+countryCode; // Specifying which file to get
ajax.onCompletion = createCities; // Specify function that will be executed after file has been found
ajax.runAJAX(); // Execute AJAX function
}
function fetch_select(){
var kontinent = document.getElementById('kontinent').options[document.getElementById('kontinent').options.selectedIndex].value;
$.ajax({
type: 'POST',
url: 'get_land.php',
data: {
'function': 'fetch_select',
'kontinent': kontinent
},
success: function(result) { //we got the response
document.getElementById('land').innerHTML=result;
},
error: function(xhr, status, exception) {
console.log(xhr);
}
});
}
function createCities()
{
var obj = document.getElementById('dhtmlgoodies_city');
eval(ajax.response); // Executing the response from Ajax as Javascript code
}
</script>
</head>
<body onload=\"if(document.auswert)document.auswert.dhtmlgoodies_country.focus();if(document.auswert)document.auswert.uberschrift.focus();return false;\">
<body onload='fetch_select();'>
<h2>Fragebogen zum Auslandspraktikum</h2>
<p align='center'>
@ -407,7 +378,7 @@ function createCities()
$query2 = "SELECT kid, kontinent FROM aesp_kontinent ORDER BY kontinent ASC";
$result2 = $db->query ($query2)
or die ("Cannot execute query");
echo "<select id='dhtmlgoodies_country' name='dhtmlgoodies_country' onchange='getCityList(this)' onfocus='getCityList(this)'>
echo "<select id='kontinent' name='kontinent' onchange='getCityList(this)' onfocus='getCityList(this)'>
<option value=''>Select</option>";
#echo "<option value='%'";if($row3[kontinent] == '%'){echo " selected";} echo">Alle&nbsp;&nbsp;&nbsp;</option>\n";
while ($row2 = $result2->fetch_array()){
@ -423,7 +394,7 @@ function createCities()
Land </td>
<td width='82%' style='border-right-style: solid; border-right-width: 2px'>
<p style='margin-left: 3px; margin-right: 3px'>
<select id='dhtmlgoodies_city' name='dhtmlgoodies_city'>
<select id='land' name='land'>
</p>
</td>
</tr>
@ -1035,8 +1006,8 @@ if(!$sql){
}
## Bewerbung ##
$kontinent=$_POST['dhtmlgoodies_country'];
$land=$_POST['dhtmlgoodies_city'];
$kontinent=$_POST['kontinent'];
$land=$_POST['land'];
$stadt=$_POST['stadt'];
$stelle=$_POST['stelle'];
$adresse=$_POST['kontaktadresse'];