JavaScript - String Manipulation-url
Hi I have a given url and want to back up a level.
So for example if start with: url = "test/level1/level2/level3/" I would like to it remove the "level3/" to become url="test/level1/level2/" Similar TutorialsHi i was wondering if anyone might be able to help me here as i hve an idea but not quite sure how to impliment it. I want to be able to create 2 Divs, 1 for my navigation button and a second for an image to be placed in. i ant to be able to have the 2nd div move position to underneath Div 1 when i hover over the navigaton(div 1). Ive attached a link to a diagram of what i mean Any help would be very much apreciated http://spark-box.co.uk/images/ideaz.jpg I have the following code for a textbox that is supposed to change itself to 20 if the entered value is over 20, to 1 if it's less than 1, and round itself to the nearest integer Code: <input type="text" size="1" name="blevel" value="1" onchange=' document.unitselect.blevel.value++; document.unitselect.blevel.value--; document.unitselect.blevel.value = document.unitselect.blevel.value / 1 Math.floor(document.unitselect.blevel.value); if(document.unitselect.blevel.value > 20){ document.unitselect.blevel.value = 20 }else if(document.unitselect.blevel.value < 1){ document.unitselect.blevel.value = 1 } '> The textbox is in a form named "unitselect". For some reason, it just ignores the Math.floor line. After experimenting for a bit, I found out that it was treating the textbox value as a string. I tried both using the increment/decrement operators and dividing it by 1. Although the operations executed properly, it still treated it as a string after the operations. Does anyone know what I can do to round this value? I have tried to manipulate attributes in a specific class & am successful by using jquery. Now for the purpose of learning I want coders to look at my simple snippet & tell me how can I use functions namely getElementsByTagName & For loop instead of each. http://jsfiddle.net/defencedog/Zz7cX/ [My snippet adds 'fullscreen' functionality to youtube vids, which unfortunately isn't present in default phpBB3 forum engine] regards;; I have created a simple webpage that allows users to search multiple comparison shopping sites at once. This is just a side project that I am working on. At the current time, the webpage has the sites listed with checkboxes. The user can put in a search term in the box and then select which sites they want to search. The sites then open in a new window or on different tabs depending on which browser they are using. What I would like to do is find out if there is a way to have the same thing, but the sites open in the same window below the search box, like in tabbed frames. I tried doing something with the tabbed viewer script from dynamic drive: http://www.dynamicdrive.com/dynamici...bdocviewer.htm, but was unable to figure out how to get the search parameter into the url. My page can be found at http://www.imarkinteractive.com/tools/onesearch.html and all of the javascript is on the page. Does anyone know if this can be accomplished and if so, how would I go about doing it. I can run a php script on my server if that would be easier, but I would really appreciate the assistance. Thanks. Hello, I am trying to get an image to change based on a date range within an array, then display that image on a webpage, if there is no corresponding date, then display a default image. I have NEVER coded in JavaScript and need some assistance with this. Here is the array example: Code: var holiday = new Array() holiday[0] = "images/bronc.jpg" holiday[1] = "0210, 0214, images/Valentines_Pic.jpg" holiday[2] = "0317, 0317, images/St-Patrics_Day.jpg" holiday[3] = "0701, 0704, images/4th_Of_July.jpg" holiday[4] = "1015, 1031, images/Halloween.jpg" holiday[5] = "1111, 1130, images/Thanks_Giving.jpg" holiday[6] = "1201, 1227, images/Christmas.jpg" holiday[7] = "9999, 9999, images/New_Years_Pic.jpg" holiday[0] would be the default image that would display if no other images fall in the date range at the begining of each array element. Then something like get date alter date to be mmdd if date >= firstarraydate and date <= secondarraydate then set image to ********.jpg else set image to *******.jpg loop then in the body display the correct image <p><img src="image" /></p> Or something simple like that. I have searched and cannot find anything simple like that. I have tried a few available scripts for rotating banners but they always either do not work at all or they use one specific date or time and since I am not too swift with javascript, any help would be greatly appreiated. Thanks Kel Hi, I'm looking for some help, or perhaps an explaination in regards to "click & rotate" an image using your cursor with Javascript. I've seen this a couple of times on various websites and I'm wondering how difficult/expensive it is to develop such an image. I own a clothing company and what I'm looking to do is to create images on my website of a product in which the customer can click on and "rotate" to see a 360 degree view of the product. Think autocad to a degree... Is Javascript the best language to pursue for this function? I'm quite new to this department, so any help/advice is greatly appreciated. I code through Greasemonkey using Firebug on Firefox. I'm trying to write my first script using a simple function to change the appearance of my email address in Gmail. My current email address is formatted like this example: Code: firstlast@gmail.com I want the script to manipulate the text to resemble this: Code: first.last@gmail.com I've posted my script below. The Mozilla error console shows no syntax errors or warnings. JavaScript IS allowed to run and there are no restrictions of any kind that should hinder this script's ability to run. What am I doing wrong in the code? Any help would be greatly appreciated! Code: (function () { var loadOldName = window.document.body.getElementById('loading').getElementsByClassName('msg').textContent('\nLoading+ firstlast@gmail.com…\n'); var topLeftName = window.document.getElementsByClassName('cP').getElementsByClassName('bB').getElementsByTag('u').innerHTML('<b>firstlast@gmail.com</b>'); var topLeftDrop = window.document.getElementsByClassName('cP').getElementsByClassName('J-N-Jz').innerHTML('<span class="Qu L4">firstlast@gmail.com (default)</span>'); function changeName() { if(loadOldName) { window.document.body.getElementById('loading').getElementsByClassName('msg').removeChild(textContent('\nLoading+ firstlast@gmail.com…\n')).appendChild(textContent('\nLoading+ first.last@gmail.com…\n')); }; if(topLeftName) { window.document.getElementsByClassName('cP').getElementsByClassName('bB').getElementsByTag('u').removeChild(innerHTML('<b>firstlast@gmail.com</b>')).appendChild(innerHTML('<b>first.last@gmail.com</b>')); }; if(topLeftDrop) { window.document.getElementsByClassName('cP').getElementsByClassName('J-N-Jz').removeChild(innerHTML('<span class="Qu L4">firstlast@gmail.com (default)</span>')).appendChild(innerHTML('<span class="Qu L4">first.last@gmail.com (default)</span>')); }; }; changeName(); }); Greetings. It has been a long while since I have needed to code and a lot has changed. I am looking for resources on how to use JavaScript to When a button is pressed it moves the playhead of a single video to an assigned frame or timestamp in the video and begin playing. Then when the playhead reaches its destination it stops. I have done this in Flash before using AS1 and simple keyframe based commands and buttons for goToandPlay and stop. Is there any good reading to be had on the interwebs on this topic? Thanks in advance!! Hello everyone, I am trying to make a canvas element display an image with some text on using canvas.drawImage and canvas.fillText. Only problem is my code is generating a very odd and hard to debug error. Thanks in advance, Alex Code(JS): Code: function runstuff() { canvasthing = document.getElementById('1'); context = canvasthing.getContext('2d'); purple = new Image(); purple.src = 'img/buttonpurple.png'; purple.onload = function() { context.drawImage('purple', 0, 0); }; context.font = '16px Vani'; context.textBaseline = 'top'; context.fillText('Test', 26, 24); } Code(html): Code: <!doctype html> <html lang="en"> <head> <title>POB.G</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="style.css"> <script type="text/javascript" src="script.js"> </script> </head> <body onload="runstuff()"> <canvas id="1" width="127" height="128"></canvas> </body> </html> Error: Code: Error: uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMCanvasRenderingContext2D.drawImage]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: file:///C:/Users/*BlahBlahBlah/script.js :: <TOP_LEVEL> :: line 7" data: no] Ok, first off I would like to say hi to everyone as this is my first post! Now that we have been introduced, here is my problem. I am trying to create a billing system in which you generate invoices. The way I am going about this is using a table with rows for each item the user is placing on the invoice. I have a script that adds new rows to the table when the user wants to place more than one item on the invoice, thats all fine and dandy. The problem is that I also want to be able to delete any row of the table at any time so that the user can remove items as well. When the user presses the attached "delete" button on the row they wish to remove the delete script gets the table length and changes the id and name of every item in the rows below the one being deleted so that when I submit the data as a form it will have a predictable pattern for getting the post variables. At the moment the script runs fine the first time and does exactly what it is supposed to. The issue is that the second time you run it after it has changed the id and name values for the delete button elements on the lower rows it only makes it to the first alert() call! I have been pulling my hair out for days!!!!! Here is the Code: Code: function getEl(element) { var object = null; if (document.layers) { object = document.layers[element]; } else if (document.all) { object = document.all[element]; } else if (document.getElementById) { object = document.getElementById(element); } return object; } function addRow() { var tbl = getEl('invTbl'); var lastRow = tbl.rows.length; // if there's no header row in the table, then iteration = lastRow + 1 var iteration = lastRow; var row = tbl.insertRow(lastRow); var cellqty = row.insertCell(0); var qty = document.createElement("<input type='text' name='qty_"+iteration+"' id='qty_"+iteration+"' size='4' value='1' onChange='javascript:updatePrice();' />"); cellqty.appendChild(qty); var cellitm = row.insertCell(1); var itm = document.createElement('input'); itm.type = 'text'; itm.name = 'itm_' + iteration; itm.id = 'itm_' + iteration; itm.size = 30; cellitm.appendChild(itm); var celldsc = row.insertCell(2); var dsc = document.createElement('input'); dsc.type = 'text'; dsc.name = 'dsc_' + iteration; dsc.id = 'dsc_' + iteration; dsc.size = 50; dsc.value = iteration; celldsc.appendChild(dsc); var cellprc = row.insertCell(3); var prc = document.createElement("<input type='text' name='prc_"+iteration+"' id='prc_"+iteration+"' size='9' value='1.00' onChange='javascript:updatePrice();' />"); cellprc.appendChild(prc); var celldel = row.insertCell(4); var del = document.createElement("<input type='button' name='"+iteration+"' id='"+iteration+"' value='Delete' onClick='javascript:removeRow(this.id);' />"); celldel.appendChild(del); } function removeRow(row) { alert("you are deleting row " + parseInt(row)); tbl = getEl('invTbl'); rowTotal = tbl.rows.length; alert("there are " + rowTotal + " rows!"); tbl.deleteRow(parseInt(row)); for ( i = 1; i < rowTotal; i++ ) { if ( i > parseInt(row) ) { place = i - 1; alert(i + " becomes " + place); qtycontainer = "qty_" + i; itmcontainer = "itm_" + i; dsccontainer = "dsc_" + i; prccontainer = "prc_" + i; delcontainer = i.toString(); buttonchange = place.toString(); getEl(qtycontainer).name = 'qty_' + place; getEl(qtycontainer).id = 'qty_' + place; getEl(itmcontainer).name = 'itm_' + place; getEl(itmcontainer).id = 'itm_' + place; getEl(dsccontainer).name = 'dsc_' + place; getEl(dsccontainer).id = 'dsc_' + place; getEl('dsc_'+place).value = getEl('dsc_'+place).id; getEl(prccontainer).name = 'prc_' + place; getEl(prccontainer).id = 'prc_' + place; getEl(delcontainer).name = buttonchange; getEl(delcontainer).id = buttonchange; alert("del button changed to " + getEl(i).id); } } // updatePrice(); } The button element for each row calls javascript:removeRow(this.id); Please help me figure out what I am doing wrong! Hey all, I have a simple example below showing how when I pass in the value of the value attribute of option node, and then use if operator to check whether parameter is a string or not, even though it's a string, it converts it to false boolean and triggers the else statement rather than calling a function: Code: <body> <select> <option value="createMsg">Add Message</option> <option value="removeMsg">Remove Message</option> </select> </body> Code: var menu = { handleMenu : function(callback){ if(callback === "string"){ menu[callback](); } else { console.log("Issue occurred") } }, createMsg : function(){ var content = document.createTextNode("Please give additional information."), heading = document.createElement("h1"); heading.appendChild(content); document.body.appendChild(heading); }, removeMsg : function(){ } } document.getElementsByTagName('select')[0].onchange = function(){ menu.handleMenu(this.value)}; callback should be a string so why is it saying otherwise? Thanks for response I was looking at this page, and came across "%" used in strange context. It appears that the mod operator can be used in Strings?? http://download.oracle.com/javase/tu...vaOO/enum.html What does this do/ mean? Thanks!!: System.out.printf("Your weight on %s is %f%n", p, p.surfaceWeight(mass)); I am trying to use some string functions with no results. It appear what I'm using them on are not strings. my_string = document.getElementById("link5").onclick; document.write(my_string.lastIndexOf("5")); This gets nothing! And document.write(document.getElementById("link5").onclick.lastIndexOf("5")); gets nothing. BUT if I make a string and put what the onclick is set to with: my_string = "function onclick(event) { reveal(\"5\", \"2\", \"1864\")"; then my_string.lastIndexOf("5") will yield 34. So why is my original my_string = not working? And how can I get it to work? I need help with the following code below. It just doesn't turn out okay. Any ideas? Code: function changing() { A = document.exempel.Amount.value B = ("<%#Container.DataItem("Price_2_qty")%>") C = ("<%#Container.DataItem("Price_3_qty")%>") D = ("<%#Container.DataItem("Price_4_qty")%>") E = ("<%#Container.DataItem("Price_5_qty")%>") if (A < B) {document.exempel.Price.value = "<%#Container.DataItem("Price_1")%>"} else if (A = B && (!(A >= C))) {document.exempel.Price.value = "<%#Container.DataItem("Price_2")%>"} else if (A = C && (!(A >= D))) {document.exempel.Price.value = "<%#Container.DataItem("Price_3")%>"} else if (A = D && (!(A >= E))) {document.exempel.Price.value = "<%#Container.DataItem("Price_4")%>"} else if (A >= E) {document.exempel.Price.value = "<%#Container.DataItem("Price_5")%>"} } This is probably easy if I knew Javascript. Can someone show me the code to get the number "800014352" part from the url???? http://testebiz/ebizbtest/ShoppingCa...2/Default.aspx How to handle String in Javascript
Hello, I need your help. Let's say for example if I have the following file number: 2011-1234567 and if the value of the variable is already the same (ie. var fileNo = 2011-1234567) how can I go about automatically adding a number at the end? ex.1.) var fileNo = "2011-1234567" if (fileNo already exists) { fileNo = 2011-1234567-2 } ex.2.) var fileNo = "2011-1234567-2" if (fileNo already exists) { fileNo = 2011-1234567-3 } ect. Much thanks and appreciation for all your help. Jay This is all php except for the java code I am struggling with. Please advise. I have tried this 2 ways and have spent hours on something that should be simple. I have a string that I am trying to display in an alert box with an onclick method 1: $mystring = "<a href=\"mysite.com\">Click</a>"; this does not work echo "<input type='button' value='Grab Code' onClick=alert('$mystring')>"; nor does this echo "<input type='button' value='Grab Code' onClick=alert('".$mystring."')>"; nor does anything I try. All I want to do is display the value of mystring in an alert box. However, this does work .. echo "<script type='text/javascript'> alert('".$mystring."');</script>"; But I cannot call this from an onclick. Any help is appreciated. Thanks JT Hi guys im new here i have a project about searching string im am going to use javascript the program should look like this. Enter first word: abcd Search in first Word: ab then pop up ab found then if i type like sdg then pop up sdg not found something like this plss how can i do that Hi, I have a string stored in a variable var = "4.25 houses". I would like to only extract the currency value, ie "4.25" from this. Is this possible? Also I would like to divide and multiply the new variable I get... does this number need to be converted or something? Thanks in advance! |