JavaScript - Jquery Questions
I am not understanding something here with this:
http://www.w3schools.com/jquery/jquery_ajax.asp Code: <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("div").load('test1.txt'); }); }); </script> </head> <body> <div><h2>Let AJAX change this text</h2></div> <button>Change Content</button> </body> </html> When you click on the button, AJAX changes the text : Code: Let AJAX change this text to: Code: AJAX is not a programming language. It is just a technique for creating better and more interactive web applications. My question is, where is this text above located since it's not in the code? Also, if I wish to change the text mentioned, how can I do so please? Similar Tutorials1.I found a Slider Toggle thats demonstrated here and it seems to work fine but only if the link is placed above the div that slides down.. im trying to make the div slide down from above my menu and i want 1 of the links on my menu to toggle the slider. how do i get it work to where I can place the link below the sliding div? 2. the script originally used Code: .fader{opacity:0;display:none;} but I wanted the slider div to be visible if javascript was disabled so I added Code: jQuery(".fader").hide(); so its now Code: <script type="text/javascript"> $(document).ready(function() { jQuery(".fader").hide(); $(".fadeNext").click(function(){ $(this).next().fadeSliderToggle() return false; }) }); </script> instead of Code: <script type="text/javascript"> $(document).ready(function() { $(".fadeNext").click(function(){ $(this).next().fadeSliderToggle() return false; }) }); </script> <style> .fader{opacity:0;display:none;} </style> will this be fine in browsers or is there a better way to hide the div with javascript so its visible when javascript is disabled? So, i have this code which retrieves php files for me using jquery and id love to get it working with Jquery history plugin. I tried modifying the code i got from the ajax demo to work for me, but i just couldnt do it as i do not know any javascript really.. ( actually what i tried was simply to change "#ajax-links a" to "#menu li a" and .html to .php ..but nothing.. :rolleyes: Id be very gratefull if someone would help me out with this one. All related code can be found bellow (the ones that should be needed anyways): This is the code that retrieves php files inside "#content" when item from "#menu li a" with the specified id is clicked Code: $(document).ready(function(){ //References var change = $("#menu li a"); var loading = $("#loading"); var content = $("#content"); //Manage click events change.click(function(){ //show the loading bar showLoading(); //load selected section if(this.id == "home") { change.load(this.className='current-page'); content.slideUp(); content.load("pages/index.php", hideLoading); content.slideDown(); } else if(this.id == "secondpage") { change.load(this.className='current-page'); content.slideUp(); content.load("pages/secondpage.php", hideLoading); content.slideDown(); } else { //hide loading bar if there is no selected section hideLoading(); } }); //show loading bar function showLoading(){ loading .css({visibility:"visible"}) .css({opacity:"1"}) .css({display:"block"}) ; } //hide loading bar function hideLoading(){ loading.fadeTo(1000, 0); }; }); Heres the structure of the menu/content Code: <ul id="menu"> <li><a id="home" class="normal" href="#Home"></a></li> <li><a id="secondpage" class="normal" href="#Secondpage"></a></li> </ul> <div id="content"> <ul id="sec-menu"> <li><a id="link1" class="normal" href="#">Link1</a></li> <li><a id="link2" class="normal" href="#">Link2</a></li> </ul> </div> Heres the code that jquery history plugin uses in demo for ajax Code: jQuery(document).ready(function($) { function load(num) { $('#content').load(num +".html"); } $.history.init(function(url) { load(url == "" ? "1" : url); }); $('#ajax-links a').live('click', function(e) { var url = $(this).attr('href'); url = url.replace(/^.*#/, ''); $.history.load(url); return false; }); }); hi, i have a jquery problem... this script is not working with jquery-1.4.2.min, but it works with jquery-1.2.6.min.js, can anyone help me???the script is the above: (it is not working the tab actions, the slideout works...) http://www.benjaminsterling.com/wp-c...es/sidetab.htm the javascript code is the above: PHP Code: var jqsideTabs; var tabs, h = 50, r = 0,ra = 0; $(document) .ready(function(){ jqsideTabs = $('#sideTabs').addClass('closed'); tabs = jqsideTabs .find('.tab h3') .clone() .appendTo(jqsideTabs) .each(function(i){ var that = $(this), cls = '',ow,newThis, newEl; if( i == 0 ) cls = ' active'; newEl = $('<a href="#" class="tabLinks'+cls+'">' + that.text() + '</a>'); that.replaceWith(newEl); ow = newEl.outerWidth(); if( i == 0 ) ra = ow; else r = ow; h = newEl.css({'top':h , 'right': -ow }).height() + h; newThis = newEl.get(0); newThis.jq = newEl; newThis.i = i; newEl.click(function(){ var el = this.jq; if( jqsideTabs.hasClass( 'closed' ) ){ jqsideTabs.removeClass('closed'); } else if( !jqsideTabs.hasClass( 'closed' ) && el.hasClass('active') ){ jqsideTabs.addClass('closed'); } el .siblings() .removeClass('active') .css({'right': -r }) .end() .addClass('active') .css({'right': -ra }); tabs.eq( this.i ).show().siblings('.tab').hide(); return false; }); }) .end() .parent() .eq(0) .addClass('active') .end() .filter(':not(:eq(0))') .hide() .end(); jqsideTabs.bind("mouseleave",function(){ jqsideTabs .animate({left:-310}, 'fast', function(){ jqsideTabs.addClass('closed').removeAttr('style'); }); }); }); and the html file is: [HTML] <div id="sideTabs"> <div class="tab"> <h3>Tab 1</h3> <div class="gut"> <p>Some text</p> </div> </div> <div class="tab"> <h3>Tab 2</h3> <div class="gut"> <ul> <li>link</li> </ul> </div> </div> <div class="tab"> <h3>Tab 3</h3> <div class="gut"> <ul> <li>link</li> </ul> </div> </div> </div> [/HTML] the problem is that the tab button works, but the content doesnt change...in all of tabs showing the same text(showing all tbas content).... can anyone help...please..... i keep getting the error GET http://code.jquery.com/jquery.min.map net::ERR_TOO_MANY_REDIRECTS & Failed to load resource: net::ERR_TOO_MANY_REDIRECTS when i load my page...and the havascript doesn't work properly on ym page...how do i resolve this. thanx in advance var s="attr" var i=$(s) // jQuery(elem).attr(attr,eval("elm"+attr)); jQuery(elem).$(s)(attr,eval("elm"+attr));//i tried this. how to assign a variable name in the above code(in place of s) so that i need to add an attribute to the element "elem". Hi again, I have 2 new questions for you all! 1.) *RESOLVED* 2.) So in this form: Code: <form name="form" action="email.php" method="post"> <div id="dynamicInput"> <br> <input type="checkbox" name="1" /><input type="text" name="i[]"> </div> <input type="button" value="Add another text input" onClick="addInput('dynamicInput');"> <br> <input name="email" type="text"> <br /> A12098 <input name="verify" type="text"> <input name="submit" type="submit"> </form> I have a button that will add a form element to the form. In this case, it adds a checkbox and a text box. The name on the checkbox goes up from 1-30 (thats the max amount of fields that can be added) and the text box has a name of i[]. Is it possible for the user to click on the checkbox and the corresponding text box (the one next to the checkbox) will be disabled so editing is stopped? Then they could un-click it and it would be editable again. Thanks in advance! 1. I am in the midst of making a website and doing a few things but am thinking of adding a log in section for members can i put a password directly on a video file? or do i have to do it to the page? 2. Also looking for a good provider to upload my site to, what does everything suggest for this? Thanks JavaScript functions must be called: A. from the server B. implicitly C. explicitly D. A and C, but not B. E. None of the above. JavaScript commands written outside of a function will be executed: A. by the server. B. implicitly. C. explicitly. D. never, they are ignored. E. None of the above. The best loop for iterating through an array is A. Enhanced For loop B. While C. Do Until D. Do While. E. None of the Above. JavaScript Arrays are always passed to functions? A. By Reference. B. By Value. C. Globally. D. As a string. E. None of the Above. The best way to execute JavaScript code when you first bring up a page is: A. onload event B. JavaScript code outside of any function. C. onstart event. D. All of the above. E. None of the Above. Write a JavaScript function to handle a callback: Assume the following input fields: <input type="text" id="lastName" name="lastName" /> <input type="text" id="firstName" name="firstName" /> <input type="text" id="phone" name="phone" /> <input type="text" id="email" name="email" /> A callback function will receive a pipe delimited string from the server as such: Last-name|first-name|phone#|email Example: Doe|Jane|415-555-1212|jane.doe@gmail.com The callback function is: function customer_Callback ( content ) { // use the split method to convert content to an array. // use document.getElementById() to get each of the above input fields. // populate from the array. } ----------------------------------------- I am having serious trouble with these problems, I beseech you! There will be a special prize to whoever answers correctly all these questions first. Thanks! Hi, I am currently having a problem with my code. It is pointing at a logical error somewhere as neither the error console in FireFox nor Firebug can detect any errors. The problem is getting the alert box to pop up when the user types in invalid letters or numbers for their respective functions. I guess it could be the Unicode coding for Internet Explorer or Mozilla, or maybe the validation is not getting called from the option list....Anyway here's my code so far: <script type="text/javascript"> /* <![CDATA[ */ function validateAlphabetic(keyPressEvent) { if (navigator.appName == "Microsoft Internet Explorer") var enteredKey = keyPressEvent.keyCode; else if (navigator.appName == "Netscape") var enteredKey = keyPressEvent.charCode; var enteredChar = String.fromCharCode(enteredKey); var retValue = true; try { if (!/\D/.test(enteredChar) && !/\W/.test(enteredChar)) throw "You did not enter an alphabetic value."; } catch(inputError) { window.alert("You can only enter letters into this field."); retValue = false; } finally { return retValue; } } function validateNumeric(keyPressEvent) { if (navigator.appName == "Microsoft Internet Explorer") var enteredKey = keyPressEvent.keyCode; else if (navigator.appName == "Netscape") var enteredKey = keyPressEvent.charCode; var enteredChar = String.fromCharCode(enteredKey); var retValue = true; try { if (!/\d/.test(enteredChar) && !/\W/.test(enteredChar)) throw "You did not enter a numeric value."; } catch(inputError) { window.alert("You can only enter numbers into this field."); retValue = false; } finally { return retValue; } } /* ]]> */ </script> </head> <body> <h1>Challenge Questions</h1> <form action="" enctype="application/x-www-form-urlencoded"> <select> <option value="maiden" onkeypress="return validateAlphabetic(event)">What is your mother's maiden name</option> <option value="pet" onkeypress="return validateAlphabetic(event)">What is the name of your favorite pet?</option> <option value="city" onkeypress="return validateAlphabetic(event)">What city were your born in?</option> <option value="security" onkeypress="return validateNumeric(event)">What is your social security number?</option> <option value="siblings" onkeypress="return validateNumeric(event)">How many siblings do you have?</option> </select><br /> <input type="text" size="25" /> </form> </body> Reply With Quote Hey everyone. I am very new at JavaScript and I need some help. I want to have a section on my home page where a person can choose a bike by clicking on a couple of arrows on the right and left ends of the bike. I want something similar to this type of program. http://qlpros.com/ I don't want a border around the bike. I have been looking for a couple hours now and I haven't found anything. Any help would be much appreciated!! My other question is how to transfer javascript to an external style sheet in dreamweaver. Thanks!! Ok, so I have a couple of questions about JavaScript that I would like answered by the programming gurus on this forum, please. Firstly, I have an idea for an online text-based role-playing game (games like GangsterParadise, etc.), and I am wondering, is it possible (or advisable?) to create the site using nothing but HTML, CSS and JavaScript? Can it be done, and if so, are there any downsides to doing this? I have heard using strictly JavaScript as a programming language on its own, on a site where members will have their own password-protected accounts, should not be done, as there are serious security flaws - is this true, and if so, why? Secondly, most JS programmers on the forum have probably digested and been through hundreds and hundreds of books on the subject since beginning to learn JavaScript - in your opinion, what are the best books to get hold of, for a relative beginner to JavaScript? What book makes the language easy to understand, and doesn't have you scratching your head to make sense of what it is saying? Thanks a lot in advance for the help, it's much appreciated. 1. I want to make form with 2 select filds that one of them will be disabled if in the first the use choose a specific option i wrote it in this way (but its not work) how I fix it? Code: <script type="text/javascript"> function itay() { if (document.some1.one.value="x") document.some1.two.disabled=true if (document.some1.one.value="y") document.some1.two.disabled=false } </script> </head> <body bgcolor="#FFFFFF"> <form name="some1"> <table> <tr> <td> <select id="one" onclick="itay()"> <option value="x">x</option> <option value="y">y</option> </select> </td> <td> <select id="two"> <option value="a">a</option> <option value="b">b</option> </select> </td> </tr> </table> </form> 2. I want that after u fill the form and press submit u will see a txtarea with all the options u selected (for confirm that you chose the right things) and then press submit agien and get all the things u saw in the txtarea to a Email. (Hope u understand ) so how I do it? 3 questions. I am very very new to JS (i am a html/css wiz but am just now learning js. I have taken 2 university CS courses but both were with C++)... My friend sent me these problems and wanted some help. Anyone here wanna give em a go? Given the string "Frank delete from users Beans" in a textfield If you find any sql token you find (like delete, drop, truncate, etc), strip it out, and regenerate the original string without those tokens; place the regenerated string (without the sql) back in the textfield. If You cannot strip out the sql and place the sanitized value back in the textfield, you will not get full credit for this question. Write a document that contains 5 paragraphs, and 4 headers. Create a script that finds all of them and puts "FOUND IT" beside it. Create a document that lets user's enter a planet's (like Jupiter, Saturn, Mars...) name (via a select or input field), and at the click of a button (or when the selected option was chosen), have the distance (from the Sun or Earth) appear next to that select box or textfield (which ever you choose to implement for the input from the user.) Please use Google to find the distances. HINT: use innerHTML = '...' Thanks guys! I'm researching a possible web project. The project will allow users to create and run JS online, similar to JSFiddle, Construct 2 and GameSalad. At this stage I'm just looking to gather general information. So my first question is, just how big of a project would that be? what web technologies would be needed? Would Node.Js be needed? or would PHP be ok for the backend? Thanks for any advice. Hey everyone, I have a survey that I have been developing (with the help of people from this forum among others) that is nearing completion but still has a couple things to be worked out using JavaScript. For reference, here is a link to the survey: http://wri.eas.cornell.edu/weed_survey_site/index2.html Here is one issue that I'm having and I would appreciate any help: 1. on line 111, the label, id and value for each input needs to increase by one (i.e <label for='ValidCheckbox_01'><input type = 'checkbox' name = 'ValidCheckbox2' id= 'ValidCheckbox_01' value= '1'>" + i + "</label>, <label for='ValidCheckbox_02'><input type = 'checkbox' name = 'ValidCheckbox2' id= 'ValidCheckbox_02' value= '2'>" + i + "</label>, etc.) for each additional label. Lately I've been doing some modding for a game called Minecraft which requires some programming in Java. I've been doing a lot of research but because I can't think of a simplified version of my questions it's hard to get any results from Google. So I'm hoping someone could answer these for me. If you can't, I would even appreciate being pointed in the right direction or led to some reading material that would answer these questions for me. 1) How can I add the value of a variable onto the name of another variable. For instance, I have this line of code Code: EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(Item.ingotIron)); and this variable that will always be a number Code: private int numberA; I would like to add the value of numberA onto entityitem. So if numberA was 1 entityitem would become entityitem1. 2) What is the best variable type to store values such as Item.coal, which is an object within the game? Would a String type suffice? 3) Using the same code above: Code: EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(Item.ingotIron)); How could I use a variable's value where Item.ingotIron is? I tried some different things but the compiler threw "ItemStack doesn't exist" or some error along those lines at me. For instance if variableA's value is Item.coal, how could I use that variables value where Item.ingotIron is. Code: EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(variableA)); I appreciate your time and help on this issue and anything you can provide will be greatly appreciated. Hi all, This is a quickie. I'm a JavaScript newbie. I have had a crack programming with it but I need some questions answered to help my understanding. Please tell me the convention that governs the use of "" and '', because so many articles that I am finding in my learning journey are using them interchangeably and it is so confusing. For instance, but not limited to, take the id and value tags of an <input type=... of whatever. Is it best to use '' or "" for the labels you give? What is the convention governing the use of a ; (semicolon) because so many people use one where others do not. I'm under the impression it is an EOL terminator like in Bash, right? So it goes after declaring variables or after something within an if statement perhaps? Thanks QF I am newbie in javascript. While being studying it I have not understood some concepts well. JS is prototype-based language, as in Java it has one main prototype Object, also there are some other widely used object, like Array, RegEx, String ...... . So I can access and inherit from this objects/prototypes. So the questions is where do this object (declarations) are stored ? They are also allocated in memory ? Or when JS sees that there is declaration of some object is present i script it reads from file or whatever ? When I am using Function with key word new, what happens. As far as function is also object, it has field prototype and when calling this function with new it returns object of prototype type ? Am I right ? So if I haven't specified prototype it will returns object of Object type ? How does javascript knows about real type of variable. For example when I use regexp, it has method exec. I can call it on every variable. But I guest if variable doesn't have this field it returns undefined ? So the question is how does JS determine what real type of variable is ? Where this information is stored ? Closure in JS. I don't understand this concept well. I think of it like reference count in Java (used or been used by Garbage Collector). If we have a least one reference to variable it will still exist and it doesn't matter where it was declared. So making getter method inside another func makes it exists in memory. If I am wrong please give good explanation of this. Does JS runs in its own virtual machine like Java ? Or browser plays this role. I guess if it has GC, since one process cannot access address space of another process it should be something like virtual machine which controls memory allocation. I would be very grateful for help. Thx in advance. Reply With Quote 01-21-2015, 10:44 AM #2 Dormilich View Profile View Forum Posts Senior Coder Join Date Jan 2010 Location Behind the Wall Posts 3,532 Thanks 13 Thanked 372 Times in 368 Posts Questions About Javascript - JavaScript | Dream.In.Code I know that global variables are properties of the window object... so does that mean that local variables are properties of the function they belong to? And does that mean that functions are methods of the window object and that nested functions are methods of the function they belong to?
|