JavaScript - Replace With All Of For Loop
Building a shopping cart, at the moment I have 1 variable array. My JS gets values from hidden inputs when add to shopping cart is clicked. The JS then pushes them all into the array in order.
I've managed to get the js code to replace innerHTML and add the array to the HTML to show the products, quantity and totals in a table. However its only showing the last product, price, and total in the array in the table. I need to get it to do this: Product: Quantity: Total: Product1 1 1 Product2 2 2 Product3 3 3 So basically I think I need to have my 3 for statements then plus 2 to each i instead of i++ to print out the products but that still doesn't solve my problem with printing every product in a vertical list, same with quantity and same with total. Heres the code Code: var cart= new Array(); function readInput(){ var prd=document.test.prd.value; var prc=document.test.prc.value; var qty=document.test.amount.value; var total= prc * qty; cart.push( prd ) cart.push( qty ) cart.push( total ); var lenp=cart.length; for(var i = 0; i<lenp-2; i++ ) { document.getElementById("product").innerHTML = cart[i]; } for(var i = 0; i<lenp-1; i++ ) { document.getElementById("qty").innerHTML = cart[i]; } for(var i = 0; i<lenp; i++ ) { document.getElementById("total").innerHTML = cart[i]; } } Code: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" type="text/css" href="css\basic.css" /> <script language="JavaScript" src="test.js"></script> <title>Shopping Time</title> <body> <form name="test"> <input type="hidden" name="prd" value="Paper"> <p class="desc" value="Paper"> Product: Paper 1</p> <p class="desc"> <input type="hidden" name="prc" value="1.99"> Price: £1.99</p> <p class="desc"> Select Quantity: <select name="amount" onchange="quantity()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select></p> <p class="submit"> <input type="button" onclick="readInput();" value="Add To Cart" /> </p> </form> <table border="1px solid black" rules="ALL" frame="void" class="cart" width="100%"> <tr> <th> <p class="cart">Product:</p> </th> <th> <p class="cart">QTY:</p> </th> <th> <p class="cart">Total:</p> </th> </tr> <tr> <td class="test"> <div id="product"> <p class="cart">Product:</p> </div> </td> <td> <div id="qty"> <p class="cart">QTY:</p> </div> </td> <td> <div id="total"> <p class="cart">Total:</p> </div> </td> </tr> </table> </body> </html> Similar Tutorialsi 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. Ok, I'm nearly pulling my hair out with this one. I have been looking at this code for two evenings now, and rewrote it 4 times already. It started out as jQuery code and now it's just concatenating strings together. What I'm trying to do: Build a menu/outline using unordered lists from a multidimensional array. What is happening: Inside the buildMenuHTML function, if I call buildMenuHTML, the for loop only happens once (i.e. only for 'i' having a value of '0'.) If I comment out the call to itself, it goes through the for loop all 3 times, but obviously the submenus are not created. Here is the test object: Code: test = [ { "name" : "Menu 1", "url" : "menu1.html", "submenu" : [ { "name" : "menu 1 subitem 1", "url" : "menu1subitem1.html" }, { "name" : "menu 1 subitem 2", "url" : "menu1subitem2.html" } ] }, { "name" : "Menu 2", "url" : "menu2.html", "submenu" : [ { "name" : "menu 2subitem 1", "url" : "menu2subitem1.html" }, { "name" : "menu 2subitem 1", "url" : "menu2subitem1.html" } ] }, { "name" : "Menu 3", "url" : "menu3.html", "submenu" : [ { "name" : "menu 3 subitem 1", "url" : "menu3subitem1.html" }, { "name" : "menu 3 subitem 1", "url" : "menu3subitem1.html" } ] } ]; Here is the recursive function: Code: function buildMenuHTML(menuData,level) { var ul; if (level == 1) { ul = "<ul id='menu'>"; } else { ul = "<ul class='level" + level + "'>"; } for (i = 0; i < menuData.length; i++) { menuItemData = menuData[i]; ul += "<li>"; ul += "<a href='" + menuItemData.url + "'>" + menuItemData.name + "</a>"; if (typeof menuItemData.submenu != 'undefined') { ul += buildMenuHTML(menuItemData.submenu,level + 1); } ul += "</li>"; } ul += "</ul>"; return ul; } Here is how the function is called initially: Code: buildMenuHTML(test,1); This is it's return value (with indentation added for readability): Code: <ul id='menu'> <li><a href='menu1.html'>Menu 1</a> <ul class='level2'> <li><a href='menu1subitem1.html'>menu 1 subitem 1</a></li> <li><a href='menu1subitem2.html'>menu 1 subitem 2</a></li> </ul> </li> </ul> 'Menu 2' and 'Menu 3' don't show up! I'm sure it's something small that I'm overlooking, but any help would be appreciated. Hi all I'm well aware that I can't post assignments here and expect an answer, however, I have been staring at this code for so long. I feel I am close to the solution (to get the correct output to the browser) but I just cannot get it to count how many moves it takes. I don't want an answer, but a nudge in the right direction would be very grateful. As you can see from the code and the output, it will attempt to write to the browser how many moves, but only '0'. Code: function rollDie() { return Math.floor(Math.random() * 6) + 1; } /* *searches for a number in a number array. * *function takes two arguments * the number to search for * the number array to search *function returns the array index at which the number was found, or -1 if not found. */ function findIndexOf(number, numberArray) { var indexWhereFound = -1; for (var position = 0; position < numberArray.length; position = position + 1) { if (numberArray[position] == number) { indexWhereFound = position; } } return indexWhereFound; } //ARRAYS that represent the board -- you do not need to change these //array of special squares var specialSquaresArray = [1,7,25,32,39,46,65,68,71,77]; //array of corresponding squares the player ascends or descends to var connectedSquaresArray = [20,9,29,13,51,41,79,73,35,58]; //VARIABLES used -- you do not need to change these //the square the player is currently on var playersPosition; //play is initially at START playersPosition = 0; //what they score when they roll the die var playersScore; //the index of the player's position in the special squares array or -1 var indexOfNumber; //MAIN PROGRAM //TODO add code here for parts (iii), (iv)(b), (v), and (vi) // start of question(iii) playersScore = rollDie(); document.write(' Sco ' + playersScore); playersPosition = playersScore + playersPosition; document.write(', Squa ' + playersPosition); indexOfNumber = findIndexOf(playersPosition, specialSquaresArray); if (indexOfNumber != -1) { document.write(', Ladder to Squa ' + connectedSquaresArray[indexOfNumber]); playersPosition = connectedSquaresArray[indexOfNumber]; indexOfNumber = -1; } document.write('<BR>') // end of question(iii) // start of question(iv)(b) while(playersPosition<=80) { playersScore = rollDie() document.write(' Sco ' + playersScore) playersPosition = playersPosition + playersScore document.write(', Squa ' + playersPosition) indexOfNumber = findIndexOf(playersPosition, specialSquaresArray) if(indexOfNumber != -1) { document.write(', Ladder to Squa ' + connectedSquaresArray[indexOfNumber]); playersPosition = connectedSquaresArray[indexOfNumber]; } document.write('<BR>'); } var countMoves = 0; while(countMoves <= 0) { document.write('You took ' + countMoves + ' moves to get out'); countMoves = countMoves + 1 } /*for (var countMoves = 0; countMoves < playersPosition; countMoves = countMoves + 1) { countMoves = countMoves + playersPosition; document.write('You took ' + countMoves + ' moves to get out'); }*/ // end of question(iv)(b) // start of question (v) /*if (playersPosition >=80) { document.write('The player is out'); }*/ // end of question (v) </SCRIPT> </HEAD> <BODY> </BODY> </HTML> Many thanks. Hello... Thanks for reading... I am getting an undefined error when i try to get a value from this array in the interior loop... Code: // This is the array I am trying to access AuditTable [0] = ["Visio Modifed date","Word Modified Date","User Status","User Comment","Last Audit","Audit Status","Audit Comment"] AuditTable [1] = ["11/23/2009 8:52:18 AM","missing","OK","user comment number 1","1/1/2009","ok","audit comment number 1"] AuditTable [2] = ["11/24/2009 12:21:19 AM","missing","Out of Date","Changes from 2008 not implemented","1/2/2009","Out of Date","needs update"] AuditTable [3] = ["11/22/2009 9:24:42 PM","missing","Incomplete","Document doesnt cover all possibilities","1/3/2009","Inadequate","needs update"] I have hard coded values and had success such as: Code: data = AuditTable[1][0] But when I put the vars associated with the loop in I get an undefined error - AuditTable[i] is undefined: Code: // produces error data = AuditTable[i][j] //Works but retrieves wrong data data = AuditTable[j][i] //Works but retrieves wrong data data = AuditTable[1][i] //Works but retrieves wrong data data = AuditTable[j][2] I must be trying to access the array incorrectly or something... I have defined all the vars, and tried many combinations, alerted the values of both vars so I can prove it is not a scope issue... Am I missing something obvious? Thanks much... Code: var reportArray=new Array(); var reportData, title, subTitle, data; for(i in parmarray)// loop thru AuditTable array and get values { title = '<div style="font-family:verdana; font-size:14px; font-weight:bold; margin:25px 0px 5px 30px">'; title += namearray[i][0]; title += '</div>'; reportArray.push(title);//Take compiled variable value and put it into array for(j=0; j < AuditTable[0].length; j++)// loop thru AuditTable array and get values { subTitle = AuditTable[0][j];//points to first row of AuditTable where the labels are data = AuditTable[1][0];//points to the current row where actual data is html = i + j +'<div style="font-family:verdana; font-size:12px; color:#696969; font-weight:bold; margin-left:30px;">'; html += subTitle; html += '</div><div style="font-family:verdana; font-size:12px; color:#a9a9a9; margin-left:30px; margin-bottom:10px">'; html += data; html += "</div>"; reportArray.push(html);// put results into array } } Hi I'm looking for a very simple script to replace one div with another. I've found a few but they seem overly complicated with features I don't need. I simply want to be able to click on a div and for it to be replaced with another div previously hidden. If someone could suggest a solution or point me in the right direction I'd really appreciate it. Thanks First of all, I don't want to replace text in a form, or on click. I'm writing up a design document in HTML, and I need an area to display code. The < and > tags won't show up, obviously, but to make it easier on the programmer, I don't want him to have to manually put in < and > for each time it shows up. I am aware that JavaScript has a replace function, but I am not familiar with JavaScript quite yet. Is there a way to have JavaScript find the < and > in a certain div, and replace it with < and > on load? I would appreciate your help so much, Its been frustrating me. I found a regular expression that will strip my string of every html tag... var stripped = htmlStr.replace(/(<([^>]+)>)/ig,""); Well, I also want it to strip every thing between parentheses, square brackets, and replace " &# 160;" with a space. It would be really cool if you could explain how to do this as well, because the stuff in the above code after "replace" confuses me. I have no idea how that's working. in the div class "done" it reads 13/34 i want to compare these to numbers like this if (13 < 34){do something()} else {return false;} so i am trying to get each number by it self to compare with. var did=m[1].getElementsByClassName("done")[1].innerText.replace(/\/.*/,"").value; this line returns 13 correctly. var need=m[1].getElementsByClassName("done")[1].innerText.replace(? ,"").value; this ? the info that i need to get for the other number. i know how to do it if it were a letter but can find the correct way being that it is a / instead. Thx Does anyone know if it it possible to automatically replace any instance of & with 'and' using javascript when someone types into a text input?
Building a javascript shopping cart for an assignment. First time using Javascript so ignore the ****ness of it please Anyway basically I need to replace the qty of an item in an array if the item has already been added to the array. if it hasn't then it adds the normal values to the array. So I assume atm that I have to run an if statement when the function Code: function readInput(prd, qty, prc){ is called that checks in the array before pushing the new values into the array if array contains product name then var id = productarrayID+1 then replace that with the new quantity read in by the form. Quantity in my array is after the product name so I assume productarrayID+1 would give me the qty id variable. So heres the steps, be they correct: 1) get product name from HTML. 2) check if array contains product name. 3) continue with adding to array if product name doesn't exist in array. 4) if array contains product name retrieve id of product name within array. 5) + 1 to the ID to the product name thus giving me the ID for the quantity. 6) run some array.replace with the new id and replace with the quantity. Just wondering if thats a year or no to how that would run. Il post my HTML code but please dont post solutions I would prefer to write the code myself but just checking if the step-by-step process would work thankyou. HTML: Code: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" type="text/css" href="css\basic.css" /> <script language="JavaScript" src="js/basic.js"></script> <title>Shopping Time</title> <body> <div id="wrapper"> <div id="header"> </div> <div id="content"> <div id="items"> <div id="column"> <img src="img/paper1.jpg"> <form name="test"> <input type="hidden" name="prd" value="Paper"> <p class="desc" value="Paper"> Product: Paper 1</p> <p class="desc"> <input type="hidden" name="prc" value="1.00"> Price: £1.00</p> <p class="desc"> Select Quantity: <select name="amount" onchange="quantity()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </p> <p class="submit"> <input type="button" onclick="readInput(prd.value, amount.value, prc.value);" name="test" value="Add To Cart" /> </p> </form> <img src="img/paper1.jpg"> <form name="test"> <input type="hidden" name="prd" value="Paper2"> <p class="desc" value="Paper2"> Product: Paper 2</p> <p class="desc"> <input type="hidden" name="prc" value="1.00"> Price: £1.00</p> <p class="desc"> Select Quantity: <select name="amount" onchange="quantity()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </p> <p class="submit"> <input type="button" onclick="readInput(prd.value, amount.value, prc.value);" name="test" value="Add To Cart" /> </p> </form> <img src="img/paper1.jpg"> <form name="test"> <input type="hidden" name="prd" value="Paper3"> <p class="desc" value="Paper"> Product: Paper 3</p> <p class="desc"> <input type="hidden" name="prc" value="1.00"> Price: £1.00</p> <p class="desc"> Select Quantity: <select name="amount" onchange="quantity()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </p> <p class="submit"> <input type="button" onclick="readInput(prd.value, amount.value, prc.value);" name="test" value="Add To Cart" /> </p> </form> </div> <div id="column"> <img src="img/paper1.jpg"> <form name="test"> <input type="hidden" name="prd" value="Paper4"> <p class="desc" value="Paper4"> Product: Paper 4</p> <p class="desc"> <input type="hidden" name="prc" value="1.00"> Price: £2.00</p> <p class="desc"> Select Quantity: <select name="amount" onchange="quantity()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </p> <p class="submit"> <input type="button" onclick="readInput(prd.value, amount.value, prc.value);" name="test" value="Add To Cart" /> </p> </form> <img src="img/paper1.jpg"> <form name="test"> <input type="hidden" name="prd" value="Paper5"> <p class="desc" value="Paper5"> Product: Paper 5</p> <p class="desc"> <input type="hidden" name="prc" value="1.00"> Price: £1.00</p> <p class="desc"> Select Quantity: <select name="amount" onchange="quantity()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </p> <p class="submit"> <input type="button" onclick="readInput(prd.value, amount.value, prc.value);" name="test" value="Add To Cart" /> </p> </form> <img src="img/paper1.jpg"> <form name="test"> <input type="hidden" name="prd" value="Paper6"> <p class="desc" value="Paper6"> Product: Paper 6</p> <p class="desc"> <input type="hidden" name="prc" value="1.00"> Price: £1.00</p> <p class="desc"> Select Quantity: <select name="amount" onchange="quantity()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </p> <p class="submit"> <input type="button" onclick="readInput(prd.value, amount.value, prc.value);" name="test" value="Add To Cart" /> </p> </form> </div> <div id="column"> <img src="img/paper1.jpg"> <form name="test"> <input type="hidden" name="prd" value="Paper7"> <p class="desc" value="Paper5"> Product: Paper 7</p> <p class="desc"> <input type="hidden" name="prc" value="1.00"> Price: £1.00</p> <p class="desc"> Select Quantity: <select name="amount" onchange="quantity()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </p> <p class="submit"> <input type="button" onclick="readInput(prd.value, amount.value, prc.value);" name="test" value="Add To Cart" /> </p> </form> <img src="img/paper1.jpg"> <form name="test"> <input type="hidden" name="prd" value="Paper8"> <p class="desc" value="Paper8"> Product: Paper 8</p> <p class="desc"> <input type="hidden" name="prc" value="1.00"> Price: £1.00</p> <p class="desc"> Select Quantity: <select name="amount" onchange="quantity()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </p> <p class="submit"> <input type="button" onclick="readInput(prd.value, amount.value, prc.value);" name="test" value="Add To Cart" /> </p> </form> <img src="img/paper1.jpg"> <form name="test"> <input type="hidden" name="prd" value="Paper9"> <p class="desc" value="Paper9"> Product: Paper 9</p> <p class="desc"> <input type="hidden" name="prc" value="1.00"> Price: £1.00</p> <p class="desc"> Select Quantity: <select name="amount" onchange="quantity()"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </p> <p class="submit"> <input type="button" onclick="readInput(prd.value, amount.value, prc.value);" name="test" value="Add To Cart" /> </p> </form> </div> </div> <div id="sidebar"> <table border="1px solid black" id="table" rules="ALL" frame="void" class="cart" width="100%"> <tbody> <tr> <th> <p class="cart">Product:</p> </th> <th> <p class="cart">QTY:</p> </th> <th> <p class="cart">Price:</p> </th> <th> <p class="cart">Total:</p> </th> </tr> </tbody> </table> <button onclick="viewshoppingcart('table')" class="button">Update Shopping Cart!</button> </div> </div> <div id="footer"> </div> </body> </html> Script: Code: var cart= new Array(); var down= 0; function readInput(prd, qty, prc){ down = down + 1; var total= prc * qty; cart.push( prd ) cart.push( qty ) cart.push( prc ) cart.push( total ); } var p = 0; var q = 1; var t = 2; var s = 3; function viewshoppingcart(id){ if(!cart[p])return; for(var i = 0; i < down; i++ ) { var tbody = document.getElementById(id).getElementsByTagName("tbody")[0]; var row = document.createElement("tr") var data1 = document.createElement("td") data1.appendChild(document.createTextNode( cart[p] ) ) var data2 = document.createElement("td") data2.appendChild (document.createTextNode( cart[q] )) var data3 = document.createElement("td") data3.appendChild (document.createTextNode( cart[t] )) var data4 = document.createElement("td") data4.appendChild (document.createTextNode( cart[s] )) row.appendChild(data1); row.appendChild(data2); row.appendChild(data3); row.appendChild(data4); tbody.appendChild(row); p = p + 4; q = q + 4; t = t + 4; s = s + 4; } down = 0; } Hi, I need function for replacing one string with some html tag (for example <div>something</div>) in web page. Tricky is that in this replacing I must ignore all text between <a> and </a>. It's look easy but I am not good in javascript.
I know how the replace method works, but I can't for the life of me figure out exactly what this replace function is doing... Can someone shed somelight for me? the g I *think* is a flag for global replacement... Code: replace(/\s/g, " "); I know that *something* is being replaced by a non-blank space, but what? How would you do a .replace for a Javascript if statment.
document.write(str.replace(/(\+|\(|\)|.|-|\/ /g,'')); feeble attempt to remove '.' '(' ')' ' ' '-' '/'and '+' I have a javascript that takes information from a form and recompiles that information into a readable shift report. The problem I am having is with returns in the textareas. I tried: Code: theReport = theReport.replace(" ","<br>" but that space puts the rest of the var on a different line and screws with the results. How can I replace a return with <br>? Code: dropDownPart.innerHTML = tmpInnerHTML; how does this tmpInnerHTML gets filled : Code: for (var i = 0; i < arr.length ; i++) { var arr1 = arr[i].split('|'); id_tezaver = arr1[0]; term = arr1[1] // if arr1[1] contains ', then ewerything after that disapears inside term, // like "bird's eyes" becomes "bird" // how to handle that ? // bad example how I get to verify that the stuff is complete inside array // term = arr1[1].replace(/'/i, /oo/); } Hi all, I have this code: Code: <input type="hidden" value="update_cart" name="ca"> <input type="hidden" value="2" name="numcart"> <input type="submit" name="submit" value="Update Cart" class="inpSubmit"> I'd like to replace this: Code: <input type="submit" name="submit" value="Update Cart" class="inpSubmit"> with this: Code: <button>blabla<button> How can I do? I know something about unobtrusive javascript but I don't know how to do it. Thank you very much I have a series of videos which must be loaded dynamically on their pages which then get loaded into an iframe. I need to be able to load these videos using variables for the width and height. It's imperative that I use variables as the sizes of the movies will be determined by the user's resolution. Here's the code I'm currently using Code: <script type="text/javascript"> var dimW = screen.width; var dimH = screen.height; var w1 = dimW.toString(); var h1 = dimH.toString(); document.write('<OBJECT ID="Player" width="'+w1+'" height="'+h1+'" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style=border:0px;">\n'); document.write('<PARAM name="autoStart" value="True">\n'); document.write('<PARAM name="uiMode" value="full">\n'); document.write('<PARAM name="volume" value="50">\n'); document.write('<PARAM name="mute" value="false">\n'); document.write('<PARAM name="URL" value="../../../videos/oracleChangeLocation_1.wmv">\n'); document.write('<embed src="../../../videos/oracleChangeLocation_1.wmv" width="'+w1+'" height="'+h1+'" autoStart="True" uiMode="full" volume="50" mute="false">\n'); document.write('</embed>\n'); document.write('</OBJECT>\n'); </script> I'm developing in xhtml so naturally, IE doesn't recognize the document.write statements and the page comes up blank in IE. It works flawlessly in FireFox (as expected). So, I need to replace the document.write statements with something else while still being able to pass variables for the movie objects height & width. I've tried this code: Code: <script type="text/javascript"> //alert("The beginning"); var dimW = window.innerWidth; var dimH = window.innerHeight; var w1 = dimW.toString(); var h1 = dimH.toString(); var theNewMovie = document.createElement('p'); var theTextOfTheMovie = document.createTextNode('<OBJECT ID="Player" width="'+w1+'" height="'+h1+'" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" style=border:0px;">\n<PARAM name="autoStart" value="True">\n<PARAM name="uiMode" value="full">\n<PARAM name="volume" value="50">\n<PARAM name="mute" value="false">\n<PARAM name="URL" value="../../../videos/oracleWelcome_1.wmv">\n<embed src="../../../videos/oracleWelcome_1.wmv" width="'+w1+'" height="'+h1+'" autoStart="True" uiMode="full" volume="50" mute="false">\n</embed>\n</OBJECT>\n'); theNewMovie.appendChild(theTextOfTheMovie); document.getElementById('mediaPlayer').appendChild(theNewMovie); </script> . I then have a <td> with the id of "mediaPlayer" but nothing is showing up. Most likely because I'm still fairly new to javascript and am probably forgetting or overlooking something. Can anyone give me any ideas, suggestions, or pointers as to what I am doing wrong? Thanks! M I've got a form textarea on my site, which after being submitted is stripped by my php file. Then my javascript kicks in and does some analysis of the entered text. However everytime the user entered a hard return within the textarea my javascript gives me an error 'tekenreeks niet afgesloten' which means something like 'string is not closed'. Therefore I decided to replace all occurences of chr(10) and chr(13) with ok2 (just some random characters), I did this with php which worked fine, and I didn't get the javascript error. However I need to reshow the entered text (original) to the user, so I need to restore the old values. I tried Code: result.waarde.replace('ok2', 'chr(13)'); but it doesn't work, as it still displays ok2. I'm no expert in javascript, but how can I replace those characters by the hard returns? Oh yeah I'll show some more coding, perhaps the error can be found the Code: result.waarde.replace('mdw', 'chr(13)');container.innerHTML = result.waarde; and in my html: Code: <div id='waarde' style="width:500px;"></div> I am trying to fix some datetime strings so I can convert form values into date objects so I can compare the dates in my validation process. the date time strings look like - 7/21/2011 8:00am for some reason the am is not being replaced by " am" . here's the function Code: function ampm(str){ str.replace(/am/gi," am") str.replace(/pm/gi," pm") return str } for example the result of ampm("8:00am") is 8:00am and not 8:00 am .. it seems so simple. |