JavaScript - Replace Text Throughout Page
Hello, how do I replace text throughout a page?
I would like to replace: Code: <IMG SRC="../template/wysiwyg/uploads/image1.jpg"> with: Code: <IMG SRC="template/wysiwyg/uploads/image1.jpg"> removing the: Code: ../ throughout the whole page. Thank you! Similar TutorialsI need to replace the captions with simple text for download speed purposes. This is controlled by a piece of Javascript written for me. I need to change the caption image for a text one. The site is here Frank alias effpeetee. So I have a site, It has a few paragraphs. When a customer presses a href, or a navigation link, I want that block of text to change to a different set of paragraphs. For instance Ive got a Div set for the main block of text with general information. When they click a link at the top, I want this text to change to something else, without having to reload the entire page or create a completely new HTML file. I have read on innerhtml and setting particular elements but I cant find any good online resources for using a simple link rather than a button to change a block of text In essence Set block of text to be element "old text" Set block of new text to be element "new text" ( all the while not showing this text on the page until the link is pressed) Classify href as trigger to replace old text with new text. BAM, victory! Any help would be greatly appreciated. Hello, I want to replace the text headings with images. I have tried adding an 'img scr' tag but then the menu won't expand. I got the code from here The JavaScript Source: Navigation : Expanding Menu I would appreciate any help. Im working on a 2nd case and I could use some help I need to replace the content of the welcome box Code: <div id="welcome"> Today is<br /> Tuesday, May 29, 2007 <br /><br /> Born today<br /> Ian Fleming (1908) - Author </div> with generated text that displays the current date, and the name of a famous person born on that date. Including comments that describe each of the variables used in writing this code and the functions that the code accesses. How to get this to work? Code: <html> <body> <script type="text/javascript" src="01.js"> <h1>Welcome</h1> <a href="#" onclick="write(); return false;">Click here</a> <div id="info_here"> </div> </body> </html> 01.js Code: function write() { var a=document.getElementById("info_here"); a.innerHTML=document.write("Hello <br />" + "Thanks for clicking"); } I'm trying to find a script that will replace all instances of HTML code within a page. I saw the Javascript replace method. How can I leverage this on my page to replace every instance of a certain piece of code? Pretend this is a <div> in my page: <div style="width:340px;">Try this code out.</div> How could I convert all instances of this code to: <div style="width:340px;">Try this testing stuff.</div> Thanks for any help! Hello I have this snippet for controlling the number of characters entered in a textarea. It works. But, if I replace in this code the name "my_form" by "contact-form" and "my_text" by "message", it doesnt ! It looks like the keyword is " my_form ". You change that , and the script will not work! It turns out that I have to change those names because the form as it was already had those names my_form and message before I added this counter And I dont want to replace the names of the form in order to adapt them to this code snippet below. The question is why would the script not work if I have just replaced two words, which dont seem to be keywords of JS programming (my_form and my_text) <html><head> <title>(Type a title for your page here)</title> <script language=JavaScript> <!-- function check_length(my_form) { maxLen = 50; // max number of characters allowed if (my_form.my_text.value.length >= maxLen) { // Alert message if maximum limit is reached. // If required Alert can be removed. var msg = "You have reached your maximum limit of characters allowed"; alert(msg); // Reached the Maximum length so trim the textarea my_form.my_text.value = my_form.my_text.value.substring(0, maxLen); } else{ // Maximum length not reached so update the value of my_text counter my_form.text_num.value = maxLen - my_form.my_text.value.length;} } //--> </script> </head> <body> <form name=my_form method=post> <textarea onKeyPress=check_length(this.form); onKeyDown=check_length(this.form); name=my_text rows=4 cols=30></textarea> <br> <input size=1 value=50 name=text_num> Characters Left </form> </body> </html> Hi all, Thanks for reading. I'm having an issue trying to accomplish the following - I have a text field (field1) already displayed on the HTML page. However, there's a link where you can add additional text fields to the page as well. When the link is clicked, the second text field is added successfully (field2), and when the link is clicked again, the third text field (field3) is added successfully. However, the third field does not add itself to the page, and the text for anything greater than a third field also isn't displayed after. This obviously means that my "fields" variable is not working right, so I'm wondering, would anyone be able to assist me to help me get that variable processing correctly? Code: <script language="javascript"> fields = 1; function addMore() { if (fields = 1) { document.getElementById('addedMore').innerHTML = "<input type='text' name='field2' size='25' /> <span>Field 2.</span>"; fields = 2; } else if (fields = 2) { document.getElementById('addedMore').innerHTML = "<input type='text' name='field3' size='25' /> <span>Field 3.</span>"; fields = 3; } else { document.getElementById('addedMore').innerHTML = "Only 3 fields are allowed."; document.form.add.disabled=true; } } </script> Here is the code in my HTML - Code: <input type="text" name="field1" size="25" /> <span>Field 1.</span> <div id="addedMore"></div> <p class="addMore"><form name="add"><a onclick="addMore()">Add another field.</a></form></p> Thank you very much. i am trying to make an online graphing calculator with javascript. dont ask how because i dont know. but there is an annoying error in a do...while loop. although it should break out of the loop when the |'s (absolute value signs) are replaced with Math.abs( and ). here is the code. Code: var initec = function(){ var rg = { } ; rg.matc = false; rg.i = 0; rg.change = function(equ){ if (typeof(equ) != "string"){ alert('Equation must be a string'); return; } alert("starting equation: "+ equ); rg.i = 0; do{ rg.matc = equ.match(/\|/); if(rg.i === 0){ equ.replace(/\|/, " Math.abs("); rg.i = 1; alert("1 "+equ); } else { equ.replace(/\|/, " ) "); rg.i = 0; alert("0 "+equ); } }while(rg.matc) alert("finished equation: " + equ); } return rg; } rg=initec(); rg.change("|8/x+7|-2"); the last 2 lines and the alerts are for debugging. as you can see, it is not finished. but still, it should work. Hi there, I've been searching for an answer to this for the last few days but with no luck, so I thought I'd register here to see if anyone can possibly help. All I've been able to find everywhere for this is examples of changing images when rolling over them or clicking them, and I don't need that. What I need is a bit of javascript that will recognise some image paths on a page and replace those image paths with other ones. It's for an ecommerce website on a certain platform, using a customer reviews section which outputs star images based on the customer's rating. So, the images used (which look awful) are, for example, "sourcehere/stars_5.gif", "sourcehere//stars_4.gif", and so on. Just 5 of them. I want to design my own 5 images, upload those images, and then have the javascript replace the rubbish looking ones on the page with my own images. I thought I'd be able to find something quite easily, but so far all I can find is examples of mouseover events and so on, and I don't need any of that, just the entire image replaced with my own image. Can anyone help please? I'm a beginner with javascript so I'll need it spelled out to me! Thankyou for your time. How do I make it so that typing into a text box and hitting a button will take me to a different page and populate a text box on that page with the text from the previous page?
While on vacation I've been writing a bunch of javascript/css text effects for fun and I'm planning to look into how I can implement my code inside a url. So now I want to know how I can recognise and grab the text from any random webpage and put it inside of a variable, my script can take it from there.
Hi, I would like to adapt this script to make it so that when the user selects something in the dropdown, it changes the text within a div (for example, but so i can have formatting) this is because i want to have html in the text that appears (instead of it being in a textarea) ive been trying to get this to work but not with much luck thanks for any help! Is there a way to pull a text off a certain div on a page, and put it into a javascript string? I'm certain that the field has a particular name and id that I can use, if need be.
Just wondering if there is a way to scan a page for strings of text where the combined text has more than 6 concurrent numbers and then highlight that particular string? I work backend on a project and i have to watch for strings in which if there is more than 6 numbers in a row have to be deleted. The HTML of the backend for one string looks like this: Code: <tr class="row2"><th><a href="7457301/">7457301</a></th><td class="nowrap">May 19, 2011, 10:59 a.m.</td><td class="nowrap">May 19, 2011, 10:59 a.m.</td><td>asdf485920</td><td><div class="jquery-buttongroup"><input type="radio" id="form-1-status_A" name="form-1-status" value="A" /><label for="form-1-status_A">Approved</label><input type="radio" id="form-1-status_I" name="form-1-status" value="I" checked="checked" /><label for="form-1-status_I">Inactive</label><input type="radio" id="form-1-status_D" name="form-1-status" value="D" /><label for="form-1-status_D">Deleted</label></div></td><input type="hidden" name="form-1-kid_id" value="7457301" id="id_form-1-kid_id" /></tr> The part i want to search though is the name part <td>asdf485920</td> and not the account number <a href="7457301/">7457301</a> Good Morning all I have a code that worked and i messed something up trying to add on to it and i cant figure out what i did I have a form for gift certificates (giftcerticate.html)user enters to: amount: from: then can choose a gift card to include with it. to do so they click a link that sends them to another page (giftcards.html) with a group of radio buttons. they choose a radio button where the result is to be sent back to the first page (giftcerticate.html) and place the result in a text box with a sample of the giftcard image. My issue is that when i go back to the first page it does not pass any of the values to the textboxes. it does show the the text box id's in the URL but no values or place them in the boxes. here is what it sends in the url: http://www.allyscandle.com/index/GIF....html?product1[]2=&product1[]=&price1=&giftcardstocknumber=BBA+-+003&submit=CARD+STYLE+CHOOSEN here is the script: <script type="text/javascript"> function getURI(string,parm) { var url = location.href; // Get the current URL var gsn = (location.href.split('giftcardstocknumber=')[1].split('&')[0]).replace(/\+/g,' '); var img = (location.href.split('img=')[1]).replace(/\+/g,' '); document.getElementById('gsn').value = gsn; document.getElementById('gsn-img').src = 'GIFTCARDS/'+img; } window.addEventListener?window.addEventListener('load',getURI,false):window.attachEvent('onload',get URI); </script> here are the two forms http://www.allyscandle.com/index/GIFTCERTIFICATES.html http://www.allyscandle.com/index/GIFTCARDS.html any help would be great i have been at this for a week now I'm writing a calculator script that will need user input (how much they pay on internet, phone or cable bill) and then multiply those numbers by a known rate and then show the customer the new number. I have the math setup (working right now), and the script works to spit out the answers in an alert. Instead of the alert (which is the only thing I can do correctly at this point), I need the script to give the answers for each bill and then a total answer at the bottom. The script is here, it's all in the index file. http://gotsmith.com/calculator/ Thanks. Hi. Stuck on an assignment, inserting 3 files that i am working with, unable to get the unhide or move functions working. Thanks for all your help. ***Index.htm Code: 01.<html> 02.<head> 03.<!-- 04. New Perspectives on JavaScript 05. Tutorial 4 06. Review Assignment 07. 08. Avalon Books 09. Author: Rexdreamer 10. Date: 08/12/09 11. 12. Filename: index.htm 13. Supporting files: ab.gif, ablogo.gif, avalon2.htm 14.--> 15.<title>Avalon Books</title> 16.<script type="text/javascript" > //insert embedded script that uses an if statement to test for W3C DOM 17. if (document.getElementById) location.href="avalon2.htm" //if supported browser load avalon2.htm using the href prop of the location obj 18.</script> 19. 20.</head> 21. 22.<body style="background-color: black"> 23.<p style="text-align: center"> 24.<img src="ablogo.jpg" alt="Avalon Books" /><br /> 25.<img src="ab.gif" alt="" /> 26.</p> 27.</body> 28.</html> ***Avalon.htm Code: <html> <head> <!-- New Perspectives on JavaScript Tutorial 4 Review Assignment Avalon Books Author: Chris Veal Date: 08/12/09 Filename: avalon2.htm Supporting files: kids.jpg, fiction.jpg, nfiction.jpg, scripts2.js, styles2.css --> <title>Avalon Books</title> <link href="styles2.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="script2.js"></script> <script type="text/javascript"> function placeObjects() { //insert function named placeObj var w = winWidth/2; //declare variable named w that is =1/2 of the value returned by the winWidth function placeit("avalon2", W-75, 0); placeit("kids", W-75, 100); //place kids coordiantes at w75,100 placeit("fiction", W-75, 100); placeit("nfiction", W-75, 100); setZ("kids",z3) //use setZ functionto set zindex for kids object to 3 setZ("fiction",z2) //use setZ functionto set zindex for fiction object to 2 setZ("nfiction",z1) //use setZ functionto set zindex for nfiction object to 1 moveAvalon(); //call the moveAvalon function } function moveAvalon() { var x = xc if (x <= w-125); shiftIt("avalon",10); setTimeout("moveAvalon",50); } if (x > w-125) { } } function swapImages() { //insert swapimages function, purpose to change the stacking order of the 3image obj setTimeout("showIt('kids')"); setTimeout("showIt('fiction')"); setTimeout("showIt('nfiction')"); setTimeout("swapIt()", 2000); } </script> </head> <body onload="placeObjects()"> <div id="kids"> <img src="kids.jpg" alt="" /><br /> Sale this month on children's books </div> <div id="fiction"> <img src="fiction.jpg" alt="" /><br /> Fiction selection of the month </div> <div id="nfiction"> <img src="nfiction.jpg" alt="" /><br /> Non-fiction selection of the month </div> <div id="avalon"> Avalon <span id="books">Books</span> </div> </body> </html> ***script.js Code: /* New Perspectives on JavaScript Tutorial 4 Review Assignment Avalon Books Name: Chris Veal Date: 08/12/09 Function List: xCoord(id) Returns the x-coordinate of the object with id with the value id placeIt(id, x, y) Places the id object at the coordinates (x,y) shiftIt(id, dx, dy) Moves the id object dx pixels to the right and dy pixels down showIt(id) Hides the id object by setting its visibility style to "visible" winWidth() Returns the width of the interior browser window in pixels winHeight() Returns the height of the interior browser window in pixels setZ(id, z) Sets the z-index value of the id object swapIt(id1, id2, id3) Swaps the z-index values of id1, id2, id3 */ function setZ(id, z) { // create new function called setZ with 2 parameters object=document.getElementById(id); // use the value of the id parameter to select the obj in the document with that id value object.style.zIndex=z; // set the z index of the object to the z parameter } function swapIt(id1, id2, id3) { // create new function called swapIt with 3 parameters var object1=document.getElementById(id1); //getObj function to create the 3 variables named obj 1-3 var object2=document.getElementById(id2); var object3=document.getElementById(id3); var z1=object1.style.zIndex; //create 2 variables named z1-z3 set variables=to zIndex values of obj1-3 var z2=object2.style.zIndex; var z3=object3.style.zIndex; object1.style.zIndex=z3; //change the zIndex value of obj1 to z3thus moving it to the bottom of the stack object2.style.zIndex=z1; //change the zIndex value of obj2 to z1thus moving it to the top of the stack object3.style.zIndex=z2; //change the zIndex value of obj3 to z2thus moving it to the middle of the stack } function placeIt(id, x, y) { var object=document.getElementById(id); object.style.left=x+"px"; object.style.top=y+"px"; } function shiftIt(id, dx, dy) { var object=document.getElementById(id); object.style.left=parseInt(object.style.left)+dx+"px"; object.style.top=parseInt(object.style.top)+dy+"px"; } function xCoord(id) { object=document.getElementById(id); xc=parseInt(object.style.left); return xc; } function showIt(id) { var object=document.getElementById(id); object.style.visibility="visible"; } function winWidth() { if (window.innerWidth) return window.innerWidth; else if (document.documentElement) return document.documentElement.offsetWidth; else if (document.body.clientWidth) return document.body.clientWidth; } function winHeight() { if (window.innerHeight) return window.innerHeight; else if (document.documentElement) return document.documentElement.offsetHeight; else if (document.body.clientHeight) return document.body.clientHeight; } |