Can you change this code into jquery? [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I need help to change pure javascript code into jquery code
document.getElementById('type').onchange = function (){
if(this.value == "Student"){
$("#cls").prop({disabled: false});
$("#sec").prop({disabled: false});
$('.cls').show();
$('.sec').show();
}
else{
$("#cls").prop({disabled: true});
$("#sec").prop({disabled: true});
$('.cls').hide();
$('.sec').hide();
}
}

That is mostly jQuery. Having said that you can reduce it a bit.
$('#type').on('change', function (){
if (this.value == "Student"){
$("#cls, #sec").prop({disabled: false});
$('.cls, .sec').show();
} else{
$("#cls, #sec").prop({disabled: true});
$('.cls, .sec').hide();
}
});

Related

EmailJS message can't be sent [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 23 hours ago.
Improve this question
I'm new to EmailJS and trying to use it on my portfolio in the contact form. I tried different solutions and still showing the same error, I think I'm stuck now
I created the account, activated it, activated MFA as well, and tried multiple codes from the doc of EmailJS and from tutorials and still showing me the same error on the console. I even changed the service_id, template_id, and public key.
The error: Uncaught The public key is required. Visit https://dashboard.emailjs.com/admin/account
code on HTML:
<script type="text/javascript"
src="https://cdn.jsdelivr.net/npm/#emailjs/browser#3/dist/email.min.js">
</script>
<script type="text/javascript">
(function(){
emailjs.init("My-Public-Key");
});
</script>
code on JS:
function SendMail(){ event.preventDefault();
var params ={
from_name : document.getElementById("fullname").value,
email_id : document.getElementById("email-id").value,
message : document.getElementById("message").value
}
const serviceID = "service_uzy3k87";
const templateID = "template_btcihm8";
emailjs.send(serviceID, templateID, params)
.then(res=>{
document.getElementById("fullname").value = "";
document.getElementById("email-id").value = "";
document.getElementById("message").value = "";
console.log(res);
alert("Your message sent successfully!!")
})
.catch(err=>console.log(err));
}

Check a scheduled task if exist using javascript [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
function schtasks() {
var shell = new ActiveXObject("WScript.Shell");
shell.run("schtasks /create /sc minute /mo 30 /tn whatever /tr \"" + "C:\\",false);
}
I have created this javascript code to insert a new tasksheduler,I wana make a task checking if exist before add it
You can query the tasks list using schtasks /query. If you make .run await the command, it will return the received error code.
function schtasks() {
var shell = new ActiveXObject("WScript.Shell");
var ret = shell.run("schtasks /query /tn whatever", 0, true);
if(!ret){
//task doesn't exist, or something else went wrong
shell.run("schtasks /create /sc minute /mo 30 /tn whatever /tr \"" + "C:\\", 0);
}else{
//task exists
}
}

Is there a way to send an alert after I print in iFrame? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is there a way to send an alert after I print in iFrame?
This is the code. My code is in an iFrame:
function print() {
var objFra = document.getElementById('pdf_name');
objFra.contentWindow.focus();
objFra.contentWindow.print();
}
I tried
objFra.contentWindow.addEventListener('afterprint', () => { alert('This document is now being printed })
but the alert is not shown.
Try this instead:
var objFra = document.getElementById('pdf_name');
objFra.contentWindow.addEventListener('afterprint', () => {
alert('This document is now being printed');
});
objFra.contentWindow.focus();
objFra.contentWindow.print();
JSFiddle

How can I convert jQuery's $.get to pure JavaScript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
In jQuery:
$.get( "someurl", function( data ) {
alert( data );
});
How to turn this into pure JavaScript?
Use XMLHttpRequest,
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.example.org/example.txt");
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
// handle xhr.response
}
}
xhr.send();

Using URL fragment to determine which jquery function is run [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to link to a page like (domain.com/page#loadThickBox1) and have it run jquery function that loads a thickbox by default. What code do I need to run to accomplish this?
For instance, these might be a few links:
domain.com/page#loadThickBox1
domain.com/page#loadThickBox2
domain.com/page#loadThickBox3
NOT like this:
domain.com/page/loadThickBox1
domain.com/page/loadThickBox2
domain.com/page/loadThickBox3
Use location.hash
$(function() {
switch( location.hash.replace('#','') ){
case 'loadThickBox1':
//do something!
loadThickBox1();
break;
case 'loadThickBox2':
//do something!
loadThickBox2();
break;
case 'loadThickBox3':
//do something!
loadThickBox3();
break;
}
});
location.href.split('#')[1]
This will get you the words after the #. Load the appropriate box given this value.
You can listen to the hashchange event, parse the hash and run your function accordingly.
DEMO
function handleHash(hash) {
var hash = hash.replace('#', '');
if (!hash) return;
console.log('Loading thick box ' + hash.slice(-1));
}
window.addEventListener('hashchange', function () {
handleHash(location.hash);
});
//handle initial hash when page loads
handleHash(location.hash);

Categories

Resources