I have taken 1 textbox, 1 button and 1 alert image in my asp.net page. And I have written JavaScript function and call it in onblur and onclick event of text box. The function of onblur is that if the textbox is empty then the alert picture will show else picture will hide. And in onclick picture will hide. And another JavaScript function I also used to hide the picture when I open the page first time. I call this in pageload of aspx.cs page
Same things I want to do in my button Onclientclick event but it is not working because when I clicked on button the page is loaded.
How to solve this problem?
Your button click is causing postback. The simple way without seeing your code, at the end of javascript function that onclick is invoking, before the closing bracket - return false.
From the code you shared, do return false after alert();
Related
I have a very complex website and I know that somewhere is an alert() with a description. Is there a way to set a breakpoint on the alert() call? The HTML is generated, so I cannot just grep for the message.
You can use the console to replace the alert function:
window.alert = function() { debugger; };
Firebug's Script panel allows you to search for code throughout all your JavaScript sources.
So you can simply search for alert( or search for the message that the alert box shows and set a breakpoint on the line where it's called.
Another way is to use the Break On Next button ( ) to stop at the next JavaScript statement that gets executed. So, click the button and then do the action that causes the alert box to be displaced.
Note: This only works if there are no other event handlers called before the event showing the alert box.
Every time I press a button, there is a random chance that a alertify alert window popups. The alertify alert popup is something I use instead of javascript Alert, just to get a nicer design.
Alertify library
And here is a screenshot of the current situation:
I want to assign a event to the OK button. When I use the "inspect element" function in google chrome, I see that this green OK button has an id called "alertify-ok", so I want to assign an event when this button is pressed.
I've tried to add this part to my HTML document in the script part:
$( "#alertify-ok" ).on( "click",function() {alert("finally");});
But nothing happens. The reason why I need this to work, is that the youtube popupmodal should come up right after I've pressed the OK button. I belive the error comes because the alertify window with HTML is from an external library, so how can i do this?
Alerts and the others take callback functions on creation, https://github.com/alertifyjs/alertify.js/blob/0.3.12/src/js/alertify.js#L608. You don't need to attach another event listener, just give it the function you want it to execute. example below:
alertify.alert("alerttext", function(e) {
functionIWantToCall();
});
You can put the event on an element you know is already existent (like "body") and specify it to trigger only when the wanted element is clicked:
$(" body").on({
click: function () {...
}
}, "#trigger");
When a link is clicked on my site the Javascript code below is executed, if the condition is true it will display an alert dialog. When the user selects the OK button in the alert dialog the block of code is executed again.
So the alert closes, the code below is executed for a second time and the alert dialog is displayed again. When the used selects the OK button on the alert dialog the second time the alert dialog is closed for good.
How can I prevent the code below being executed twice?
$("#my-button").click(function() {
var login = someVar;
if(!someVar || someVar == ''){
$('.close-reveal-modal').click();
alert(myMessage);
}
});
Check if you are adding the click handler twice, maybe that is what is causing that behavior.
In that case remove one of them.
From the very limited information that's provided, this is all that I can think of as going wrong:
$('.close-reveal-modal').click();
This piece of code should have some kind of function which is executed to display a similar Alert Box.
A complete code would be more useful for a complete answer!
Might not have anything to do with that code at all. Check to make sure that your javascript file isn't being called twice in the same app.
From what we have here, I'm guessing that your .close-reveal-modal element is in #my-button (or is the same html node).
When you trigger the click on it (by $('.close-reveal-modal').click();), it also trigger the click on its parent node, so on #my-button too.
I can be wrong, we need the HTML part (a fiddle would be great) to validate my theory.
I have a single HTML page which has several div class. In second div class I have a registration form. When I click on submit button and check validation and give pop up, after clicking on the pop up it redirect on home div, and I want the registration div class to stay the same after clicking on the pop up button. How can I do this?
if you are using href to get click and call js method. You have to prevent default behavior. It may solve your prob even you don't use href.
function(e){
e.preventDefault();
// your code.
return false;
}
It sounds like the href value for your link is #
You could add
return false;
as the last line of the function bound to the click event
how run one javascript function for diffrent element with one ASP.Net button click ?
for example if you want to run another button's click event function you can call document.getElementById('myButton').click();
but remember, if click function of that button is doing postback, you need to prevent it. because that calling that function will avoid the code from continuing.