disclose the alert button using javascript - javascript

In my project, I've added the alert box and try to close the box if the user clicks on disclose button. But I don't know why this if condition is not executed.
can anyone tells me where I did make a mistake?
window.onload = function(){
var button = document.querySelector(".close");
var successMessage = document.querySelector(".messageStackSuccess");
var messageStack = document.querySelector(".messageStackError");
// console.log(successMessage.className);
button.onclick = function () {
if (messageStack.className == "messageStackError") {
messageStack.classList.add("displayNone");
}
else if (successMessage.className == "messageStackSuccess") {
successMessage.classList.add("displayNone");
}
};
};

Related

Pop up removed completly from DOM

I have created the below function that uses bootstrapalert where a pop up comes up that holds random data from a database table. But after I trigger the event and close the window I need to refresh the page in order for it to work again. I don't seem to find the issue in the code that causes this problem. Any suggestions for improvement?
<script>
var alertList = document.querySelectorAll(".alert");
alertList.forEach(function (alert) {
new bootstrap.Alert(alert);
});
function randomName() {
if (
document.getElementById("randomNamePopUp").dataset.showned == "false"
) {
document.getElementById("randomNamePopUp").style.display = "block";
document.getElementById("randomNamePopUp").dataset.showned = "true";
} else {
//window.location.href=window.location.href+"?showRandom=true";
}
}
const urlParams1 = new URLSearchParams(window.location.search);
const myParam = urlParams1.get("showRandom");
if (myParam == "true") {
randomName();
}
</script>

JavaScript Follow / Unfollow Button

I would like to make a simple JavaScript program witch allow you to like and dislike.
So actually I am new in JavaScript it's a bit difficult me yet.
So when you click onto the Follow button it will increase the "countF" variable's amount with 1, and change the button text to "Unfollow".
So as I said it is a basic program.
So I don't know how to acually do it in reverse. I mean when the Unfollow button has clicked the "countF" should decrease with 1, and the button text should change back to "Follow".
Yeah I know it's simple too, but somehow I can't do it.
Any help or idea how to finish this?
var countF = 0;
var btnText = "Unfollow";
var countButton = document.getElementById("followButton");
var displayCount = document.getElementById("followers");
countButton.onclick = function() {
countF++;
followers.innerHTML = countF;
var countButton = document.getElementById("followButton");
countButton.innerHTML = btnText;
if(countButton.innerHTML = btnText) {
countF--;
countButton.innerHTML = "Follow";
}
}
<div id="followers">0</div>
<button id="followButton"></button>
Check this video out for a great tutorial on voting systems. https://www.youtube.com/watch?v=mBPURBO1kD8 Whenever you have voting you need to handle the voting with more than just the client side.
With that being said, maybe this concept would help:
let likedPost = false
function toggleVote() {
likedPost ? removeUpvote() : addUpvote()
likedPost = !likedPost
}
function removeUpvote() {
//code for removing
//probably should be a few calls to a server
}
function addUpvote() {
//code for adding
//probably should be a few calls to a server
}
Something like this would work:
var countF = 0;
var countButton = document.getElementById("followButton");
var displayCount = document.getElementById("followers");
countButton.onclick = function() {
if (countButton.innerText == "Follow") {
countF++;
countButton.innerText = "Unfollow";
} else if (countButton.innerText == "Unfollow") {
countF--;
countButton.innerText = "Follow";
}
followers.innerHTML = countF;
}
And add text to your button:
<button id="followButton">Follow</button>

Javascript onclick() show and onclick() hide

I wanted to make a function with onclick where if I press the div the content should be displayed. If I click on that content it will give me the "starting"-form.
Let me show you the code:
HTML:
<div id="demo">click</div>
Javascript:
var div = document.getElementById("demo");
var info = "This is the information for the user.";
var status = true;
if(status){
div.onclick = function() { div.innerHTML = info };
status=false;
}
else {
div.onclick = function() { div.innerHTML = "click" };
status=true;
}
So I made a variable status that checks what is being shown.
I hope i could express myself good enough. :)
The if statement is not going to magically run again. You need to do the check inside the click. Do not try to bind separate click events.
(function () {
var div = document.getElementById("demo");
var info = "This is the information for the user.";
var status = false;
div.addEventListener("click", function() {
status = !status;
div.innerHTML = status ? info : "click";
});
}());
<div id="demo">click</div>

jQuery confirm popping up multiple times

I'm having problems with this confirm box popping up multiple times. I only confirm after a certain button is pressed. If I only click on that button this should only ask once for that button but it's asking me once for every button of that class.
Any ideas why this is looping if I'm only firing this condition when a user clicks on a specific button?
$(".TweetNow").each(function () {
$(this).click(function TweetThis() {
var identify = $(this).attr('id');
var prestart = identify.indexOf('_');
var start = prestart + 1;
var end = identify.length;
var position = identify.substr(start, end);
var message = $("#Tweet_" + position).val();
var site = $("#SiteLabel").text();
if (message != '') {
var trend = $("#Topic_" + position).text();
var website = $("#SiteLabel").text();
if (confirm("Are you sure you want to tweet the following message:\n" + message + " ?")) {
PageMethods.TweetThis(message, site, trend, website);
location.reload();
}
}
});
});
Change your code as
$(".TweetNow").click(function() {
var identify = $(this).attr('id');
//Rest of code
});
Instead of
$(".TweetNow").each(function () {
$(this).click(function TweetThis() {
});
});

run javascript function from master page button

I have a javascript function on the child page that I need to run when the save button on the master page is clicked.
ValidateCheckList = function() {
var ErrorCodeU1001 = "U1001";
var ErrorCodeU1002 = "U1002";
var ErrorCodeU1003 = "U1003";
var errors = [];
$('<%= errorsHiddenField.ClientID %>').val("0");
var fingerprintsTaken = $('<%= FingerprintsTakenYesNo.PluginSelector %>').YesNoPlugin(YesNoMethodsEnum.IsYes);
if (!fingerprintsTaken) {
errors.push(ErrorCodeU1001);
}
var dnaTaken = $('<%= DNATakenYesNo.PluginSelector %>').YesNoPlugin(YesNoMethodsEnum.IsYes);
if (!dnaTaken) {
errors.push(ErrorCodeU1002);
}
var photographTaken = $('<%= PhotographTakenYesNo.PluginSelector %>').YesNoPlugin(YesNoMethodsEnum.IsYes);
if (!photographTaken) {
errors.push(ErrorCodeU1003);
}
if (errors.length > 0) {
('<%= errorsHiddenField.ClientID %>').val(errors.length.toString());
$(document).PageUtilPlugin(PageUtilMethodsEnum.DisplayUserNotificationMessage, { messageType: "Warning", message: errors });
}
}
I have tried -
$(document).ready(function() {
document.getElementById("ctl00_ctl00_ContentPlaceHolder1_SaveButton").onclick = ValidateCheckList;
but this doesn't work.
It also needs to do a postback.
Can anyone help?
thanks
try this
change you code like this
function ValidateCheckList ()
{
if(allvalidates)
return true;
else
return false;
}
on master page save button in page load
button.Attribute.Add("OnClick", "return ValidateCheckList ()");
what do you mean with the parent and child exactly ?
if you mean the pop-ed up window is the child window you can use this
childwindow = window.open("child.html", "Pop", "width=700,height=400, scrollbars=1");
childwindow.yourfunction();

Categories

Resources