<script language="JavaScript">
function del_rcd(param)
{
if(confirm("Do you really want to delete it"))
{
window.location = 'controller/del_task_ctl.php?param='+param;
}
}
</script>
<script language="javascript">
function popup(id)
{
window.open("detail.php?tid="+id, "Preview","width=600,height=500,scrollbars=yes");
}
</script>
<script language="javascript">
function popupcomp(id)
{
window.open("edit_task.php?tid="+id, "Preview","width=600,height=500,scrollbars=yes");
}
</script>
<script language="javascript">
function popupclose(id)
{
window.open("close.php?qid="+id, "Preview","width=600,height=500,scrollbars=yes");
}
</script>
Is JavaScript disabled in Firefox?
Just as a side-note. The "language" attribute is quite obsolete (See point 7). Instead write
<script type="text/javascript">
</script>
I just made this quick test under OSX Firefox and it just works:
<html>
<head>
<script type="text/javascript">
function del_rcd(param){
if(confirm("Do you really want to delete it"))
{
window.location = 'controller/del_task_ctl.php?param='+param;
}
}
function popup(id)
{
window.open("detail.php?tid="+id, "Preview","width=600,height=500,scrollbars=yes");
}
function popupcomp(id)
{
window.open("edit_task.php?tid="+id, "Preview","width=600,height=500,scrollbars=yes");
}
function popupclose(id)
{
window.open("close.php?qid="+id, "Preview","width=600,height=500,scrollbars=yes");
}
</script>
</head>
<body>
<input type="submit" Text="Click me" onclick="del_rcd('test')"/>
</body>
</html>
Additionally what I always recommend web devs is to install Firebug and optionally PageSpeed. This is a must especially when you deal with JavaScript. Firebug automatically shows you syntax or JavaScript runtime errors.
I am submitting a form to this script by calling these js function
but submit button only works in IE and on all other browsers Submit button is not working
Related
i am playing around with some new javascript functions to try to automatically click the button on a web page.
However, the click event of the button does not fire automatically. I have googled some code and it appears to be correct.
I am using IE browser 10
<html>
<head>
<script type = "text/javascript">
function haha1()
{
alert('haha1');
}
</script>
<script>
document.getElementById('haha').click();
</script>
</head>
<body>
<input type = "button" id = "haha" onClick = "haha1()" value = "lol"/>
</body>
</html>
You need to do it after the page loads. Basically your script executes before haha gets created so it doesn't show your alert.
<script type = "text/javascript">
function haha1()
{
alert('haha1');
}
function fire_haha() {
document.getElementById('haha').click();
}
</script>
</head>
<body onLoad="fire_haha()">
You have to wait for the DOM fully loaded before triggering the event and dccording to unobstrusive javascript. You should not embed javascript into html.
<html>
<head>
<script type = "text/javascript">
function haha1()
{
alert('haha1');
}
</script>
<script>
window.onload = function(){
document.getElementById('haha').onclick = function(){
haha1();
};
document.getElementById('haha').click();
}
</script>
</head>
<body>
<input type = "button" id = "haha" value = "lol"/>
</body>
</html>
Try this with jQuery
function fire_haha() {
$('#haha').trigger('click');
}
The code below is a simple abstraction of what I want to do - it deals with publish and subscribe of the dojo event model. My aim is to publish an event, and subscribe a method to that event.
<html>
<head>
<script>
dojoConfig={async:true, parseOnLoad: true}
</script>
<script type="text/javascript" src="dojo/dojo.js">
</script>
<script language="javascript" type="text/javascript">
require(["dojo/topic","dojo/domReady!"],
function(topic){
function somethod() {
alert("hello;");
}
try{
topic.publish("myEvent");
}
catch(e){
alert("error"+e);
}
//topic.publish("myEvent");
try{
topic.subscribe("myEvent", somethod);
}catch(e){alert("error in subscribe"+e);}
});
</script>
</head>
<body></body>
</html>
I get no alerts, not even in try and catch blocks. Developer console also shows no errors. Is this the correct way to handle publish and subscribe?
You're very close but have made one little mistake. You're subscribing to the topic after you're publishing to it, so you're not catching it. If you put the pub after the sub it'll work.
Here's your sample with slight modifications and comments:
<html>
<head>
<script>
dojoConfig={async:true, parseOnLoad: true}
</script>
<!-- I used the CDN for testing, but your local copy should work, too -->
<script data-dojo-config="async: 1"
src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js">
</script>
<script language="javascript" type="text/javascript">
require(["dojo/topic","dojo/domReady!"],
function(topic){
function somethod() {
alert("hello;");
}
try{
topic.publish("myEvent");
/* ignored because no one is subscribed yet */
}
catch(e){
alert("error"+e);
}
try{
topic.subscribe("myEvent", somethod);
/* now we're subscribed */
topic.publish("myEvent");
/* this one gets through because the subscription is now active*/
}catch(e){
alert("error in subscribe"+e);
}
});
</script>
</head>
<body></body>
</html>
I am using Twitter Bootstrap 2 and jQuery. I have simple HTML button as follows:
<button type="button" onclick="Redirect(1,'');" class="btn btn-danger">Cancel</button>
In the head section I have a javascript function as follows:
function Redirect(id, push) {
if (id == 1) {
if (push == 1) {
window.location.href('../dashjs/dashboardjs.aspx?pushchart=1');
}
else {
window.location.href('../dashjs/dashboardjs.aspx');
}
return false;
}
}
For some reason, the function Redicect is never called in CHROME. This seems to be working in IE.
Any ideas of what might be the issue here.
The following are loaded in the head section:
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script src="js/bootstrap-modal.js"></script>
<script src="../Content/bootstrap-button.js"></script>
any help will be much appreciated.
window.location.href actually isn't a method.
Try:
window.location.href = '../dashjs/dashboardjs.aspx?pushchart=1';
http://www.w3schools.com/jsref/prop_loc_href.asp
<script type="text/javascript">
function Redirect(id, push) {
if (id == 1) {
window.location.href = 'http://www.google.com';
} else {
window.location.href = 'http://www.yahoo.com.com';
}
return false;
}
</script>
</head>
<body>
<button type="button" onclick= Redirect(1,''); class="btn btn-danger">Cancel</button>
</body>
Try that. you need to assign location using =
If you want to use your syntax try window.location.replace as a redirect
How do I modify this mathjax example to live preview while I type? Right now it only displays result after I have pressed enter. I would like to tweak it so that it works similar to how stackoverflow/math.stackexchange shows the preview when typing a question.
<html>
<head>
<title>MathJax Dynamic Math Test Page</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [["$","$"],["\\(","\\)"]]
}
});
</script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full">
</script>
</head>
<body>
<script>
//
// Use a closure to hide the local variables from the
// global namespace
//
(function () {
var QUEUE = MathJax.Hub.queue; // shorthand for the queue
var math = null; // the element jax for the math output.
//
// Get the element jax when MathJax has produced it.
//
QUEUE.Push(function () {
math = MathJax.Hub.getAllJax("MathOutput")[0];
});
//
// The onchange event handler that typesets the
// math entered by the user
//
window.UpdateMath = function (TeX) {
QUEUE.Push(["Text",math,"\\displaystyle{"+TeX+"}"]);
}
})();
</script>
Type some TeX code:
<input id="MathInput" size="50" onchange="UpdateMath(this.value)" />
<p>
<div id="MathOutput">
You typed: ${}$
</div>
</body>
</html>
Instead of using onchange try onkeypress or onkeyup.
onchange is only triggered when you leave the field, but the others (obviously) happen with each key-stroke.
I suspect you are using Internet Explorer, which doesn't fire onchange events as often or efficiently as other browsers.
The version in the MathJax Examples includes more code to handle IE better. You might want to look at the source code there for details.
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [ ['$','$'], ["\\(","\\)"] ],processEscapes: true}});
</script>
<script
type="text/javascript"
charset="utf-8"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script>
function f() {
var input = document.getElementById("input");
document.getElementById("output").innerHTML = input.value;
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
</script>
<textarea id="input" cols="25" rows="5" onkeyup="f()">
</textarea>
<p id="output"></p>
I'm trying to reuse a function i made, but with any help yet.
Here is my index.html.
<html>
<head>
<script src="jquery-1.5.1.js")" type="text/javascript"></script>
<script src="JqueryScript.js")" type="text/javascript"></script>
<script type="text/javascript">
//MYLIBRARY.init(['#button1']);
execute(['#button1']);
execute(['#button2']);
</script>
</head>
<body>
<button type="button" id="button1">Click Me!</button>
<button type="button" id="button2">Click Me!</button>
</body>
</html>
And here is my script.
function execute (Args){
_args = Args;
$(function() {
$(_args[0]).click(function() {
alert("hello " + _args[0]);
return false;
});
});
}
The problem is always triggers the second alert windows (#button2). How can i make it work with both alert windows?
My guess is that you are wondering why both buttons alert the same output.
Because _args is global. Thus the second invokation will overwrite _args.
Use var to make it local:
var _args = Args;
Your code could still be improved (see #Town's answer), but this should get you started.
You also have errors in your HTML
<script src="jquery-1.5.1.js")" type="text/javascript"></script>
<!-- ^^ -->
<script src="JqueryScript.js")" type="text/javascript"></script>
<!-- ^^ -->
What exactly are you trying to do?
From what I can see, you could achieve the same functionality as what you have with simply:
$(function() {
$('button').click(function() {
alert("hello #" + this.id);
});
});
Example
Looks like C to me :)
You'd be better off with
<script type="text/javascript">
$(function () {
execute('#button1');
execute('#button2');
}
function execute(buttonId)
{
$(buttonId).click(function () { alert('Hello ' + this.id); });
}
</script>