if ($("#Switch").is(":checked") == true)
{
alert("checked");
}
else
{
alert(" Not checked");
}
This code is giving me the alert "checked" first time after changing the switch state from OFF to ON. And after i am changing the state to OFF again but it is showing only alert "checked".
Please help me, I am using this code in button click event. Every time I am getting only checked.
function getChecked(elementId)
{
if ($("#elementId").is(":checked") == true)
{
alert("checked");
}
else
{
alert(" Not checked");
}
}
onchange="getChecked('#id')"
put this code inside your js onchange event
var checked = $(this).prop('checked');
if(checked) {
alert('checked');
} else {
alert('not checked');
}
Related
I keep having an issue with returning a redirect from the load method in sveltekit. I'm ready to quit. So this simple little redirect doesn't see to work for me in __layout.svelte
export async function load() {
let user = false
if (!user) {
return {
status: 301,
redirect: '/login'
}
} else {
return {}
}
}
And I get the screenshot below. Nothing I do seems to work with redirects. Any suggestions as to why I can't seem to get this simple thing to work.
Solved the problem. Because it's __layout.svelte the code needed a check for the url.pathname otherwise it seems to act like a loop.
The solution:
export async function load({ url }) {
let user = false
if (!user && !url.pathname.includes('/login')) {
return {
status: 301,
redirect: '/login'
}
} else if (user && url.pathname.includes('/login')){
return {
status: 301,
redirect: '/'
}
} else {
return {}
}
}
I have a mobile app where the user needs to re-login after some time for security reasons. The thing is that the content that was open in the background needs to stay there, and open after the login. So, even if it was a modal.
What is the best way to do this.
Pushing the login view when a modal is open doesn't help, since the view is put behind the modal.
Thanks in advance!
on the current page
public openLogin() {
let loginModal = this.modalController.create(LoginPage, { modal: true });
loginModal.present();
loginModal.onDidDismiss(data => {
if (data) {
this.profileData = data;
} else {
}
});
};
on loginPage
this.userService.login(username, password)
.subscribe(
data => {
console.log(data);
if (data.success) {
var user = data.result;
this.userService.setSession(user);
if (this.itsModal) {
this.closeModal(data)
}
else {
this.gotoHome();
}
} else {
// error handling
}
},
error => {
console.log(error);
}
);
public closeModal(data: any = null) {
this.viewController.dismiss(data);
}
I'm working out on the ionic project. I need to get the items based on current district. To get the current district I tried the below.
cordova.plugins.diagnostic.isLocationEnabled(function(enabled) {
alert("Location is " + (enabled ? "enabled" : "disabled"));
if(!enabled)
cordova.plugins.diagnostic.switchToLocationSettings();
var geocoder = new google.maps.Geocoder();
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
}
function successFunction(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
}
function errorFunction(){
$ionicPopup.alert({
title:"Alert",
content:"Geocoder failed"
});
}
function codeLatLng(lat, lng) {
geocoder.geocode({'latLng': new google.maps.LatLng(lat, lng)}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
for (var i=0; i<results[0].address_components.length; i++) {
for (var b=0;b<results[0].address_components[i].types.length;b++) {
if (results[0].address_components[i].types[b] == "administrative_area_level_2") {
district= results[0].address_components[i];
}
}
}
alert(distrcit.long_name);
}
else {
alert("No results");
}
}
else {
alert("Geocoder Failed");
}
});
}
}, function(error) {
});
This code is working fine if the GPS is enabled after switching to location settings. I'm getting the problem when the GPS is not enabled and getting back into the app. How can I detect whether it is enabled or not after moving to location settings and getting back to the app? Even though I referred many posts in StackOverflow, I didn't get the solution what I needed actually. So please help me out in solving it.
How can I detect whether it is enabled or not after moving to location settings and getting back to the app?
You can detect when your app is returned to the foreground using the resume event.
function onResume() {
cordova.plugins.diagnostic.isLocationEnabled(function(enabled) {
console.log("Location is " + (enabled ? "enabled" : "disabled"));
// etc.
}, function(error) {});
}
document.addEventListener("resume", onResume, false);
My code:
this.condition = function() {
element(by.partialLinkText('Times Jobs')).isDisplayed().then(function (result) {
if (result) {
element(by.partialLinkText('Times Jobs')).click();
} else {
console.log('Times source not found')
}
});
}
If "Times Jobs" is not presented in the page then it should display whatever text inside the else statement. How can i do that?
I don't want to make test fail, just i need to print that text in console.
You can use isPresent(), as in this answer, but if you want to keep using isDisplayed(), you must handle the case of the element not being found in the error callback of its returned promise:
element(by.partialLinkText('Times Jobs')).isDisplayed().then(function (result) {
if (result) {
element(by.partialLinkText('Times Jobs')).click();
} else {
console.log('Times source in page but not displayed');
}
}, function() {
console.log('Times source not in page');
});
Or, if you want to output the same message in both of the cases of not being
in the page, or being in the page but not displayed, you can...
element(by.partialLinkText('Times Jobs')).isDisplayed().then(function (result) {
if (result) {
element(by.partialLinkText('Times Jobs')).click();
} else {
return protractor.promise.rejected();
}
}).catch(function() {
console.log('Times source not in page or in page and not displayed');
});
You can try this ::
this.condition = function() {
element(by.partialLinkText('Times Jobs')).isPresent().then(function (result) {
if (result) {
element(by.partialLinkText('Times Jobs')).click();
} else {
console.log('Times source not found')
}
});
}
as if the element is not present on the page than it give element not found error
I am trying to validate my form and make it writeToFile when submitted (.txt file) but I can't seem to get it right, searched Google for help but still nothing happens when submit button clicked.
Name:
Business:
Telephone:
Comment:
The Script I tried:
function validateForm()
{
var x=document.forms["commentform"]["fname"]["fcomment"].value;
if (x==null || x=="")
{
alert("You must enter a Name and Comment");
return false;
}
}
if( document.commentform.fname.value == "" )
{
alert("You must enter a Name");
return false;
}
if( document.commentform.fcomment.value == "" )
{
alert("You must enter a Comment");
return false;
}