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>
Is there a way to get the index of the a you clicked passed into the handler? Like if I clicked the second A i would = 2.Same question for any jquery method actually. Since they all work off of collections I'd like to be able to get the index on anything.
Unfortunately that doesn't work. I understand that the index() isdocumentation (though confusing) correctly tells you that the above code doesn't work. Maybe I'm just weird, but I feel that the way .index() is implemented for string arguments is very counter intuitive. I have an expectation that .index() is similar to indexOf() in javascript.
Currently we have two forms on a single page. This is our jQuery
[Code]...
I've spent quite awhile reading documentation, how-to's etc, but I can' figure out how I can modify our jQuery so that we don't have a validate routine for each form. This is not a big deal for two forms, but some of our pages have five and more forms, so the jQuery would start to get long.
Does any body know how to use the index value of a tab and pass it to other functions across the app.. this works as long as it is in focus of the function
I know almost nothing about javascript... I am a designer. That being said, I need to code a zip code search form. There will be 2 or 3 different pages a user could get to depending on which zip code they enter. This is what I "borrowed" so far...
I am trying to get the index of a li with a specific class. I know I'm selecting the right object because I can apply a CSS class to it (eg change border colour) but when I try to get the index it returns -1. But I know the object exists as I can alter it. :-s
jQuery(document).ready(function() { var active = $("#tertiarynavigation .bordered").get(0); var num = $("#tertiarynavigation li").index(active); alert("Index: " + num);
Has anyone now how to simplify the following expression by avoiding
using attr("id") alert($("#"+$(obj).attr("id")+"~p:last").attr("id")); I need this because not every image could have an id. <script language="javascript" type="text/javascript"> function ExpandCollapseOnLeftPanel(obj) { if ($(obj).attr("src") == "/Content/Images/arrow_bot.gif") { // [Code]...
Code: function initArray() { this.length = initArray.arguments.length; for (var i = 0; i < this.length; i++) {[code].....
For the above piece of code, does the function 'function initArray()' just predefine the array that is written right after so that it's first array index starts at 1 instead of 0?
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.
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)
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.
I have the below array called "results". When I loop through all document elements I would like to check "field_name" against the "results" array and see if it exists and what index number it is at??
// Split the comma delimited response into an array results = result.split("~"); //Loop through array and populate fields[code].....
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.
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?
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.
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.
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:
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:
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:
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.
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.
I have a problem with layers. In my example there's a link inside div#msg with 'z-index:1' and a overlay with 'z-index:2'. Now when "mousedown" fires, will change the div#msg z-index value from 1 to 3 to be on Top, so the link become a clickable link.
The question is, it is possible to make the link on top and open it with just one click?
I have two methods and I would like to call somename1 method from within somename2 method. I have tried several ways to do so however I keep getting "TypeError" or "RefernceError" I have tried several ways to reference but I am still unable. What am I doing wrong. I would think this would be easy to do.
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.