Function For Onclick Method ?
Nov 18, 2010
I am self-studying Javascript, and I have encountered a few problems with exercises from the book I am using. All problems seem to be related to the onclick() method and the function I am defining.
In the latest exercise, I am supposed to use a confirm button to see if a person really wants to leave a site. If they click the link, they should get the confirm pop-up box, and if they click cancel, they should get an alert box saying they'll stay here.
I am following the code exactly as it is in the book, but instead of the confirm box, the browser immediately follows the link. I have included the code below.
This problem also occurred in an earlier exercise covering the innerHTML property. There's a math problem, and when you click the link, the answer is supposed to supplant the problem. I have included the code in the first reply to this message.
Please note that on the second problem, I do think there was an error in the book. I think that in the line "answer_link.onclick = function() {", the variable should have been a_link, not answer_link. However, I have tried it both ways and neither works.
Give me any input on this. If it matters, I am using Firefox 3.
Code:
View 8 Replies
ADVERTISEMENT
Dec 6, 2006
When I click on the image link the relevant id should change. But it doesn't.
Why is this?? Tried adding form tags but no difference.
<a href="#" <img src="img.jpg" id="" height="80" width="80" /> </a>
<img src="img.jpg" id="lrg_img" class="showcase_main" />
View 2 Replies
View Related
Jul 5, 2004
I know how to use the DOM to change the properties of page elements/tags, but I can't work out (and can't find any references anywhere) how to change the onclick event using the DOM.
I want to achieve something like this:
Code:
document.getElementById("myLink").onclick = "this.blur();"
but it doesn't work.
View 2 Replies
View Related
Sep 14, 2009
Let's say you have a :<a href="#" onclick='DoSomething(this);'>asd</a>I want to get the onclick text in a variable - something likevar onclick = $('a').attr('onclick');The problem is that the onclick variable now is a function and if Itry to execute , this wil be the document instead of the link .How can I get only the text, so I can later reattach it to the link ?
View 9 Replies
View Related
May 12, 2010
I am creating an application that uses as much Object Oriented code as I could (mostly to learn it).
I have an object called 'photo' that contains two Image() objects 'fullImage' and 'thumbnail'. All is fine and dandy, I can read the thumbnail and the full image, and their associated properties just fine.
But what I can't seem to do is make the thumbnail's onclick event refer to one of the object's methods.
Here is a greatly simplified version of the object's code.
Code:
So, the thumbnails div gets populated with the thumbnails fine. But for the life of me, I cannot figure out how to make the onclick call the photo object's "editPhoto" method.
Will the way that I am creating the objects using the same name for each one, result in only the last one created being accessible. If so, do I need to create an array of objects so I can uniquely identify each one?
View 3 Replies
View Related
Sep 12, 2010
I built up 2 codes, which do the same cause. but which one would be most efficient? or maybe which one would be best compatible for browsers?
CODE 1 :
- this code allows for me to use an #id
CODE 2
- using the REL
View 1 Replies
View Related
Aug 17, 2011
If I had 12 element divs, how could I make a toggle function that work for all of them?
<div id = "element1">
<div class="question">1. Who wrote the book James and the Giant Peach?</div>
<div class="answer"><img src="images/cover.gif" class="top"/><p>Ronald Dahl</p></div>
</div>
[Code]...
View 2 Replies
View Related
Aug 4, 2011
I have this javascript code which I would like to call the refresh method in my init function but I can't seems to be able to call it. What is the proper way of doing this?
PHP Code:
View 11 Replies
View Related
Dec 1, 2011
New to JS. Have ordered some new books, but need to get somethings going in the mean time. What I wanted to do is to link to a new page having a date range input in the form of 6 text boxes, 2 sets of mm-dd-yy, from and to, where the upon loading the page box 1 of the from would auto focus and then auto tab and then post where php could take over on the server side. Setting up the form and the lay out, no problem. Auto focusing went just like expected using the following code, included because on the next step everything fell apart.
Code:
<script type="text/javascript" >
window.onload=function() {
document.getElementById("input1").focus();
}
</script>
So then the wheels came off and in response, began to simplify what was trying to be done to find where the issues were. As far as I can get working is:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL]">
<html>
<head>
<script type="text/javascript" >
window.onload=function() {
document.getElementById("input1").focus();
}
</script>
<script type="text/javascript" >
function myFunc() {
alert("is this working");
}
</script>
</head>
<body>
<input id="input1" name="input1" type="text" onkeyup="myFunc()" maxlength="2" value="type a No." />
</body>
</html>
First issue with this: When I first get to the page everything is just as ordered. The focus is on the text box and the default value is "type a No." When I press a key onkeyup, I bring up the alert box with "is this working" in it. But when I refresh the page with the refresh button, after clicking the "ok" on the alert box, the character that was typed in is still displayed. If I use the link to the page, or the URL from the address bar, then the page reloads properly with the default value, "type a No".
How do you get the default textbox value using the refresh button as apposed to reloading the page using a link or from the address bar? Using Firefox 8.0 more important at the moment: If I change the script to pass an argument to the function the script crashes. It does not pull up an alert box and freezes. My guess is that I'm doing something wrong on a concept level. Changed the default value of the text box to " ". Looked like to me there was an issue with the size specification and the default string length as you could only enter in a key stroke by highlighting the text and replacing it.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL]">
<html>
<head>
<script type="text/javascript" >
window.onload=function() {
document.getElementById("input1").focus();
}
</script>
<script type="text/javascript" >
function myFunc(awe) {
alert(awe);
}
</script>
</head>
<body>
<input id="input1" name="input1" type="text" onkeyup="myFunc("123")" maxlength="2" value="" />
</body>
</html>
View 1 Replies
View Related
Oct 31, 2010
i am using the jquery multi day-plugin ([URL] and have a problem with inArray. here is my code
var arr = ['10.11.2010','11.11.2010'];
if ($.inArray(
[day.getDate(), (day.getMonth() + 1), day.getFullYear()].join('.'),
[code]....
View 1 Replies
View Related
Mar 16, 2011
I am trying to retrieve json data from the world bank's API, here's my code:
<html>
<head>
<script src="[URL]"></script>
<script type="text/javascript">
var theData;
$(document).ready(function(){
$("button").click(function(){
$.ajax({ url: '[URL]',
success: function(data) {
/*this alert message does not show*/
alert(data);
}, dataType: 'json' });
});
});
</script>
</head>
<body>
<p></p>
<button> Get World Bank Data </button>
</body>
The callback function is not executed but there is response when I checked it using firebug.
View 1 Replies
View Related
May 27, 2009
I've been using a hidden iframe for remote server scripting - how i've been doing it is that a load(); function changes the src component of the iframe with $_GET variables to pass to PHP:
this.load = function () {
this.iframe.src = this.file + "?action=load&gid=" + this.gid + "&last_modified=" + this.last_modified;
}
The frame itself then has an "onload" function that calls a doLoad(); function that handles receipt of any information back from the server. declared this way:
<iframe id="loader" onload="loader.doLoad();" style="width:0px;height:0px;border:none;"></iframe>
The trouble with this as you may guess is that the page was reloading every time src was changed and the history list of the browser was messed up. So I did some research and came up with this method that solves that problem:
this.load = function () {
//this.iframe.src = '';
this.iframe.contentWindow.document.location.replace(this.file + "?action=load&gid=" + this.gid + "&last_modified=" + this.last_modified);
}
Which is great, but now onload doesn't call!
View 1 Replies
View Related
Dec 1, 2011
What I wanted to do is to link to a new page having a date range input in the form of 6 text boxes, 2 sets of mm-dd-yy, from and to, where the upon loading the page box 1 of the from would auto focus and then auto tab and then post where php could take over on the server side. Setting up the form and the lay out, no problem. Auto focusing went just like expected using the following code, included because on the next step everything fell apart.
[/CODE]
<script type="text/javascript" >
window.onload=function() {
document.getElementById("input1").focus();
[Code].....
View 3 Replies
View Related
Dec 24, 2009
I'm trying to graph line with a delay between each line drawn - my code is:
var jg = new jsGraphics('Canvas');
jg.setColor('maroon');
jg.drawLine(40,130,80,120);
setTimeout('jg.paint()',10000);
jg.drawLine(80,120,120,110);
setTimeout('jg.paint()',10000);
Unfortunately it draws all the lines at the same time i.e the setTimeout function doesn't like the paint method.
View 1 Replies
View Related
Jun 24, 2009
html code:
view plaincopy to clipboardprint?
1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2. <html xmlns="http://www.w3.org/1999/xhtml">
[Code]...
I want - when the page load in result div will apper "Hello bla bla". It works for me if I dont use parameter(aka data: "{ }" and HelloToYou dont accept parameters)
View 1 Replies
View Related
Sep 30, 2010
I can't use the value returned by $.post() method out of the scope of success function.
For instance in below example myvar alerted as empty even though var is alerted with a value. Besides, hide does not work in the scope of success function.
View 2 Replies
View Related
Jul 25, 2011
I am inserting an image into a span tag by click on button and resize the image using resize_image_height_weight function.I am using two function to do this task. code...My purpose is to resize the image.
View 2 Replies
View Related
Nov 7, 2009
What is return statemen? what is functionn statement ? how can i write my frist program through return statement?
View 1 Replies
View Related
Jul 11, 2011
I am making a small gallery script. When a user clicks an image, I would like for a function to be called that tells the browser where that image is located in an object. For example:
[Code]...
It works, I just don't like it because it is messy and it seems sensible that some workaround exists.
View 1 Replies
View Related
Jan 1, 2011
How can I set a href or onclick function for an "a" element that passes information to the function?I have a function showpage() that is called whenever one of a number of buttons are clicked. I need to pass information from the button clicked to that function.
View 4 Replies
View Related
Aug 3, 2006
I'm trying to do something, but I don't know if it's possible.
Basically, I want to have a public static class method that could
access a private object's method. I would like to be able to do :
Class.method(InstanceOfClass);
The method would then access a private function from Class by doing
something like
function method(param) {
param.privateMethodOfClass();
}
I've done a lot research and experimentations but just can't come up
with a solution... I don't even know if what I'm trying to do is
possible.
View 4 Replies
View Related
Jan 31, 2011
Why is the callwhy is the slice method only a method of an Array instance? The reason why I ask is because if you want to use it for the arguments property of function object, or a string, or an object, or a number instance, you are forced to use Array .prototype slice.call(). And by doing that, you can pass in any type of object instance (Array, Number, String, Object) into it. So why not just default it as a method of all object instances built into the language?In other words, instead of doing this:
function Core(){
var obj = {a : 'a', b : 'b'};
var num = 1;[code]....
//right now none of the above would work but it's more convenient than using the call alternative.
}
Core('dom','event','ajax');
Why did the designers of the javascript scripting language make this decision?
View 4 Replies
View Related
May 23, 2010
I have a jsp document,and a java class with some functions,i want that a button that located in the jsp document, will execute a function from the java call on click.
View 1 Replies
View Related
Nov 1, 2006
I have a table in which rows are dynamically created. I have declared a onclick function dynamically which has arguments in it. And the arguments changes correspondingly as a result of xmlhttprequest.
How to assign a onclick function with arguments for a dynamically created element?
The problem is dynamically declared onclick function doesn't take the arguments.
tr=document.createElement('tr');
for(j=1;j<=3;j++)
{
td=document.createElement('td');
img = document.createElement('img');
img.id = "status" + (i+1);
img.src = '<?php echo $SG_ROOT_PATH; ?>' + /images/latest.gif;
img. { ViewCurrentState(studentName, Id, age);
td.appendChild(img);
tr.appendChild(td);document.getElementById('retrieveBkupsTable').appendChild(tr);
function ViewCurrentState(studentName, Id, age)
{
alert(studentName);
alert(Id);
alert(age);
}
Im getting undefined alert for all studentName, Id and age.
View 4 Replies
View Related
Mar 2, 2011
I would like to see if checkbox id='dirMember' is checked. If so, disable the field, if not enable the field. It will not work, and I can't see
javascript Code:
function disable() {
if (document.dirMember.checked == 1) {
document.featured.coStreet.disabled=true;
} else {
[Code].....
View 2 Replies
View Related
Jan 30, 2011
I'm having a small issue with being able to use the onclick more than once. When I load the page and click the link the request works fine the first time. But if I cancel the request then goto click the link again, nothing happens.
[Code]...
View 2 Replies
View Related