Jump to content
  • Announcements

    • boen_robot

      Guidelines and Netiquette   03/28/2017

      Posting Problems:   Having problems posting your topic? Read through this: To join, you agree to our terms and conditions and fill out and submit a registration form. An activation email will be sent to your email adress, so you'll need to verify your account. After that the account has to be validated by one of the moderators. This will mean that it can take up to a day to be activated. A couple of things to remember to ensure approval: Don't use an email address in one of those $2 four character .com domains eg. xyds.com. These will be deleted and the domain added to the banned list. Don't use an email address that is within a domain with a bad reputation for spam. A Google search is run on every email address and email domain. Don't sign up with an email address that doesn't exist, doesn't work or requires the sender to answer a quiz before their email can get to you. Put your country and or state and city in the signup form. Blank forms will go to the botton of the "to do" list. And make sure that your email address and your country match, saying you're from Alabama and using a .ru email address is not going to get you activated. After a membership is activated the first few posts will be monitored. Posting spam or unapproved topics described in the agreement results in an immediate ban. The email provider and the IP addresses associated with the account will be banned and all posts will be deleted. These strict measures have been deemed necessary to hinder spam. Sorry for any inconvenience this causes, but it's not liable to change. If, after reading this, you still can't post and don't understand why, contact one of the Moderators listed here.   Topic Guidelines   Including the following information can expedite an accurate response from board members: Must be a Specific Problem or Question related to web design and development Include Code in Question (wrap with   for small blocks of code and for longer blocks   ) Include Code Author Include Extra Notes/Modifications/Attempts Include web link to page/file when possible Content Guidelines   You may not post, upload, link to, or email any Content that contains, promotes, gives instruction about, or provides prohibited Content. Prohibited Content includes any Content that breaks any local, state, county, national or international law. Prohibited Content also includes: No direct or indirect advertising or websites, forums, products, services No hijacking of posts (do not post your question in someone elses) Content that infringes upon any rights [ex. MP3s and ROMs] (including, but not limited to, copyrights and trademarks) Abusive, threatening, defamatory, racist, or obscene Viruses or any other harmful computer software False Information or libel Spam, chain letters, or Pyramid schemes Gambling or Illicit drugs Terrorism Hacking or cheating for internet/online games Warez, Roms, CD-Keys, Cracks, Passwords, or Serial Numbers Pornography, nudity, or sexual material of any kind Excessive profanity Invasive of privacy or impersonation of any person/entity Hacking materials or information Posting Tips   There are more BBcodes than there are buttons for on the reply menu. To get the full list, click "BB Code Help" underneath the clickable smilie face menu. Use   for small snippets of code Use   for lengthy snippets of code Use   if your snippet is HTML (optional) Use   if your snippet is SQL (optional) Rules of Conduct   Be nice. There's no need for calling someone stupid if they ask an 'easy' question. Keep your avatars and signatures absolutely child friendly. We have a younger audience on this forum. Keep your language appropriate for the same reason above. Do not PM moderators for help on the forum. Post on the topic, or create a new one.   Spam:   Recently, as you have all without doubt noticed, we have had lots of spam and advertisement on the forum. Therefore, we'd like to alert you as to what to do when you have found any of the aforementioned annoying messages: it. Immediately. Give a clear reason, please, if the advertising is not evident. DO NOT POST! Report, let the post stay as is, and we will get to it, meanwhile if you continue to post as normal in the other threads, it won't be on the top so long. Refrain from PMing the member. This won't help at all, as they are most likely spambots anyway. Thank you.       Images in signatures:   After thinking of users on dial-up, we have decided to enforce the following rules regarding signatures. Please pay heed to them. Respecting these rules is respecting the members on this forum with dial-up. Signature rules: No animated images AT ALL. No matter the amount of animation. Maximum image widthxheight: 300x150 Maximum image (file) size: 15kb Use calm colors. Do not use highly contrasting images in your signature, as this can get really annoying when seeing several posts from one member in the same thread. The same prohibited content goes for images as for posts. Lastly, use common sense. No lengthy signatures please. Save us some scrolling. Thank you.       Links in signatures:   Please understand that w3schools.com only exists because of voluntary work and is barely supported by the advertising littered throughout the tutorials and the forum. So, please, stop advertising other sites. DO not post links that drive traffic away from the w3schools domain - especially to a site that offers similar if not identical information. Please help support the site by keeping individuals on it. Thank you. Here are some guidelines as to what you can put in your signature: w3schools links --> allowed w3.org links --> allowed browser links --> allowed html editor links --> allowed personal sites --> allowed tutorial sites competing with w3schools --> NOT allowed sites completely irrelevant to webprogramming and this forum --> NOT allowed   Thanks for understanding, and for taking the time to read this. ~W3Schools Modstaff~
phn221181

noUiSlider is 'undefined'

Recommended Posts

Hello, i tried to style up my script.

i integrated a noUiSlider but it doesn't work. i looked for solving in the documentation, YouTube and google, without success. Can someone help me to make it work?

The JavaScript Code can be found at the bottom of the script tag. Thanks!

<!DOCTYPE html>
<html lang="de-DE">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="font-awesome.min.css">

<title>Matheaufgaben</title>
    <!-- Bootstrap -->
	<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
    <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" />
	<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css" />-->
	<!-- CSS Files -->
    <!--<link href="../bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet" />-->
	<link href="assets/css/bootstrap.min.css" rel="stylesheet" />
    <link href="assets/css/material-kit.css" rel="stylesheet"/>
	
<style>

#box {
	width:400px;
}
#configuration {
	height:200px;
	padding: 10px 0;
	text-align: center;
	// background-color: ;
	margin-top: 10px;	
}

.h2 {
	font-size:30px;
}
body {
	background-color:#fff;
}

.fadeInAndOut {
	padding-left: 100px;
	-webkit-animation: fadeinout 4s linear forwards;
	animation: fadeinout 4s linear forwards;
}

@-webkit-keyframes fadeinout {
  0%,100% { opacity: 0; }
  50% { opacity: 1; }
}

@keyframes fadeinout {
  0%,100% { opacity: 0; }
  50% { opacity: 1; }
}

</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>

var richtig = 0, falsch = 0, last_erg = '';
var plusaufgaben = 0;
var minusaufgaben = 0;
var multiaufgaben = 0;
var diviaufgaben = 0;

function showconfig() {
    var x = document.getElementById("configuration");
    if (x.style.display === "none") {
        x.style.display = "block";
    } else {
        x.style.display = "none";
    }
	var user = ''
    for (var i = 0; i < 2; i++) {
		if(document.userdata.user[i].checked) {
			user = (document.userdata.user[i].value);
			break;
		}
    }
	document.getElementById("showuser").innerHTML = user;
} 
 
function hilfe() {
	/* show result in  red */
	document.getElementById("erg-output").style.color = "red";
	/* Using Help Button is like a not solved task*/
	falsch++;
	document.getElementById("falsch").innerHTML = falsch;
	/* Reset Inputfield */
	document.ergebnis.ergebnis_eingabe.value ="";
	/* neue  Aufgabe nach 1,5 Sekunden */
	alert(erg);
	aufgabe_erstellen();
}
  
function sleep(milliseconds) {
	var start = new Date().getTime();
	for (var i = 0; i < 1e7; i++) {
		if ((new Date().getTime() - start) > milliseconds){
		break;
		}
	}
}
  
function compare () {
	/* compare entered and calculated value */
	var erg_eingabe = (document.ergebnis.ergebnis_eingabe.value);
  
	if (erg == erg_eingabe) {
		/* Reset input field */
		document.ergebnis.ergebnis_eingabe.value ="";
		/* increment richtig++ */
		richtig++;
		document.getElementById("visual").innerHTML = '<i class="fa fa-check fa-2x" aria-hidden="true"></i>';
		/* show quantity correct tasks */
		document.getElementById("richtig").innerHTML = richtig;
		/* check rating */
		rating(richtig);
		/* nächste Aufgabe */
		aufgabe_erstellen();
    
	} else {
		falsch++;
		document.getElementById("visual").innerHTML = '<i class="fa fa-times fa-2x" aria-hidden="true"></i>';
		document.ergebnis.ergebnis_eingabe.value ="";
		document.getElementById("falsch").innerHTML = falsch;
		last_aufgabe = aufgabe;
	}
  
}

function rating(richtig) {
    if (parseInt(richtig) >= 100) {
      document.getElementById("rating").innerHTML = '<i class="fa fa-star fa-2x" aria-hidden="true"></i><i class="fa fa-star fa-2x" aria-hidden="true"></i><i class="fa fa-star fa-2x" aria-hidden="true"></i><i class="fa fa-star fa-2x" aria-hidden="true"></i><i class="fa fa-star fa-2x" aria-hidden="true"></i>';
    } else if (parseInt(richtig) >= 80) {
      document.getElementById("rating").innerHTML = '<i class="fa fa-star fa-2x" aria-hidden="true"></i><i class="fa fa-star fa-2x" aria-hidden="true"></i><i class="fa fa-star fa-2x" aria-hidden="true"></i><i class="fa fa-star fa-2x" aria-hidden="true"></i>';
    } else if (parseInt(richtig) >= 60) { 
      document.getElementById("rating").innerHTML = '<i class="fa fa-star fa-2x" aria-hidden="true"></i><i class="fa fa-star fa-2x" aria-hidden="true"></i><i class="fa fa-star fa-2x" aria-hidden="true"></i>';
    } else if (parseInt(richtig) >= 40) {
      document.getElementById("rating").innerHTML = '<i class="fa fa-star fa-2x" aria-hidden="true"></i><i class="fa fa-star fa-2x" aria-hidden="true"></i>';
    } else if (parseInt(richtig) >= 20) {
      document.getElementById("rating").innerHTML = '<i class="fa fa-star fa-2x" aria-hidden="true"></i>';  
    } 
}

function define_min() {
	var zahlenraum1 = parseInt(document.zahlenraum.minimal.value); 
	document.getElementById('min-output').innerHTML = zahlenraum1;
	aufgabe_erstellen();
}

function define_max() {	
	var zahlenraum2 = parseInt(document.zahlenraum.maximal.value); 
	document.getElementById('max-output').innerHTML = zahlenraum2;	
	aufgabe_erstellen();
}

function number_random(min,max) {
	return Math.floor(Math.random() * (max - min +1)) + min;
}

function aufgabe_erstellen() {

	/* show result in white */ 
	document.getElementById("erg-output").style.color = "white";
  
	/* if input empty create new task */
	if(document.ergebnis.ergebnis_eingabe.value == '') {
	
	var zahlenraum1 = parseInt(document.zahlenraum.minimal.value); 
	var zahlenraum2 = parseInt(document.zahlenraum.maximal.value); 
	
	zahl1 = number_random(1,zahlenraum1);
	zahl2 = number_random(1,zahlenraum2);
	console.log(zahl1 + ' ' + zahl2);
	
	
    // zahl1 = Math.floor(Math.random() * (max - min +1)) + min;
    // zahl2 = Math.floor(Math.random() * (max - min +1)) + min;

	/* check which operation is activeted */
    var op ='';
    for (var i = 0; i < 4; i++) {
		if(document.operatoren.op[i].checked) {
			op = (document.operatoren.op[i].value);
			break;
		}
    }

	/* Create Task, especially if num2 > num1 change order for "minus" 
      and create a String to show in div-element */
	if (op=='-') {
		/* if zahl2 > zahl1 change Summanden */
		if (zahl2 > zahl1) {
			var aufgabe = zahl2 + ' ' + op + ' ' + zahl1;
		} else {
			/* if not, Aufgabe as usual */
			var aufgabe = zahl1 + ' ' + op + ' ' + zahl2;
		}
	} else { 
		/* if not "-" */
		var aufgabe = zahl1 + ' ' + op + ' ' + zahl2;
	};
	
	eval(aufgabe);
    
	/* Calc results */
	switch (op) {
		case '+': erg = zahl1 + zahl2; plusaufgaben++; document.getElementById("add").innerHTML = plusaufgaben;
		break;
		case '-': if (zahl2 > zahl1) { erg = zahl2 - zahl1;} else { erg = zahl1 - zahl2;}; minusaufgaben++; document.getElementById("sub").innerHTML = minusaufgaben;
		break;
		case '*': erg = zahl1 * zahl2; multiaufgaben++; document.getElementById("mul").innerHTML = multiaufgaben;
		break;
		case '/': erg = zahl1 / zahl2; diviaufgaben++; document.getElementById("divi").innerHTML = diviaufgaben;
		break;
		default:  erg = '';
	}
   
	/* Show task and result (in white) */
	document.getElementById("aufgabe").innerHTML = aufgabe + " = ";
	document.getElementById("erg-output").innerHTML = erg;

	/* if inputfield not empty call function "compare" */
	} else {
	compare();
	}
}

var slider = document.getElementById('minimum');
noUiSlider.create(slider, {
	start: 30,
	range: {min: 10, max: 500}
})

</script>
</head>
<body>
<div id="box">
	<div class="row">
	<table><tr><td><button class="btn btn-success" onclick="showconfig()">Einstellungen</button><td style="color:green;padding-left:20px;" id="showuser"></td><td style="padding-left:10px;color:orange;" id="rating"></td></tr></table>
	</div>
	<div id="configuration">
	<div class="row">
	<form name="userdata">
		<div class="checkbox col-xs-6">
			<label><input type="checkbox" name="user" value="Ilias" />Ilias</label>
		</div>
		<div class="checkbox col-xs-6">
			<label><input type="checkbox" name="user" value="Kilian" />Kilian</label>  
		</div>	
	</form>
	</div>
	<div class="row">
	<form name="operatoren" onchange="aufgabe_erstellen()">
		<div class="radio col-md-3"><label><input type="radio" name="op" value="-"><i class="fa fa-plus fa-2x" aria-hidden="true"></i></input></label></div>
		<div class="radio col-md-3"><label><input type="radio" name="op" value="+"><i class="fa fa-minus fa-2x" aria-hidden="true"></i></input></label></div>
		<div class="radio col-md-3"><label><input type="radio" name="op" value="*"><i class="fa fa-certificate fa-2x" aria-hidden="true"></i></input></label></div>
		<div class="radio col-md-3"><label><input type="radio" name="op" value="/"><i class="fa fa-arrows-v fa-2x" aria-hidden="true"></i></input></label></div>
	</form>
	</div>
	<div class="row" style="padding-left:10px">
		<div class="col-xs-12 col-md-8">
			<div id="slider-connect" class="slider slider-info">
			</div>
		</div>
		<div class="col-xs-6 col-md-4">
			<div id="min-output">Min-Wert</div>
		</div>
	</div>
		
	<!--	
	<form name="zahlenraum">
		<table><tr><td>
		<input id="minimal" type="range" min="0" max="500" value="200" step="10" onchange="define_min()" ></input></td><td id="min-output">
		</td></tr>
		<tr><td>
		<input id="maximal" type="range" min="0" max="1000" value="500" step="10" onchange="define_max()"></input></td><td id="max-output">
		</td></tr>
		</table>
	</form>
	-->
	</div>
<hr>
	<table>
		<tr><td id="aufgabe" class="h2"></td><td id="erg-output"></td></tr>
	</table>		
	<div class=""><table><tr><td>
		<form name="ergebnis"> 
			<input type="number" name="ergebnis_eingabe" style="height:40px;font-size:30px" size="10">
		</form></td><td style="align:right" id="visual"></td></tr>
		</table>
		<button class="btn btn-default" style="" onclick="compare()">Check</button>
	</div>
<hr>
	<div>
		<table>
		<tr><td>richtig: </td><td style="color: green" id="richtig"> 0 </td><td>falsch: </td><td style="color:red;" id="falsch">0</td></tr></table>
		<table>
		<tr><td>+ </td><td id="add"></td><td> | - </td><td id="sub"></td><td> | * </td><td id="mul"></td><td> | / </td><td id="divi"></td></tr>
		</table>
	</div>
	<button class="btn btn-sm btn-danger" onclick="hilfe()">Hilfe?</button>
</div>

    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <!-- <script src="bootstrap-3.3.7/js/bootstrap.min.js"></script> -->
</body>
	<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
	<!--   Core JS Files   -->
	<script src="assets/js/jquery.min.js" type="text/javascript"></script>
	<script src="assets/js/bootstrap.min.js" type="text/javascript"></script>
	<script src="assets/js/material.min.js" type="text/javascript"></script>

	<!--  Plugin for the Sliders, full documentation here: http://refreshless.com/nouislider/ -->
	<script src="assets/js/nouislider.min.js" type="text/javascript"></script>
	<!--  Plugin for the Datepicker, full documentation here: http://www.eyecon.ro/bootstrap-datepicker/ -->
	<script src="assets/js/bootstrap-datepicker.js" type="text/javascript"></script>

	<!-- Control Center for Material Kit: activating the ripples, parallax effects, scripts from the example pages etc -->
	<script src="assets/js/material-kit.js" type="text/javascript"></script>
</html>

 

Share this post


Link to post
Share on other sites

The first thing you need to do is delete that sleep function before you accidentally use it.  Javascript has several ways to delay execution without making the browser use as much CPU as possible looping over and over.

All of your script tags are after the body tag.  I'm not sure if the browser is going to ignore that or not.  Put them in the body.  You're also including jQuery three times, the last one will overwrite the others.  Only include the one version you need.

The reason for the error message is because you're trying to run the noUiSlider function at the end of the head section, but you don't include those files until after the body (if they get included at all).  You can't run that function before the files that define it have been included.  Either use a load handler to run your initialization stuff or move that code after all of the files get included.

Share this post


Link to post
Share on other sites

Thanks someguy for your explanations. The first two aspects i understand an i can handle.

The third aspect is a little bit "foggy" for me. I understand that i try to start the function in the head. Where else can i run it. I tried different "positions" like also head area, after the the </html> in the body... no useful result. finally i see the hole code as text now.

It would be really nice, if you can show me the right line an structure. With best regards...

pat

 

Share this post


Link to post
Share on other sites

The body ends at </body>, nothing except the closing </html> tag should be after that.  If you put code in the head that you want to run when the page is finished loading, use a document load or ready event listener to run that code when the page finishes loading.  Or, put it at the end of the body (but still inside the body) after you include all of the script files.

  • Thanks 1

Share this post


Link to post
Share on other sites

Yeah, there is no longer an error in the console logged. The JS-Files are included. But now i don't see a slider :-/ . On the left side of "Min-Wert" should it visible.

here is the example. In developmentmode on the browser i see the needed div. But there is no content unfortunatly. 

Share this post


Link to post
Share on other sites

yes, i made buttons and it's also okay. so i changed some points in the code and my kids can use it now ;-).

I have another question. Trying to control how many tasks and which skill they train i added some more variables an print them in a table "solved tasks" for each level.

This level i want to send by xmlhttp.request after hitting the yellow button. if i log the transaction in console i see the values of the variables: niveau1 and niveau2. I use GET to transfer. Unfortunately i loose the information in this process. The responstext is without the php echo value :-/

Thanks so much for being so patient with me ;-)

 

the JS-Code

function sendData() {
	console.log('niv1: '+niveau1+' niv2: '+niveau2); // I SEE THE VALUES IN CONSOLE
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function() {
		if (this.readyState == 4) {
		console.log(xmlhttp);
		}
		if (this.readyState == 4 && this.status == 200) {
		document.getElementById("returnresponse").innerHTML = this.responseText; // responseText is empty
		}
	};
	xmlhttp.open("GET", "rechnensave.php?", true);
	xmlhttp.send('niv1='+niveau1+'&niv2='+niveau2);
}

PHP(rechnensave.php):

<?php

header('Content-Type: text/html; charset=utf-8'); 
header('Cache-Control: must-revalidate, pre-check=0, no-store, no-cache, max-age=0, post-check=0'); // for IE

$niv1	= $_GET['niv1'];
$niv2	= $_GET['niv2'];
echo "Test: ".$niv1." / ".$niv2; // responseText shows "Test / "

?>

 

Share this post


Link to post
Share on other sites

i got it working...

ich changed the xml open part as following:

xmlhttp.open("GET", 'rechnensave.php?niv1='+niveau1+'&niv2='+niveau2, true); 
xmlhttp.send();

THANKS for your support...

Thread can be closed, but the slider doesn't still work.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×