|
Uppss!!
I forgot to add tue links to the Jquery Library...
?>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
|
|
|
|
|
$(function(){
var comunidades = [
"Galicia",
"Asturias",
"Cantabria",
"Euskadi"
];
$("#comu").autocomplete({
source: comunidades
});
});
Assuming you have an <input> with id="comu" somewhere in your document, and you've linked to the jQuery UI CSS[^] as well as the scripts, that should work. It's virtually identical to the first example on the jQuery UI site[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi!!
thanks a lot for the answer...
I had to go use a safe copy of the Projekt..becouse I finally didn`t find a solution
Greetings!!
|
|
|
|
|
Ive just started to learn JS and Ive been stuck on a memory game script Ive been messing with. Ive finally got it able to accept images, instead of text, but when it matches any 2 the cards just turn back over :/ Also when I hit the image card, the whole game freezes. Help please?
Here is code below.
<pre><!DOCTYPE html>
<html>
<head>
<style>
div#memory_board{
background: url(klematis.jpg) -repeat;
border:#FF1493 5px solid;
width:700px;
height:500px;
padding:24px;
margin:0px auto;
}
div#memory_board > div{
background: url(klematis.jpg) no-repeat;
border:#FF1493 1px solid;
width:71px;
height:71px;
float:left;
margin:10px;
padding:20px;
font-size:64px;
cursor:pointer;
text-align:center;
}
div#memory_board > div img {
height: 100%;
}
.picture{
background-size: cover !important
}
</style>
<script>
// Scripted By Adam Khoury in connection with the following video tutorial:
// http://www.youtube.com/watch?v=c_ohDPWmsM0
var memory_array = ['url("http://cs61a.org/assets/images/john-denero.jpg")','A','B','B','C','C','D','D','E','E','F','F','G','G','H','H','I','I','J','J','K','K','L','L'];
var memory_values = [];
var memory_tile_ids = [];
var tiles_flipped = 0;
Array.prototype.memory_tile_shuffle = function(){
var i = this.length, j, temp;
while(--i > 0){
j = Math.floor(Math.random() * (i+1));
temp = this[j];
this[j] = this[i];
this[i] = temp;
}
}
function newBoard(){
tiles_flipped = 0;
var output = '';
memory_array.memory_tile_shuffle();
for(var i = 0; i < memory_array.length; i++){
output += '<div id="tile_'+i+'" class="picture" onclick="memoryFlipTile(this,\ ' + i + ')"></div>';
}
document.getElementById('memory_board').innerHTML = output;
}
function memoryFlipTile(tile,val){
if(tile.innerHTML == "" && memory_values.length < 2){
index = memory_array[val]
if (memory_array[val].length > 20){
tile.style.backgroundImage = memory_array[val];
}
else {
tile.style.background = '#FFF';
if (index == "image"){
tile.innerHTML = "<div style='font-size: 20px'>" +index +"</div>"
}
else
{
tile.innerHTML = index;
}
}
if(memory_values.length == 0){
memory_values.push(index);
memory_tile_ids.push(tile.id);
}
else if(memory_values.length == 1){
memory_values.push(index);
memory_tile_ids.push(tile.id);
if((memory_values[0].length > 20) && (memory_values[1].length < 20) && (memory_values[0] == gsi_dict[memory_values[1]])){
console.log("go")
tiles_flipped += 2;
// Clear both arrays
phrase = "You found "+ memory_values[1] +"!"
alert(phrase)
memory_values = [];
memory_tile_ids = [];
if(tiles_flipped == memory_array.length){
alert("Great job naming those awesome GSI's. Get ready to play again!");
document.getElementById('memory_board').innerHTML = "";
newBoard();
}
}
else if((memory_values[1].length > 20) && (memory_values[0].length < 20) && (memory_values[1] == gsi_dict[memory_values[0]])){
console.log("go")
tiles_flipped += 2;
phrase = "You found "+memory_values[0] + "!"
alert(phrase)
// Clear both arrays
memory_values = [];
memory_tile_ids = [];
if(tiles_flipped == memory_array.length){
alert("Great job naming the CS61A staff. Get ready to play again!");
document.getElementById('memory_board').innerHTML = "";
newBoard();
}
}
else {
console.log("flip")
function flip2Back(){
// Flip the 2 tiles back over
var tile_1 = document.getElementById(memory_tile_ids[0]);
var tile_2 = document.getElementById(memory_tile_ids[1]);
tile_1.style.background = "url(klematis.jpg)";
tile_1.innerHTML = "";
tile_2.style.background = "url(klematis.jpg)";
tile_2.innerHTML = "";
// Clear both arrays
memory_values = [];
memory_tile_ids = [];
}
setTimeout(flip2Back, 700);
}
}
}
}
</script>
</head>
<body>
<div id="memory_board"></div>
<script>newBoard();</script>
</body>
</html></pre>
|
|
|
|
|
Hey guys,
I need some hep finishing my javascript assignment. This is what I have so far:
randomlnt(Math.random(0-9));
var quoteElem = document.getElementByTagName("quote")[0];
var randomQ = randomlnt;
function randomlnt(lowest, size) {
lowest = Math.floor(size);
size = Math.random(0-9);
}
getQuote(randomQ); {
document.getElementByTagName("quoteElem").innerHTML = quoteElem;
}
The instructions are a total of 4 steps, some of which I have completed but I am not sure if they are correct or placed in the right area.
Here are the steps:
5. Directly below the comment section, insert a function named randomint that will be used to generate a random integer. Specify two parameters for the function named lowest and size. The lowest parameter will specify the lowest possible value for the random integer and the size parameter will set the number of integers to be generated. Use those two parameter values and the Math.floor() and Math.random() methods to return a random integer within the specified range.
6. Above the randomInt() function insert a command to call the function, generating a random integer from 0 to 9. (Hint: Remember that the size of this interval is 10 because it includes 0 in its range.) Store the result from the function in the randomQ variable.
7. Create a variable named quoteelem that references the first element in the document that has the quote tag name.
8. Call the getQuote() function using the randomQ variable as the parameter value to generate a random Jane Aust
|
|
|
|
|
ghazabaz wrote: insert a function named randomint
ghazabaz wrote: function randomlnt(
You might want to start by using the name you were told to use. There's a difference between a lower-case I and a lower-case L.
ghazabaz wrote: Use those two parameter values and the Math.floor() and Math.random() methods to return a random integer within the specified range.
Your function doesn't return anything. And it completely ignores the size parameter.
ghazabaz wrote: Math.random(0-9)
That passes a single argument of -9 to the Math.random function. But that function doesn't take any parameters, so it's ignored.
Math.random() - JavaScript | MDN[^]
ghazabaz wrote: randomlnt(Math.random(0-9));
Your function expects two parameters. You are only passing one parameter. You are also throwing away the value that your function isn't returning yet.
ghazabaz wrote: var randomQ = randomlnt;
That stores the function in the variable randomQ . Your instructions were to store the return value in that variable.
ghazabaz wrote: getQuote(randomQ); {
document.getElementByTagName("quoteElem").innerHTML = quoteElem;
}
That throws away the return value of the getQuote function. It then tries to set the innerHTML of every <quote> element in the document to the first quote element, which isn't going to work.
You need something more like:
quoteElem.innerHTML = getQuote(randomQ);
NB: The MDN documentation for Math.random includes an example that's almost what you need for #5 - generating a random integer between 0 and max - 1 . You should be able to adapt that to your requirement with a little basic arithmetic.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard, thank you very much for the reply.
The text does not mention anything about returns, that is why I wrote it as it is
So for the return value, do I insert inside the calling of the randomInt(); function or within its definition?
randomInt(); {
randomQ;
}
OR
function randomInt(lowest, size) {
size = Math.random(0-9)
lowest = Math.floor(size);
return randomQ;
}
Here is what I have so far:
randomInt(); {
return randomQ;
}
var quoteElem = document.getElementByTagName("quote")[0];
var randomQ;
function randomInt(lowest, size) {
size = Math.floor(Math.random() * 10);
lowest = ???;
}
document.getElementById("quoteElem").innerHTML = getQuote(randomQ);
I am trying to figure out the lowest parameter of the randomInt function now. How will I set it up according to the instructions: "to specify the lowest possible value for the random integer" ???
**EDIT**
How about if I use the Math.min() function for the lowest parameter?
function randomInt(lowest, size) {
size = Math.floor(Math.random() * 10);
lowest = Math.floor(Math.min(size));
}
modified 9-Nov-18 12:15pm.
|
|
|
|
|
ghazabaz wrote: Use those two parameter values and the Math.floor() and Math.random() methods to return a random integer within the specified range.
ghazabaz wrote:
function randomInt(lowest, size) {
size = Math.floor(Math.random() * 10);
lowest = Math.floor(Math.min(size));
}
Again, that function isn't returning anything. And you're ignoring the parameters - you immediately overwrite size with a random value, and then overwrite lowest with the value of size .
Look at the demo on the MDN site[^] again:
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
Breaking that down a bit:
function getRandomInt(max) {
var number = Math.random();
var maxInt = Math.floor(max);
var numberInRange = number * maxInt;
var result = Math.floor(numberInRange);
return result;
}
That's almost exactly what you're trying to do. The difference is, you need to translate the random number to a range that's greater than or equal to Math.floor(lowest) , and less than (Math.floor(lowest) + Math.floor(size)) . You can use some fairly simple arithmetic to do that.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
plz drop the link as the response to guide me to learn javasript,,....that you know..
|
|
|
|
|
|
You didn't include any links ... nor have you attributed the source of these words
How to learn JavaScript in three months - Quora[^]
There is a zero-tolerance to plagiarism on this site so please ensure that you properly attribute the source of any information you post.
|
|
|
|
|
How many ways can you output loop information to the browser?
|
|
|
|
|
As many as you have loops.
|
|
|
|
|
prevent validation of the form if numbe1 <number 2
|
|
|
|
|
Your question itself is an answer, only written in pseudocode.
if(number1 < number2) {
} else {
} The number1 and number2 values you need to take care of, where they are coming from. Perhaps a document.getElementById("number1") , or something like that?
Document.getElementById() - Web APIs | MDN
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Hola!
es mi primer mensaje en el foro..no encontré subforo de jquery,pero espero que sea el sitio adecuado
Estoy desarrollando un proyecto con PHP en Zend Framework, y en una vista recojo los datos de nuevo cliente con el típico formulario.
hay que introducir (en textbox) 1º Comunidad y 2º Provincia..la idea es que si el usuario teclea "Galicia" en el siguiente textbox se muestren sus provincias...
el caso es que el primer autocomplete funciona, pero el segundo, no y no se que estoy haciendo mal, no me da error el debuger de Chrome, he probado en Firefox, y tampoco..agradecería algo de ayuda
Dejo un copy paste de codigo..gracias por anticipado
<html>
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<!--<link rel="stylesheet" href="/resources/demos/style.css">-->
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<script type="text/javascript">
$(document).ready(function(){
var comunidades=[
"Galicia",
"Asturias",
"Cantabria",
"Euskadi",
"Navarra",
"Cataluña",
"Comunidad Valenciana",
"Murcia",
"Andalucia",
"Canarias",
"Baleares"
];
var provingal=[
"La Coruña",
"Lugo",
"Orense",
"Pontevedra"
];
$("#comu").keyup(function(){
$(this).autocomplete({
source:comunidades
});
});
$("#provin").keyup(function(){
var comu=document.getElementById("comu").value;
switch(comu)
{
case"Galicia":
$(this).autocomplete({
source:provingal
});
break;
}
});
});
|
|
|
|
|
Es un sitio en ingles
This is an english site.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
The task
I work with Angular and Chart.js (just started working with both for the first time) and need to import a recordset into Chart.js to be displayed as a multi-axis line chart. At the moment I am displaying some dummy data for visualization which works flawless.
The recordset to be displayed is a record of statistical data stored in a local MS SQL database table. There are three columns that need to be displayed from the table in Chart.js.
1. ExeTimeStamp (in SQL server defined as the following style --> "ODBC canonical date and time with milliseconds." http://www.blackwasp.co.uk/sqldatetimeformats.aspx)
2. LogTimeStamp (same as above ExeTimeStamp style)
3. TaskResult (in SQL server defined as a String, holds thousands of recordsets, each containing 15 pairs of "value" and "label" data)
The challenge
By means of the following tutorial (http://www.tutorialsteacher.com/nodejs/access-sql-server-in-nodejs) I was able to connect to the database and to retrieve the data for all three columns to be displayed in Chrome which results in the following JSON output...
{"recordsets":[[
[{
"ExeTimeStamp":"2018-08-11T08:06:47",
"LogTimeStamp":"2018-08-11T08:07:29",
"TaskResult":[
{"value":"1452","label":"Google readings"},
{"value":"1618","label":"Navigate to 'log on' page"},
{"value":"5467","label":"Log in"},
{"value":"2420","label":"Find user"},
{"value":"1500","label":"Click on 'active cases'"},
{"value":"3084","label":"Click on case"},
{"value":"1350","label":"Click on 'documents'"},
{"value":"652","label":"Click on download PDF icon"},
{"value":"5008","label":"Log in via login client"},
{"value":"1","label":"Wait for down-load/check for PDF in PDF viewer"},
{"value":"1299","label":"Click on extended search"},
{"value":"1267","label":"Input search term"},
{"value":"5004","label":"Execute search},
{"value":"1696","label":"Log out"},
{"value":"30366","label":"Total without google readings"
}]
//...remaining recordsets...
}]],"output":{},"rowsAffected":[20461]}
This data now needs to be mapped to Chart.js so it is possible to read the data into the chart display itself.
Having looked at other suggestions, my approach would be to create a new typescript class looking somewhat like this...
export class livelogs implements OnInit {
constructor() { }
ngOnInit() {
}
exetimestamp: Date;
logtimestamp: Date;
taskresult: string[];
}
...in order to make data available for reading by Chart.js from that class.
However each recordset with the 15 pairs of "value","label" data in TaskResult needs to be accessed one pair at a time and mapped individually to Chart.js so each line (and intersecting point) in the chart gets its own value and label.
Therefore, I am in doubt as to whether my approach is the right one, nor if or how it could be actually made to work.
Can anyone point me into the right direction here?
Thanks in advance for any input.
The chart type from Chart.js which I am using now can be seen here...
http://www.chartjs.org/samples/latest/charts/line/multi-axis.html
Note: If someone might wonder why TaskResult wasn't/isn't separated rather into multiple columns, holding each one pair - as it would be a better solution to the problem - I agree, but have already asked the responsible about this option. Since the statistical information in the future will have to be accessed by many users by means of a customized search option, plus that the same information needs to refresh other more specific graphs at a fixed time-interval, the reasoning is that the server would be taxed to hard with constant requests if more columns had to be accessed and the load therefore too high, which makes this possibility a no-go.
|
|
|
|
|
Hi everybody
When I try to open my website (URL)/login.aspx in chrome, it switches in the bar to (URL)/login and goes to "HTTP Error 404.0 - Not Found" page.
but in IE, it works fine.
any idea about this problem
|
|
|
|
|
i learn test regexp,I want it if the value is correct show "learning javascript" but if the value is wrong then show "learning"
the value is always false
this code
{
var data1 =/learning+\s+html+/g.test(data1)
if (data1==true) {
console.log("learning javascript");
}else {
console.log("learning");
}
}
panggilRegexp("learning javascript")
any solution?
|
|
|
|
|
Alboyz wrote: var data1 =/learning+\s+html+/g.test(data1)
You're trying to use the variable data1 before it has any value assigned to it.
Your regular expression is also slightly off: the + means the previous element can be repeated one or more times, so you'll match "learninggggg". You're also testing for "html" instead of "javascript".
You'll probably was a case-insensitive regex, so that you match "JavaScript" or "Javascript" as well as "javascript".
Assuming you've missed the first line of your function:
function panggilRegexp(input) {
var isMatch = /learning\s+javascript/gi.test(input);
if (isMatch) {
console.log("learning javascript");
}
else {
console.log("learning");
}
}
panggilRegexp("Are you learning JavaScript yet?");
Regular Expressions - JavaScript | MDN[^]
JavaScript RegExp Reference[^]
Regex testing tool[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
|
Hi,
I have a big problem with JS.
I would like to add to my dropzona component a list of files on the server.
I have this code:
<pre lang="Javascript"><div class="row">
<div class="col-12">
<form class="dropzone" id="dpz-multiple-files" action="http://localhost/dropZoneUpload.php"
method="post" enctype="multipart/form-data" style="border:1px solid #000;">
</form>
<br>
<center>
<button id="submit-all" style="height: 40px;"> Upload All the files</button>
</center>
</div>
</div>
function getValueFromJson() {
let res = $.ajax({
url: 'http://localhost/dropZoneUpload.php?parm=1',
type: 'get',
dataType: 'json',
success: function (response) {
return response;
}
})
return res;
}
The php file returns the result:
[{"name":"index.html","size" ,"path":"..\/assets\/uploads\/index.html"},{"name":".DS_Store","size":8196,"path":"..\/assets\/uploads\/.DS_Store"},{"name":"q1.jpg","size":433382,"path":"..\/assets\/uploads\/q1.jpg"},{"name":"bla.jpg","size":193540,"path":"..\/assets\/uploads\/bla.jpg"},{"name":".htaccess","size":106,"path":"..\/assets\/uploads\/.htaccess"}]
In this way I define the truncated JS:
Dropzone.options.dpzMultipleFiles = {
uploadMultiple: true,
paramName: "file",
maxFilesize: 100,
maxFiles: 2,
createImageThumbnails: true,
acceptedFiles: ".png,.jpg,.jpeg",
clickable: true,
thumbnailWidth: 150,
thumbnailHeight: 150,
autoProcessQueue: false,
init: function () {
var submitButton = document.querySelector("#submit-all")
dpzMultipleFiles = this;
submitButton.addEventListener("click", function () {
dpzMultipleFiles.processQueue();
});
this.on('completemultiple', function (file, json) {
$('.sortable').sortable('enable');
});
this.on('success', function (file, json) {
let val = file.accepted;
if (file.accepted == true) {
console.log(json);
$('.main_form').append("<input type='text' name='imgFiles[]' value='" + file.name + "'/>");
}
let val1 = file.name;
});
this.on("addedfile", function (file) {
var removeButton = Dropzone.createElement("<button> Remove file </button>");
var _this = this;
removeButton.addEventListener("click", function (e) {
e.preventDefault();
e.stopPropagation();
_this.removeFile(file);
console.log("kasuje" + file.name);
console.log(file);
});
file.previewElement.appendChild(removeButton);
});
this.on('drop', function (file) {
console.log('File', file);
alert('bb');
});
this.on("maxfilesexceeded", function (file) {
this.removeFile(file);
});
}
};
$(function () {
$(".dropzone").sortable({
items: '.dz-preview',
cursor: 'move',
opacity: 0.5,
containment: '.dropzone',
distance: 20,
tolerance: 'pointer'
});
});
How can I display a list of my files in DropZoneJS (downloaded from PHP)?
I found an example on the Internet:
$(".dropzone").dropzone({
init: function() {
myDropzone = this;
$.ajax({
url: 'upload.php',
type: 'post',
data: {request: 2},
dataType: 'json',
success: function(response){
$.each(response, function(key,value) {
var mockFile = { name: value.name, size: value.size };
myDropzone.emit("addedfile", mockFile);
myDropzone.emit("thumbnail", mockFile, value.path);
myDropzone.emit("complete", mockFile);
});
}
});
}
});
But I do not know how to adapt it in my code.
Can I ask for help?
Does anyone know how to do it?
|
|
|
|
|
i have content page of master page i placed date picker for text when i run visual studio style worked but when i run from IIS style not working
how to slove that
|
|
|
|
|