JavaScript - Problems Encoding Html As Js String
Hi,
Sorry this is probably quite a noobish question, but I have a function which accepts the parameter "screen_name". I want to include this variable within some HTML, which is the code for a Twitter. Here is the function: PHP Code: var htmlTest = "<script src='http://widgets.twimg.com/j/2/widget.js'></script>" + "<script>" + "new TWTR.Widget({" + "version: 2," + "type: 'profile'," + "rpp: 8," + "interval: 6000," + "width: 250," + "height: 300," + "theme: {" + "shell: {" + "background: '#0e428f'," + "color: '#ffffff'" + "}," + "tweets: {" + "background: '#ffffff'," + "color: '#615161'," + "links: '#0748eb'" + "}" + "}," + "features: {" + "scrollbar: false," + "loop: false," + "live: false," + "hashtags: true," + "timestamp: true," + "avatars: false," + "behavior: 'all'" + "}" + "}).render().setUser('" + screen_name + "').start();" + "</script>"; var test = "hello"; document.getElementById('dynamic-content').innerHTML = htmlTest; } </script> The function works fine when I omit the HTML and just return "screen_name" to the target <div>, but it doesn't work as above. Can anyone spot what I'm doing wrong??? Similar TutorialsI have an input box with an I.D. of "q" on my website... By entering javascript into the URL bar I can change the place holder text (client side) to say "test" javascript:void(document.getElementById('q').value='test'); Now if I wanted to make it say test (but in bold with html) how would I do that?? I tried: javascript:void(document.getElementById('q').value='<b>test'); But that won't work.. it's a string! I don't know much javascript... Thanks all! Utilising "Search" what resides at: http://www.codingforums.com/showthread.php?t=6441 appears to be closest to my problem but does not solve it. I want to use HTML Input text boxes for processing within nested functions and with the results output back to the HTML table. The code contains the HTML and Javascript. As the code stands data is reported back to the HTML table because the wanted functions have been commented out. Within the code is a note regarding the above. If I try to engage the functions add() or take() I have "NaN" returned. I have attempted to use x=Number(yy), x=parseInt(yy), but to no avail. [code]<html > <head> </head> <body> <form id="myself"> <table border="1" bgcolor="lightblue"> <tr height="25px"> <td id="ad" width="25px"></td> <td id="sb" width="25px"></td> </tr> <tr height="25px"> <td><input id="lt" type="text" value="" onChange="calc();" style="width:20px"></td> <td><input id="rt" type="text" value="" onChange="calc();" style="width:20px"></td> </tr> </table> </form> <script language="javascript"> var mm; var nn; var tot; var subt; function calc(){ var n1=document.getElementById("lt").value; var n2=document.getElementById("rt").value; var nn; var mm; nn=Number(n1); mm=Number(n2); tot=mm+nn; // comment these lines out and ad.innerHTML=tot; // activate the functions subt=Math.abs(nn-mm); // sb.innerHTML=subt; // mm and nn need to passed to the functions //add(); //take(); } function add(){ tot=mm+nn; ad.innerHTML=tot; } function take(){ subt=Math.abs(nn-mm); sb.innerHTML=subt; } </script> </body> </html> [icode] Hi, I was wondering if it's possible to capture a piece of HTML using XPath where the source is a sting rather than a document. I know how to use xPath and document.evaluate() as I've used it before on actual web pages - I just dont understand how to run it on a string of HTML. E.g. if I have this string: var stg = "<div>The best-laid schemes o' <span>mice</span> an' men</div>"; I'd like to convert this string into something that I can run the document.evaluate() on so that I can find the contents of the SPAN element (without loading the string into a real browser page). Thanks How do I replace the string "rpg" only present in between <et> tags ? Code: <et>ReplaceOnlyrpg</et> After replacement it should look like this Code: <et>ReplaceOnly</et> Any advice is appreciated. Thank you I cant figure out how to get the value of a name inputed in HTML into the following script... <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)"> <meta name="created" content="Sat, 10 Sep 2011 19:40:31 GMT"> <meta name="description" content=""> <meta name="keywords" content=""> <title>Enter golfers name</title> <!--[if IE]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <SCRIPT LANGUAGE="JavaScript" type="text/javascript" src="script1.js"></SCRIPT> <SCRIPT LANGUAGE="JavaScript"> function GetPage(){ document.write("OK") <!-- var fullname = "david park" var lab = ""; var result = fullname.toUpperCase(); var word=result.split(" "); fname = word[0] lname = word[1] alpha = lname.slice(0,1); lab = fname.concat("_") lab = lab.concat(lname) if(word[2]){ ext = word[2] lab = lab.concat("_") lab = lab.concat(ext) } var intro = "./Stats_"; page = intro.concat(alpha); page = page.concat("_golfers.html#"); page = page.concat(lab) document.write(page) <!-- window.location.pathname = page } </script> </head> <body> <center> <form action="form_action.asp" method="get"> You can enter the golfersname or select him from the above list.<br><br> <input type="text" name="fullname" /> <button type="submit" onclick="GetPage()">GO</button> </form> </center> <BR><BR><BR> This is the end </body> </html> Hi there, this is my first post. I'm very new to javascript and have been programming a "beer counter" that simply counts +1 into a text object after every click. After I got this to work I copied the code in order to make a clear button / function. I've been having problems, even though the code seems to be identical. This is likely an obvious question, pardon my inexperience. <html> <head> <title>Beer Counter</title></head> <body><script language="Javascript"> var beers = 0 var output ="" function beer() { beers = beers + 1 output = document.getElementById('output') output.value = beers } function clear() { beers = 0 output = document.getElementById('output') output.value = beers } </script> <input type='button' value='Crush' onclick='beer()'; /> Beer count:</input> <input type='text' id='output' name='output'; /><br/> <input type='button' value='Clear' onclick='clear()'; /> </body> </html> Hi I am using Django to build my website i have some data on the server side which gets passed into my templates, this data become encoded using simplejson which is django python import my data structure looks something like this (but with a few more dictionary's thrown in " : Code: archive = ({'id' :year.id, 'months' : allMonths}) encodedData=simplejson.dumps(archive) The data is successful encoded and i pass the list into an external java script file, Now i need to figure out how to decode the data inside a JS function can anybody shed some light on this or even point my in the right direction. Thanks for reading This issue is right at the cross point between the java and javascript. Basically, I want to DYNAMICALLY pass some Cyrillic characters (such as Алла Пугачева) at the runtime to the javascript function, as following: Current text encoding setting is Cp1252 in JAVA IDE. response.getOutputStream().println("<script>test('" + testCoding +"');</script>"); If the testCoding is normal latin chracter (such as "abc, xyz"), this will work, so that at the runtime, it will execute the funciton test(param) and passing the parameter, "abc, xyz" to the javascript function test(param). The frontend javascript function test(param) will further display it as: field.innerHTML = param; But if it is the Cyrillic characters (such as Алла Пугачева), it won't work. The "Алла Пугачева" will be passed as the garbage character and displayed as so. How can I in the java class DYNAMICALLY set up the encoding so that the sysytem at the runtime will acccept the Cyrillic characters. I would believe I need to setup such ancoding as UTF-8. But I do not know how to? OR, How can I process the Cyrillic characters (such as Алла Пугачева), in the javascript function so that it can be displayed properly? Thanks Scott hi, I would like your help on the following matter. I have a JavaScript file currently reading from another site xml file in (utf-8) and I would like to store those data in my database which is in SQL_Latin1_General_CP1_CI_AS. Is there any function in JavaScript that can encode (convert) text from utf-8 to SQL_Latin1_General_CP1_CI_AS or any other way to do that? Hello! I am trying to implement some JS that redirects a user after selection from a drop down box. The redirection includes a querystring so I want to use base64 to encode that. The 'goto' code below works fine if I remove the reference to the encode64 function. However when I use the encode64 function it doesn't work. So I'm guessing I have something wrong with the base64 portion. Code: <script language="JavaScript"> var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; function encode64(input) { var output = new StringMaker(); var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output.append(keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4)); } return output.toString(); } function goto(form) { var index=form.drpAccount.selectedIndex if (form.drpAccount.options[index].value != "0") { location="/billing-test.php?q=" + encode64(form.drpAccount.options[index].value); } } </script> Hi All, I need to know, how can we get character encoding in any site through coding. Actually i need to add an option in my website, in which i am entering a domain name(url of any website i.e. "http://www.yahoo.com") and through coding i have to find out the character encoding, doctype, frameset.. etc of the entered URL. OR Are there any such links which can help me out to get these parameters directly by passing the url only. Can anyone please help me out to get the parameters of any site....... waiting for ur reply`s Thanks gaurav joshi 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 favorite I'd like to modify a form on www.formsite.com (form builder app): username: testuser password: password I would like to use the nicedit.com's inline content editor's js to transform my textarea's into a richtext area. At present the nicedit editor works well in creating the richtextarea. However, the KEY point is that I would like formsite's form to pipe in the the created html and render it with the html component of formsite. Currently, the pipe function in formsite will only put out the html syntax in it's html module. action seen he http://fs8.formsite.com/testform/form1/index.html So this would be: 1. checking out my form on formsite.com 2. the script from nicedit.com is already installed in an html component. 3. changing or telling me the scripts/tags/or whatever for formsite form using formsites form builder (which allows some html/script editing). 4. changed so as to render the rich text entered on page 1 in page 2 instead of the html syntax. Any other solutions using formsite and any other richtextarea solutions would be great too! 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)); 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 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")%>"} } I'm trying to determine whether a word exists in the URL and if so, change the CSS of a div. I know how to do each task individually, but combining the two is giving me trouble. So far I have: Code: function checkSent(divname) { if(document.URL.indexOf("sent") >= 0) *document.getElementById(success).style.display = 'block'; } var sentornot = checkSent(); // If the URL contains the word, sent, then change the display of the element "success" to block I can successfully determine whether the string exists in the URL by adding an alert, but the Javascript to change the CSS doesn't work. The CSS for the div element "success" is as follows: Code: #success { display: none; } Any help is appreciated! Thanks! Edit: If needed, this is the code I used to test whether the "check URL" portion works: Code: function checkSent(divname) { if(document.URL.indexOf("sent") >= 0) { alert("found"); document.getElementById("success").style.display = 'block'; //this line doesn't work :( } else{ alert("not found"); } } Help, I can't figure out why this doesn't work. Thanks.. [CODE] 1 //==UserScript== 2 // @name Add youcalc highrise tab 3 // @namespace http://www.youcalc.com/ 4 // @include http://*.highrisehq.com/* 5 // @include https://*.highrisehq.com/* 6 // @exclude http://www.highrisehq.com/* 7 // @exclude http://forum.highrisehq.com/* 8 // @exclude https://www.highrisehq.com/* 9 // ==/UserScript== 10 11 //change to your needs 12 13 appurl1 = "http://www.youcalc.com/pubapps/1232017802730/"; 14 tabtitle1 = "Deals and forecast"; 15 appwidth1 = "830px"; 16 appheight1 = "690px"; 17 18 appurl2 = "http://www.youcalc.com/pubapps/1226931095311/"; 19 tabtitle2 = "Deals Activity Report"; 20 appwidth2 = "830px"; 21 appheight2 = "690px"; 22 23 appurl3 = "http://www.youcalc.com/pubapps/1229432659119/"; 24 tabtitle3 = "Contacts By Tag"; 25 appwidth3 = "830px"; 26 appheight3 = "690px"; 27 28 //from here, change at own risk 29 tabs = document.getElementById('Tabs'); 30 tabshtml = tabs.innerHTML; 31 32 //new tab html and JS 33 youcalcapp1 = '<iframe src=' + appurl1 + ' width=' + appwidth1 + ' height=' + appheight1 + ' style=border:none; />'; 34 youcalcapp2 = '<iframe src=' + appurl2 + ' width=' + appwidth2 + ' height=' + appheight2 + ' style=border:none; />'; 35 youcalcapp3 = '<iframe src=' + appurl3 + ' width=' + appwidth3 + ' height=' + appheight3 + ' style=border:none; />'; 36 37 putyoucalc1 = "inner_body = document.getElementById('screen_body');inner_body.innerHTML = '"+ youcalcapp1 + "';yct1 = document.getElementById('youcalctab1');yct1.className='current';yct2 = document.getElementById('youcalctab2');yct2.className='';";yct3 = document.getElementById('youcalctab3');yct3.className='';"; =========================================================^ SyntaxError: unterminated string literal 38 putyoucalc2 = "inner_body = document.getElementById('screen_body');inner_body.innerHTML = '"+ youcalcapp2 + "';yct2 = document.getElementById('youcalctab2');yct2.className='current';yct3 = document.getElementById('youcalctab3');yct3.className='';";yct1 = document.getElementById('youcalctab1');yct1.className='';"; 39 putyoucalc3 = "inner_body = document.getElementById('screen_body');inner_body.innerHTML = '"+ youcalcapp3 + "';yct3 = document.getElementById('youcalctab3');yct3.className='current';yct2 = document.getElementById('youcalctab2');yct2.className='';";yct1 = document.getElementById('youcalctab1');yct1.className='';"; 40 41 //find last tab, and put youcalc tab after 42 lasttab = 'Tags</a></li>'; 43 youcalctabs = '<li class="with_space" ><a class="" id="youcalctab1" onclick="' + putyoucalc1 + '" href="#">' + tabtitle1 + '</a></li><li class="with_space" ><a class="" id="youcalctab2" onclick="' + putyoucalc2 + '" href="#">' + tabtitle2 + '</a></li>';<li class="with_space" ><a class="" id="youcalctab3" onclick="' + putyoucalc3 + '" href="#">' + tabtitle3 + '</a></li>'; 44 tabshtml = tabshtml.replace(lasttab,lasttab+youcalctabs); 45 tabs.innerHTML = tabshtml; |