|
I never wanted the code for the project. Sorry if I was not specific! Accept my sincere apologies for using the wrong forum as well.
modified 4-Feb-21 13:00pm.
|
|
|
|
|
1) We're happy to help if you have specific questions about code you have written, but nobody here is going to do your assignment for you.
2) Nobody is going to visit a link on a dodgy website to see the details of your question. Either post the question details here, or don't post at all.
3) It's not "urgent" to anyone but you. All you're doing by adding "urgent" to your subject line is telling us that you can't manage your own time.
4) You have posted this in the Javascript forum. Despite the similar names, Java and JavaScript are two completely different languages.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Chrome wont autoplay a video embedded with javascript, unless its muted. But i cant figure out how to use code to unmute it.
problem is that i am repurposing code [listed below, and in link]. it embeds video in an iframe. there is no variable to access the mute of that i can see. thus the vid variable below doesn work.
The whole code is at https://codepen.io/richardengle/pen/poNjvpY
Line 33 of the area of JS code is where i would change. you can see the vid muted/unmuted part, but it wont unmute the video. Any advice is welcomed
----- part of code----
$('button#play20s').click( function() {
$('body').removeClass().addClass('on playing20s');
$("#knob").trigger('play');
$("#tune").trigger('play');
$('.video-embed').remove();
$('body').append('<iframe id="decade-20" class="video-embed" width="560" height="315" src="https://www.youtube.com/embed/gTevoUhDeoM?&theme=dark&autoplay=1&keyboard=1&autohide=2&start=10&mute=1" frameborder="0" allowfullscreen ></iframe>');
var vid = document.getElementById("decade-20");
vid.muted =false;
//https://www.youtube.com/embed/gTevoUhDe
|
|
|
|
|
You can't. That's the whole point - the video can only be un-muted if the user interacts with it.
If there was any way to circumvent that, then every dodgy site in the world would have auto-playing un-muted videos shouting their scam messages as soon as you loaded the page.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am working on an Ember application, I have a following JavaScript Code written to limit the entry of digits after decimal, this function is called in Key-Down event. Its working but what it is doing it, it allowing 3 digits after decimal but when I am posting its value on the Service, that is taking correctly 2 digits after decimal but what it is showing in the Textbox is 3 digits after decimal.
And another request if possible is, can I do the same without using id attribute on the Textbox.
Any help please, thanks in advance.
allowOnly2Decimals: function (e1, event) {
var boxId = '#' + event.path[0].id;
if ((event.keyCode == 190) || (event.keyCode == 110)) {
this.decimalPressed = true;
}
if (this.decimalPressed) {
var t = e1.toString().split('.');
if (t[1] != null) {
if (t[1].length == 2) {
this.limitDecimal = e1;
$(boxId).val(e1);
}
if (t[1].length >= 2) {
e1 = this.limitDecimal;
$(boxId).val(e1);
return false;
}
}
}
}
|
|
|
|
|
No need to use Javascript:
<input type="number" scale="0.01" /> Or:
<input type="text" pattern="^\d+(\.\d{0,2})?$" />
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
But it didn't work Here is what I have put
${{input type="number" id=p.ViolationTypeId value=p.PenaltyAssessed maxlength="5" scale="0.01" pattern="^\d+(\.\d{0,2})?$" focusOut=(action 'saveTotalPenalty' p model.id p.PenaltyAssessed)}}
I tried both individually and by putting both, still it didn't work, is Ember different, I don't know.
|
|
|
|
|
I am not sure, if I could solve this problem within the Javascript code.
As you can see from the example below, I have a @ model which contains data.
In order to use particular parts of the data, I have assigned it to a Json object by using Json.Serialize .The reason I have done so, is that the events:[ ] section accepts data in some specific format, looking like a json kind of format.
As you can see in the events:[ ] section, I have tried to extract data in such a way so that the events:[ ] part of the program accepts it. (and everything works fine like that)
Problem is that, the number of records in json can vary as it pulls data from a database table.
Desired outcome is: A better formulation to introduce neccessary data in the events:[ ] section.
I would be very happy If you could suggest something about it. Thank you.
@ model IEnumerable<WebAppV2.Models.CalendarEvent>
<script>
document.addEventListener('DOMContentLoaded', function () {
var calendarEl = document.getElementById('calendar');
var json = @ Html.Raw(Json.Serialize(@ Model));
var calendar = new FullCalendar.Calendar(calendarEl, {
initialDate: '2021-01-01',
editable: false,
selectable: false,
businessHours: true,
dayMaxEvents: true,
events: [
{
title: json[0].title,
start: json[0].start,
end: json[0].end
},
{
title: json[1].title,
start: json[1].start,
end: json[1].end
},
{
title: json[2].title,
start: json[2].start,
end: json[2].end
},
]
});
calendar.render();
});
</script>
|
|
|
|
|
Try:
var events = @Html.Raw(Json.Serialize(Model.Select(e => new
{
e.title,
e.start,
e.end
})));
var calendar = new FullCalendar.Calendar(calendarEl, {
initialDate: '2021-01-01',
editable: false,
selectable: false,
businessHours: true,
dayMaxEvents: true,
events: events
});
calendar.render();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 29-Jan-21 8:08am.
|
|
|
|
|
It worked! Thank you.
var events = @Html.Raw(Json.Serialize(@Model.Select(e => new <-------------- @ added in front of Model
{
e.title,
e.start,
e.end
}))); <------- two more closing brackets on this line.
|
|
|
|
|
This project is a port of rails scaffold generate for React. You can learn more about Rail's scaffold generator here. I mainly used it for its MVC (model, view, controller) generator. It abstracted CRUD operations, form generation, form validation, list-detail presentation pages, database migrations, SQL queries through ActiveRecord, and styling all with one command.
This project leverages file templating, dynamic form generation, routing and CRUD state management to apply those concepts to React and supercharge any project by skipping lots of boilerplate setup. Create an entire app in one command.
Check out the full details of the project[[GitHub - DrewWeth/react-scaffold-generate: Scaffold generator for React projects](https://github.com/DrewWeth/react-scaffold-generate)]
|
|
|
|
|
Not the right place to post this. If you want to publish your GitHub project on CodeProject, import it as a project:
Your GitHub Project on CodeProject[^]
NB: It will be subject to the same standards as other articles[^], so make sure your readme.md has enough information about the project first.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi CodeProject friends,
Probably my question is too broad, but what do you think is the best way to trace and solve
JavaScript conflicts?
Cheers,
modified 11-Jan-21 3:14am.
|
|
|
|
|
ReverseAds wrote: but what do you think is the best way to trace and solve JavaScript?
Your query is not clear. What do you mean by trace/solve JavaScript? JavaScript is not a problem to be solved.
If you are looking for JavaScript related code, you can debug it using editors or even browser developer console.
|
|
|
|
|
ReverseAds wrote: JavaScript conflicts? What do you mean by conflict?
|
|
|
|
|
Remove everything then put things back a bit at a time. When it stops working the last thing you added is responsible.
|
|
|
|
|
i have a javascript file which will do some specific requiredment but now i need to convert it into arrow function how to do it.
const characters = [
{ name: 'Jean-Luc Picard', age: 59 },
{ name: 'Will Riker', age: 29 },
{ name: 'Deanna Troi', age: 29 }
];
const result = characters.map(function (item)
{
const nameArray = item.name.split(" ")
return {
first_name: nameArray[0],
last_name: nameArray[1],
age: item.age < 30 ? 'young' : 'old'
}
})
console.log(result)
this is the actual code how to convert it into arrow function
|
|
|
|
|
Simple:
const characters = [
{ name: 'Jean-Luc Picard', age: 59 },
{ name: 'Will Riker', age: 29 },
{ name: 'Deanna Troi', age: 29 }
];
const result = characters.map((item) =>
{
const nameArray = item.name.split(" ")
return {
first_name: nameArray[0],
last_name: nameArray[1],
age: item.age < 30 ? 'young' : 'old'
}
})
console.log(result)
The structure of
function (params) {
}
becomes
(params) => {
}
There are some other rules that allow you to avoid parenthesis, etc. For that please see MDN documentation for this: Arrow function expressions - JavaScript | 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 !~
|
|
|
|
|
You could also use array destructuring when splitting the name:
const [first_name, last_name] = item.name.split(" ");
return {
first_name,
last_name,
age: item.age < 30 ? "young" : "old"
}; Destructuring assignment - JavaScript | MDN[^]
Demo[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello we do develop a quiz
also have code but we want just quiz check which user click on mcq answer
function Quiz(questions) {
this.score = 0;
this.questions = questions;
this.questionIndex = 0;
}
Quiz.prototype.getQuestionIndex = function() {
return this.questions[this.questionIndex];
}
Quiz.prototype.guess = function(answer) {
if(this.getQuestionIndex().isCorrectAnswer(answer)) {
this.score++;
}
this.questionIndex++;
}
Quiz.prototype.isEnded = function() {
return this.questionIndex === this.questions.length;
}
function Question(text, choices, answer) {
this.text = text;
this.choices = choices;
this.answer = answer;
}
Question.prototype.isCorrectAnswer = function(choice) {
return this.answer === choice;
}
function populate() {
if(quiz.isEnded()) {
showScores();
}
else {
var element = document.getElementById("question");
element.innerHTML = quiz.getQuestionIndex().text;
var choices = quiz.getQuestionIndex().choices;
for(var i = 0; i < choices.length; i++) {
var element = document.getElementById("choice" + i);
element.innerHTML = choices[i];
guess("btn" + i, choices[i]);
}
showProgress();
}
};
function guess(id, guess) {
var button = document.getElementById(id);
button.onclick = function() {
quiz.guess(guess);
populate();
}
};
function showProgress() {
var currentQuestionNumber = quiz.questionIndex + 1;
var element = document.getElementById("progress");
element.innerHTML = "Question " + currentQuestionNumber + " of " + quiz.questions.length;
};
function showScores() {
var gameOverHTML = "<h1>Result</h1>";
gameOverHTML += "<h2 id='score'> Your scores: " + quiz.score + "</h2>";
var element = document.getElementById("quiz");
element.innerHTML = gameOverHTML;
};
var questions = [
new Question("शरीर से पसीना सबसे अधिक कब निकलता है", ["जब तापक्रम अधिक और हवा सुख हो", "जब तापक्रम अधिक और हवा आर्द्र हो","जब तापक्रम कम और हवा आर्द्र हो", "जब तापक्रम कम और हवा सुखी हो"], "जब तापक्रम अधिक और हवा आर्द्र हो"),
new Question("Which language is used for styling web pages?", ["HTML", "JQuery", "CSS", "XML"], "CSS"),
new Question("Which is not a JavaScript Framework?", ["Python Script", "JQuery","Django", "NodeJS"], "Django"),
new Question("Which is used for Connect To Database?", ["PHP", "HTML", "JS", "All"], "PHP"),
new Question("Webdevtrick.com is about..", ["Web Design", "Graphic Design", "SEO & Development", "All"], "All")
];
var quiz = new Quiz(questions);
populate();</pre>
modified 5-Jan-21 11:51am.
|
|
|
|
|
Quote: which user That needs you to know which user opened the form, which needs you to handle this request from a web server and authenticate the users before showing the form to them.
That answer requests a server-side answer, and it depends on which language/framework you are using to build that.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
This is part of the old PHP 4.7 App that I'm working on. The last time somebody worked on it was back in 2008, so there is a lot of old outdated stuff in it. One of them is this eval() function.
I read up on it, but I'm still kind of fuzzy on the point of it. If I understand correct, it evaluates the notion of an equation, or string, and returns the outcome if it can be done, or undefined if it can't be done. And then the Mozilla documentation said "Don't use it", and offered work around solutions such as using a function instead.
Looking at this block of JavaScript, I'm having trouble with understanding why it was written this way, and coming up with a rewrite.
So like on Ref 1, it must be a select option element, and it getting the value.
I would think document.getElementByID('document.step2.' + txt + '.value') would be a good replacement, and then check if the element is undefined.
And Ref 2 is thew same thing.
Mozilla says this, in which I get, but confuses me because my eval() is being used different.
I just need help in understanding, and if I am interpreting this correct.
Wrong
function looseJsonParse(obj){
return eval("(" + obj + ")");
}
Right
function looseJsonParse(obj){
return Function('"use strict";return (' + obj + ')')();
}
function save(bkType, txt, id , dataType) {
let error = false;
let typeVar = eval('document.step2.' + txt + '.value');
let referenceId = '';
let refDetail = '';
let quantity = '';
const fPost = true;
if ('Q' == bkType) {
typeVar = 'document.step2.' + id + '\$quan' + '.value';
quantity = eval(typeVar);
}
else if ('TQ' == bkType) {
typeVar = 'document.step2.' + id + '\$quan' + '.value';
quantity = eval(typeVar);
typeVar = 'document.step2.' + id + '\$type' + '.value';
referenceId = eval(typeVar);
if ('quan' != data_type) {
var typeOptions = eval('document.step2.' + txt + '.options');
FilterInactivePart(typeOptions);
}
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
There is a much easier way than using eval for your particular example. The w.x.y.z syntax in Javascript can be rewritten as w['x']['y']['z'] instead.
So instead of
var typeOptions = eval('document.step2.' + txt + '.options');
you can use
var typeOptions = document.step2[txt].options;
|
|
|
|
|
That was going to be my next question.
I got that error about missing name after dot operator, and tried working with dots.
So I started working on it, but didn't get it to work right. Then I realized that the original author just wanted to make sure that the right select element was chosen, so I sent "this" to the function.
From this:
<select id='$sel_cat_name' name='$sel_cat_name' onchange='return check_supplier($sel_cat_name)'>
To this:
<select id='$sel_cat_name' name='$sel_cat_name' onchange='return check_supplier(this, $sel_cat_name)'>
And adjusted the function
From this:
function check_supplier(opType) {
const form_ele_name = "document.form2." + op_type + ".selectedIndex";
let tmp_sel_index = eval(form_ele_name);
const form_sel_name = "document.form2."+op_type+".options["+tmp_sel_index+"].text";
let sel_ven_name = eval(form_sel_name);
To This:
function check_supplier(sourceElement, opType) {
const tempSelectIndex = sourceElement.selectedIndex;
const formSelectName = sourceElement.options[tempSelectIndex].text;
let selectVendorName = eval(formSelectName);
I don't know, guess it could be re imagined several different ways. But your help is of great value to quickly fix this.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Hi!
This is an example of code.
Simply not able to understand what it does. How can I check some kind of result in the console?
Thank you in advance if sy tell me.
timeFuncRuntime(() => {
for (let i = 10; i>0; i--){
console.log(i);
}
});
The explanation from lecture:
In this example, we invoked timeFuncRuntime() with an anonymous function that counts backwards from 10. Anonymous functions can be arguments too!
|
|
|
|
|