JavaScript - What Am I Doing Wrong? Part 2
I got some updates on my progress... still no results.
(quoting my previous thread) Quote: I need desperate help with a homework! Here's the task: First of all I need to define an array of 3 elements. Each element is associated with a different first name. Then I shall realize a first function to add a name in the table. The function takes as parameter the table previously created and return it containing an additional element whose value is the name that the visitor wants to add. I must use the dialog box prompt so that the user can specify the name he wishes to add in the table. I shall also perform a second function which will display the name that is included in the different array elements. This function will also take the table in parameters and proceed with setting the display name with a dialog box alert type that contains all of the name separated by ";". Here's what I've done so far: Code: <html> <head> <title> Task #4 </title> </head> <body> <script language="javascript"> function addName() { var names=new Array(3); names[0]="John"; names[1]="Patrik"; names[2]="Jane"; document.open(); document.write(names[3].join()); document.close(); if(names==new Array); { prompt("What name do you want to add?"+""); } return addName } </script> <noscript> <h1> You're browser doesn't support Javascript </h1> </noscript> </body> </html> Updates: Code: <html> <head> <title> Task #4 </title> <script language="javascript"> function addName() { var names=new Array(3); names[0]="John","Brian"; names[1]="Patrik","Gene"; names[2]="Jane","Sophie"; document.open(); document.write(names.join(";")); document.close(); if(names==new Array); { var addToArray=prompt("What name do you want to add?","") names.push(addToArray) } } function displayNames(addName) { alert(addName); } </script> <noscript> <h1> You're browser doesn't support Javascript </h1> </noscript> </head> <script language="javascript"> <body onLoad="displayNames(addName)"> </body> </script> </html> Similar TutorialsI've got an idea for simplifying my code and avoid a bunch of switch functions but don't know how, though I assume it's possible. How do I write a function to change/insert only part of an img src? in other words something along the lines of if url contains: "/folder1/folder3/"; change this to: "/folder1/ folder2 /folder3/"; I'm trying to figure out how to split a url variable... I tried these two ways, with an alert to see my result, but I'm not getting anything. Suggestions? Code: function() { myURL = "http://www.test.com/folder1/folder2/someone" var partsA = myURL.split("//"); var parts = partsA[1].split("/"); alert(parts[2]); } Code: function() { myURL = "http://www.test.com/folder1/folder2/someone" var parts = myURL.split('/'); var result = parts[parts.length-2] + '/' + parts[parts.length-1]; alert(result); } My problem is relates to getting part of the text from a div, then pass this on to a variable which then acts upon it. This is a short summary in detail: http://jsfiddle.net/defencedog/W9Fsw/ Above simulates a Forum like environment (PHPBB3). here user can't insert html in posts thus a customised BBcode ([doc])is made in which is placed the required src attribute, unique to every SCRIBD document. The goal is to get the text within the two [doc] & that will be something like (discarding the two BBCodes) Code: src="http://www.scribd.com/embeds/2942002/content?start_page=1&view_mode=list&access_key=key-sxlnrfvqu5s22kzi5xb" then pass it on as a variable named src, which will then replace the contents to achieve desired output. Notice the two problems 1] how do I select the div upon which the action is to take place I.e that contains [doc]. Remember there occurs other divs as well in a posted message? 2] How do I select the desired text? Plz do giv me some suggestions Hi, I have youtube link saved as a variable with value: PHP Code: http://www.youtube.com/watch?v=oOzuBOefL8I&feature=topvideos And I need to get a part of this link which I could use later: The part would be PHP Code: oOzuBOefL8I It would be great to do it with javascript... Because I have url generated like this one: PHP Code: httpObject.open("GET", "../talpinimas.php?id=reklama&paveikslelis=" +document.getElementById('paveikslelis').value+"&pavadinimas=" +document.getElementById('pavadinimas').value+"&url1=" +document.getElementById('url1').value+"&url1name=" +document.getElementById('url1name').value+"&komentaras=" +document.getElementById('komentaras').value+"&nick=<?php echo $nick?>" , true); and I want to send just THE PART (oOzuBOefL8I) to my talpinimas.php page. If you haven't understood something or need more info ask... Thanks css: Code: #nav{ width: 960px; margin: 0 auto; } ul li{ float: left; margin-right:50px; list-style: none; } .sub-menu{ display: none; } jquery code: Code: $(function(){ ("#nav ul li").hover(function() { (".sub-menu").css("display","block"); }); html code: Code: <div id="nav"> <div class="left"></div> <div class="right"></div> <ul> <li><a href="/" class="current">Home</a></li> <li><a href="/cpanel.html" class="">cPanel</a> <div class="sub-menu"> <h2>test</h2> <p> <a href="#">test</a> <a href="#">test</a> <a href="#">test<</a> </p> <p> <a href="#">test</a> <a href="#">test</a> <a href="#">test<</a> </p> </div> i am sorry, i am new of jquery.i want to show the sub nav part when the mouse hover on the `li` part. but my code doesn't work.how to correct it. thank you hello i need help in deleting a code part, like: table, ul ... the problem is that when i use rss feeds, lot of them add some code parts that i don't need like: <ul class="similar-topics">, and it shows similar topics so, i want to remove this code part from the rss feed i think that i may add a javascript code to the rss template that brings the rss feeds, so as it remove the part i define i hope you help me doing this, even with another idea another idea is to use: http://pipes.yahoo.com i"m sure there is a way to cut parts from the code, but i couldn't get it yet and i'm still trying Regards I'm trying to figure out if its possible to get only certain parts of a string like in PHP... If I have a function like this: Code: function getUrl(selectUrl) { The selectUrl look like this: index.php?page=test1 Now what I want is to only get a variable with "test1". Thast means I want to extract the page=test1 out of the selectUrl... Is this possible...? Hi all I am new here, hopefully someone can assist me with the following... If I have ../PACKAGES/test/run.html stored in the variable myUrl and I want to extract whatever is between ../PACKAGES/ and /run.html how would I go about it? I understand that in this instance I could use: var actualUrl = myUrl.slice(12,16); but the length of the string is dynamic, the only parts that stay the same are the start (../PACKAGES/) and end (/run.html). I am new to java-script, so please be kind...any assistance would be much appreciated. I'm sure this is probably a simple question, but I'm going to ask anyway. I need to extract part of a URL and place it into a variable for use elsewhere on the page. The part to be extracted will be of varying lengths. As an example, if I have the following URL: http://more.stltoday.com/stltoday/st...e?OpenDocument I need to extract "SS". Basically, anything that appears between "static.nsf/" and "/Steve's_APT_test_page". That value needs to be put into a variable and called elsewhere on the page. For testing purposes, I'm using the following code, just to see if it works (which, so far, it doesn't): Code: <script type= type="text/javascript" language="javascript"> var page_url = window.location.href; var segments = page_url.split("/"); alert(segments[4]); </script> Can anyone help? Thanks, Steve 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? I have the following code that works fine: Code 1 Code: <script type="text/javascript"> AJS.AEV(window, 'load', function() { GB_show("Special Presentation", "http://www.site.net/temp/images/ads/special.jpg", 352, 600); }); </script> I also have the following code that works fine: Code 2 Code: function DoTheCookieStuff() { visited=getCookie('visited'); if (visited==null) { setCookie('visited','yes',365) MyWindow=window.open('http://www.site.com','MyWindow','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=640,height=480,left=1,top=1'); } } However, I want to replace the blue code in the Code 2 immediately above that opens the window with the red code in the Code 1 section that opens the GreyBox window. I tried the following but it's just not working: Code: function DoTheCookieStuff() { visited=getCookie('visited'); if (visited==null) { setCookie('visited','yes',365) AJS.AEV(window, 'load', function() { GB_show("Special Presentation", "http://www.site.net/temp/images/ads/special.jpg", 352, 600); }); } } Thank you. Hi, I have this PHP code that shows the amount of minutes and seconds to a certain date. Somehow I want to update this code every second so that it looks like it's counting down. Anyone who has any good pointers how to do this? Thank you in advance. Hi This is for a class project, for some reason only the first part is working. The (sales*.20) and all of my else if are not. Kind of stuck on this. Code: <script type="text/javascript"> function bonus() { var sales var excellent var good var fair var poor sales= document.workBonus.txtSales.value; sales= parseInt(sales); excellent= document.workBonus.chkExc.value; good= document.workBonus.chkGood.value; fair= document.workBonus.chkFair.value; poor= document.workBonus.chkPoor.vaule; if (sales && excellent) { alert(sales * .20) } else if (sales && good) { alert(sales * .10) } else if (sales && fair) { alert(sales * .05) } else if (sales && poor) { alert(sales * .01) } } </script> Hello I needed an interdependent form for my website and found a JavaScript that would do the trick. Now i have no knowledge in JavaScript but i managed to set this up right. But i seems some part of the script makes a popup window which is showing what is chosen in the form and i reeeally want to remove that Can anyone pick out which piece of the script i need to remove? Thanks in advance Code: var ss2Values = [ // 'Please choose a subject' ['Please choose a category'], // '3D Printer' ['Please choose a category', 'Darwin', 'Huxley', 'MendelMax', 'Original Mendel', 'Printrbot', 'Prusa Mendel', 'Wallace', 'Upgrades'], // 'Home' ['Please choose a category', 'Bathroom', 'Bedroom', 'Decorations', 'Furniture', 'Home utilities', 'Household items', 'Kitchen', 'Livingroom', 'Outdoor', 'Spareparts'], // 'Mechanical' ['Please choose a category', 'Gears', 'Nuts and bolts', 'Tracks and bogies'], // 'Electrical' ['Please choose a category', 'Battery boxes', 'Terminal blocks', 'Outlet boxes'], // 'Electrical' ['Please choose a category', 'Architectural', 'Games', 'Ornaments', 'Toys'], // 'Educational' ['Please choose a category', 'Biological models', 'Chemical models', 'Mathematical', 'Physical models'] ]; window.onload = function() { var ss2 = new xSubSelect('sel20', 'sel21', null, ss2Values, ss2OnChange); } function ss1OnChange(s0, s1, s2) { alert( s0.options[s0.selectedIndex].value + ' / ' + s1.options[s1.selectedIndex].value + ' / ' + s2.options[s2.selectedIndex].value ); } function ss2OnChange(s0, s1) { alert( s0.options[s0.selectedIndex].value + ' / ' + s1.options[s1.selectedIndex].value ); } function xSubSelect(sSelId0, sSelId1, sSelId2, aValues, fnOnChange) { var s0 = document.getElementById(sSelId0); var s1 = document.getElementById(sSelId1); var s2 = sSelId2 ? document.getElementById(sSelId2) : null; if (s0 && s1) { s0.onchange = function() { var i, len, val; // clear existing options for s1 len = s1.options.length; for (i = 0; i < len; ++i) { s1.options[0] = null; } // insert new options for s1 len = aValues[s0.selectedIndex].length; for (i = 0; i < len; ++i) { val = aValues[s0.selectedIndex][i]; s1.options[i] = new Option(s2 ? val[0] : val); } // update s2 if (s2) { s1.onchange(); } }; if (s2) { s1.onchange = function() { var i, len; // clear existing options for s2 len = s2.options.length; for (i = 0; i < len; ++i) { s2.options[0] = null; } // insert new options for s2 len = aValues[s0.selectedIndex][s1.selectedIndex].length; for (i = 1; i < len; ++i) { s2.options[i - 1] = new Option(aValues[s0.selectedIndex][s1.selectedIndex][i]); } }; s2.onchange = function() { if (fnOnChange) { fnOnChange(s0, s1, s2); } }; } else { s1.onchange = function() { if (fnOnChange) { fnOnChange(s0, s1); } }; } s0.onchange(); // first init } } 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. I have a situation in which I have to track clicks (links etc..). The problem is, I have a larger div ie - parentDiv - like 300px height, 400px width - approximate. This div has a background image. Now, the issue arises because over this div (parentDiv), I have another div "announceDiv" on top of it showing information. I ONLY want the parts of parentDiv that is NOT covered by announceDiv to be clickable. Just to reiterate, I have a big div that I want clickable (so I can add a link to the click), but over this big div I have a smaller div showing content ie, information, that links to its own stuff. BUT I want to be able to link from this background image that is in the parentDi without affecting when I click in the smaller div that is superimposed over it. any ideas? has to work in ie6+ and ff 3+ I'm newbie to javascript. I'm trying to print a web part in landscape orientation. I want to include CSS in java script and change the layout of the page. Here is the print code Code: function printWebPart(tagid) { if (tagid) { var html = "<HTML>\n<head>\n"+ $("HEAD").html()+ "\n</head>\n<body >\n"+ $("#"+tagid).html()+ "\n</BODY>\n</HTML>"; var printWP = window.open("","printWebPart"); printWP.document.open(); printWP.document.write(html); printWP.document.close(); printWP.print(); printWP.close(); } } </script> and here is the css class : .landScape { width: 100%; height: 100%; margin: 0% 0% 0% 0%; filter: progid:DXImageTransform.Microsoft.BasicImage(Rotation=3); } Please suggest how do i do this? Hi For our new site we need to regularly update part of page. What solutions are there for this purpose?? Hi, The Problem I am trying to create a Google Translate widget on my webpage, with just one language pair, Latin to English. Unfortunately the Google Translate AJAX API only supports a subset of all languages available, and Latin is not included. However, Latin IS included on the Google Translate website. Apparently languages that are in beta are available there, via a different server, while only fully released languages are available via the AJAX Translate API. My Attempts at Solutions a) I wrote a script that generated the XMLHttpRequest() call to the server the Google Translate website uses, but it always returned a '0' status code. I have since found out that this is normal, as these kinds of calls can only be made between pages on the same server. b) I then wrote a script that created a popup, and used the baseURL+params for the URL, , and this produced a pop-up window containing the translation result. However, as that page came from a different server to the server containing the script, I could not access the results on it. The code for that is he Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,locationbar.visible=false,status=0,menubar=1,resizable=0,width=500,height=400,left = 710,top = 400');"); window.focus(); } // End --> </script> </head> <body> <form> <input type=button value="Open the Popup Window" onClick="javascript:popUp('http://translate.google.com/translate_a/t?client=t&q=vicecomes&sl=la&tl=en&pc=0')"> </form> </body> </html> c) So, in final desperation I wrote a small script with an IFrame in it that shows the Google Translate webpage, using this code: Code: <iframe name="frame1" src="http://translate.google.com/?sl=la&tl=en#la|en|" frameborder="0" scrolling="auto" style="width:100%;height:280px;"></iframe> The result can be seen here (click on the Latin-Help tab): http://www.blanshard.org/ Not too bad. Now I would like to just to tidy this up (until Latin comes out of beta and is moved to the Google Translate AJAX API server) I would like to move the Google Translate page up a few px so that the top menu does not show, and disable the scrollbars, so I am just framing the Translation box and result area. It appears that the top-left corner of the called page always aligns with the top-left corner of the IFrame, but I want to add offsets. Is it possible to offset the called page anywhere within the IFrame so I can frame just the part I want? Thanks for any help, Wibs http://phplist.xxmn.com/menu.html When the mouse hover on the navigation (cpanel). it shows the corresponding content under it. but i can't click the link in it. is there a way to get it.i know it will be using setTimeout. but i don't know how to do. thank you. when i change the top value small.but under IE7 and IE6.i still can't click the link in the showing content. |