JavaScript - Beginner Help With Extracting A Substring Out Of A Anchor Class Name
EDIT: Great...I already screwed up the title. It's not a div class but anchor class :s
I've got previous programming experience but unfortunately none with javascript. I was hoping to get Fancybox working on my website. It actually is already but there's a small problem with dynamic varibles I haven't been able to resolve. I've described the problem in the comment line in the code section. Must be a really simple solution, after all I'm a complete js noob. Note that I've simplified the code by removing parts unnecessary in understanding what I'm after. Code: <html> <head> <script type="text/javascript"> $(document).ready(function() { var title1 = "This is title no 1", title2 = "This is title no 2", title3 = "This is title no 3"; $("a#example_video").click(function() { $.fancybox({ 'title' : 'title' + this.className.replace("video", "") // "title" should equal to "title1", "title2" or "title3" depending on which link a user has clicked. How to accomplish this? </script> </head> <body> <a class="video1" id="example_video" href= .....>Video1</a> <a class="video2" id="example_video" href= .....>Video2</a> <a class="video3" id="example_video" href= .....>Video3</a> </body> </html> Also the only reason for using classnames on anchors is to be able to distinguish between different video clips. Is there a better method I should use? Similar TutorialsHiya! Trying to figure out how to use javascript to extract all links on a page that have a certain class: e.g. - extract only links with a class of 'tools', ignore all other links: Code: <a href="http://www.google.com" class="tools">Search</a> <a href="http://www.tripod.com" class="grapes">Searched</a> <a href="http://www.dogpile.com">Searches</a> Any help would be appreciated, I'm guessing I probably have to use something like getelementbyclass("tools")? Hi all Just curious how I might be able to target an anchor class with jQuery. For example, If my anchor class is: #nav a.activeSlide { } How can I target it for a fadeTo() ? Not sure of the syntax. Tried variations of: $('#nav a.activeSlide').fadeTo(1000,.5); To no avail. Thanks for your help. Hi guys, Having a little bit of trouble with a site I'm currently working on... I'm using some AJAX for the instant g-mail/facebook style navigation, you know the kind, with no refreshes, etc. Problem is, to allow for back/forward and bookmarks, I currently use a URL that looks like: http://www.mySiteOfFun.com/index.html#page=news.html; This is fine, not a problem... The issue comes into play when I want to open up the news.html page, from my home.html page, and have it open to news item #6 (for example). I can't add a #, because one is already being used to reference the anchor for the content div. Has anyone run into a similar problem before? If so, how did you resolve it? Can some jQuery be used to find the location of the news item div in question, on load, and scroll to it like that? Just not sure how to progress really, and any help would be greatly appreciated! Hey Guys, I'm looking to code something in JavaScript within an HTML page that asks the user for two numbers. When the user clicks Calculate, it subtracts them and multiplies the difference by 3. I've gotten that to work fine. However, I run into some trouble because the user may enter 31000, and the formula only works with 31. (So, if the user enters 31000 and 11000, the code has to cut those into 31 and 11 to plug into the formula.) I know I'll have to use (var).substring(0,1) but when I do this the program doesn't seem to run. I'm not sure if this isn't working because it's within <HEAD></HEAD> or because it's looking for letters and I only have integers in the variable. Here's the code I'm currently working with: Any help on how to extract the first two digits from "currentaltitude" and "finalaltitude" is appreciated. Thanks in advance!! Code: <html> <head> <script> function temp(form) { var currentaltitude = parseFloat(form.curAltitude.value, 10); var finalaltitude = parseFloat(form.finAltitude.value, 10); var calcaltitude = parseFloat(form.calcAltitude.value, 10); calcaltitude = (currentaltitude - finalaltitude) * 3; form.calcAltitude.value = calcaltitude; } </script> </head> <body> <FORM> Enter current altitude: <INPUT TYPE=text NAME="curAltitude" VALUE="" MAXLENGTH="15" SIZE=10> <p> Enter final altitude: <INPUT NAME="finAltitude" VALUE="0" MAXLENGTH="15" SIZE=10> <p> Click this button to calculate descent altitude: <INPUT NAME="calc" VALUE="Calculate" TYPE=BUTTON onClick=temp(this.form)> <p> Begin descending <INPUT NAME="calcAltitude" READONLY SIZE=4> DME from the assigned crossing point. </FORM> </body> </html> Basically what i'm trying to do is check the data in an XML node to see if it contains a certain string. I'm completely new to javascript and this seems like something very simple, but I must not be using the correct terms in my searches. For instance here i'm checking to see if the data in an xml node is equal to "URGENT" if so I'm changing the css. Code: function DoesXmlContainThisNode(strXML, strNodeXPath) { var bolFlag // Load XML var myDOMDocument = new ActiveXObject('Msxml2.DOMDocument.3.0'); myDOMDocument.async = false; myDOMDocument.loadXML(strXML); // Parse out value var myNode = myDOMDocument.selectSingleNode(strNodeXPath) if( myNode != null ) { bolFlag = true } else { bolFlag = false } myNode = null return bolFlag } , Code: if (DoesXmlContainThisNode(strResponseXml, "Response/XMLResponse/*/Message/Body[text()='URGENT']")) { strStyle = 'URGENT' } And maybe I cant do it the same way, but how would I search for any instance of the word "urgent". Say my message has 4 sentences and if the wor durgent appears anywhere in it.. I want to change the stylesheet. I would think there is some way to use a wildcard or "contains" string... I see the text() class being used everywhere but only on exact matches. Any help is greatly appreciated. Thanks Hi all, I am having trouble trying to use the substring String method. Relevant HTML code: Code: <img id="news" src="../images/news.png" alt="News" onmouseover="change(this)" /> Relevant JavaScript code: Code: function change(element) { if (element.id == "news" && element.src.substring(3,5) != "../") { element.src = "../images/news.png"; alert(element.src.substring(3,5)); } else if (element.id == "news" && element.src.substring(3,5) == "../") { element.src = "../../images/news.png"; } } I want the image to change to another image, but depending on the src in the HTML code. This is so that it can locate the correct folder. However, it doesn't work, and I tried using an alert statement to show me what JavaScript is reading and it seems to read "e:", which is not correct. It never reads "../", which it should. I don't know how to solve this problem, any ideas? Hi Guys, I am trying to make a function that will search for a substring, in this case 'http://instagr.am/p/' within a text area on a form then add '[embed]' & '[/embed]' tags around it. I have currently got the following code Code: <script type='text/javascript'> function show_alert() { str = formname.elements['inputid'].value; arr = (str.split(' ') + '<br />'); jQuery.each(arr, function() { if (arr.indexOf('http://instagr.am/p/') >= 0) { alert('An http://instagr.am/p/ link has been found'); //alert('It is entry ... in the array'); //Then edit the entry } } ); } </script> This breaks the contents of the textarea (at spaces) into an array then finds any entries with 'http://instagr.am/p/' in them (could be 'http://instagr.am/p/29fdghHdv'). Once it has found any and all of these entries it will add an '[embed]' code to the beginning and an '[/embed]' tag at the end. Example... http://instagr.am/p/vuHdeyfa2 is converted to: '[embed]http://instagr.am/p/vuHdeyfa2[/embed]' Then the changes must reflected in the textarea input "formname.elements["textareaid"].value = editedstring; Thankyou for your assistance. Hello, I am new with Javascript and running into this problem that I don't understand. I define a base class that only contains an array "elements", and a derived class that contains nothing more (for simplicity): Code: function baseClass() { this.elements = new Array; } function derivedClass() { } derivedClass.prototype = new baseClass; Then I create two instances of the derived class, and add two elements in each: Code: a = new derivedClass(); a.elements.push("A"); a.elements.push("B"); b = new derivedClass(); b.elements.push("C"); b.elements.push("D"); When I examine the contents of these arrays, I see that both a.elements and b.elements contain {"A","B","C","D"} ! I.e. as if the two arrays are in fact the same array! But these are two separate instances of the class, I expect two separate arrays. Note that if instead I use the base class: Code: a = new baseClass(); a.elements.push("A"); a.elements.push("B"); b = new baseClass(); b.elements.push("C"); b.elements.push("D"); then I get a.elements = {"A","B"} and b.elements = {"C","D"}, as I would expect. Could someone explain to me the problem with using the derived class? Thank you, Stephanos would it be better to place the javascript into a .js file or just place the js code somewhere else in the html? How should it look? Code: <div style="width: 225px; height: 155px; float: left; height: 16px; background-color: #000000; color: #FFFFFF; margin-left: 0px; margin-bottom: 0px; font-size: small; padding-left: 0px;"> <img alt="" src="images/news.png" height="16" width="222" /><div style="width: 225px; height: 155px; float: left;"><script type="text/javascript">// <![CDATA[if(document.layers){document.write('<ilayer id="ns4div" width="'+swidth+'" height="'+sheight+'" bgcolor='+sbcolor+'><div id="ns4div1" width="'+swidth+'" height="'+sheight+'" onmouseover="sspeed=0;" onmouseout="sspeed=rspeed"></div></ilayer>')} if(document.getElementById||document.all){document.write('<div style="position:relative;overflow:hidden;width:'+swidth+'px;height:'+sheight+'px;clip:rect(0 '+swidth+'px '+sheight+'px 0);background-color:'+sbcolor+';" onmouseover="sspeed=0" onmouseout="sspeed=rspeed"><div id="iens6div" style="position:relative;width:'+swidth+'px;"></div></div>');} // ]]></script> </div></div> I'm trying to get some average rgb values from an image in one canvas object and apply them via fillstyle to a rectangle in another canvas object. I have a dropdown that loads an image onChange()="ChangeBaseWood()" into a canvas object. The second canvas object is to be filled with an average color based on the content of the first canvas onClick="GetBaseColor()". For simplicity I've replaced the for loop with just the values of pixel 0,0. Where I think I am assigning the rgb values, the error console keeps reporting that var sample is undefined at the line "var redpart = sample[0]. Code: function ChangeBaseWood(){ var dropdown = document.getElementById('woodvalue'); var woodcanvas = document.getElementById('basewood'); var woodctx = woodcanvas.getContext('2d'); var woodimage = new Image(); woodimage.onload = function(){ woodctx.drawImage(woodimage, 0, 0,256,256); }; woodimage.src = dropdown.value; }; function GetBaseColor(){ var woodcanvas = document.getElementById('basewood'); var woodctx = woodcanvas.getContext('2d'); var sample = woodctx.data var redpart = sample[0]; var grnpart = sample[1]; var blupart = sample[2]; var staincanvas = document.getElementById('stainbase'); var stainctx = staincanvas.getContext('2d'); stainctx.fillStyle = 'rgb('+redpart+','+grnpart+','+blupart+')'; stainctx.fillRect(0,0,256,256); }; I've tried various things to assign the redpart,grnpart and blupart but I'm missing something basic. Many Thanks I need to extract a particular part of a string: Code: var str=(document.images('flag').src); <img id="flag" src="../../../../img/ip/041-080/049p.png"> I only want the "041-080/049" part. It needs to be read from the right, not the left because the preceding left part will vary in length. How do I approach this? Hi, I have a bit of a problem and as my javascript is a rather poor I'm struggling to come up with a solution. Basically I need to split the variable "#country" into two parts and call the second half as the "this" value for '#int-dc'. Using '+' as the start point end ending at the end of the string. For instance 'this' returns 12+44 I want to split it to "12" and "+44" the latter (+44) replacing 'this' in the code below. Code: $(function() { $("#country").change(function() { $("#int-dc").val ($(this).val()); }); }); Thanks in advance. Hi, I'm pretty new to Javascript, by about two weeks, I'm looking for help with a problem I have with the following.... <td title='text1;text2;text3'>text4</td></tr> I'm trying to display text1-3 in a table cell on a rotation, I have this to count through the cells to get to the relevent one... [CODE] function rotateCell() { var delayed = document.getElementsByTagName('td'); //.title.split(';'); for (var i=24;i<24;i++) [CODE] This should allow me to identify the location/cell 24 but can some one tell me how I then extract the tittle data and have them alternate within the cell? I'm not allowed to edit the HTML. Very gratefull for any help PeteW Hi there... I have a question for the following code (a callback func for ajax) Code: function callBackFunctionForAddAdmin(data) { alert(data); } If we get the following alert message Quote: <result><error>the given userid is already admin.please enter another one.. </error></result> How do i extract the data inside the "error" tag?? (first checking if it exists and then if so extracting it) Hi there, I am trying to extract all of the values from the 5th column (Assignee) in this HTML table http://bugzilla.maptools.org/buglist...icksearch=test and don't know how to proceed. Is there a clever way of getting the entire col class: <col class="bz_op_sys_column"> before putting into an array. thanks, kev From this string: "(EVAL)(H:somestring)Other Text here" I need to extract (H:somestring) and somestring into variables where somestring will could be and set of characters. Below is not working. Code: <script type="text/javascript"> var x = "(EVAL)(H:pines)Some other Text here"; alert(x.match(/H\:(.*?)/g)); </script> Thanks for any help or information. Hello all, this is my first posting and I am happy to have found this forum :-) I have the following question: Is it possible to extract information which is located in a predefined area on the screen from a java platform? For example, there is java based platform which I can see on my screen. This platform contains numbers/letters. The location of these numbers/letters does not change, i.e. the script would not need to be adjusted if the field, which contains the info, would move. Lets assume the screen would look like that: 1234 I 12.20 Love I 1.30 Lake I 32.00 The info between the fields would be clearly separated. Now I would like to extract the infos from all the fields and paste the info for example in EXCEL so that I can see "Valerie12345" in .xls field A1 / 12.20 in A2 / Love in B1 etc... Does anybody of you know if that is possible to extract? Thank you very much in advance, Valerie I have the following string "d3-23-76-546" I'm looking for a regular expression that will match everything in this string before 546 so that I can replace it with an empty string and just be left with 546. The string could be of any length and contain any number of hyphens. Hello, I'm working on a project that involves extracting values from a series of select boxes and then working out the result. The select boxes contain the following: Code: <select name="select_Col1_Row1"> <option value="blue">Blue</option> <option value="green">Green</option> <option value="red>Red</option> </select> <select name="select_Col1_Row2"> <option value="blue" selected="selected">Blue</option> <option value="green">Green</option> <option value="red>Red</option> </select> <input type="text" name="RedSum"> <input type="text" name="BlueSum"> <input type="text" name="GreenSum"> </select> As you can see by my code, I'm early days at this and guessing the steps on the way. I tried using getElementsByTagName on the select and then on the option but had no luck with that. The code below does a wonderful job of returning blue for both select statements... Code: <script type="text/javascript"> function getElements() { var table = document.getElementById("x"); var x = table.getElementsByTagName("option"); for (var i = 0; i < x.length; i++) { var status = x[i].getAttribute("selected"); alert(status); if (status == "selected") { var statushcap = x[i].getAttribute("id"); var statusvalue =x[i].getAttribute("value"); if (statusvalue == "blue") { alert(statusvalue); } } } alert(x.length); } </script> If someone could suggest some way to map the select tag and then extract its option value to being the user selected value, I'd most appreciate it. I can probably do the rest of it. Can you extract additional information from the id of the option that is selected as I'd like to sum additional information from the user's choice. Best, John Hi there, im wondering if you can help me i need help in finding javascript resources to build my skills and knowledge of Jscript because im a beginner. Please help |