JavaScript - Javascript Encoding
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 Similar TutorialsThis 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 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??? I want to have another go at Javascript. I have several books on the subject but I find that my eyesight is a major problem. Therefore I want to try an on-line solution, preferably free. I have Googled, but there are so many that I am almost dizzy with the choices. Perhaps someone could recommend one. Not too fussy visually. My knowledge is VERY basic. Frank Hello! I am trying to find a script that allows you to open multiple browser tabs and then close each of those tabs, either one by one or all at once. Does anyone know how to do this please? Thanks so much for your help. Does anyone know how to make URL links that use Javascript still work when users have Javascript disabled on their browser? The only reason I'm using JS on a URL is because my link opens a PDF file, and I'm forcing it not to cache so users have the latest version. I tried the <script><noscript> tags, but I'm not sure if I'm using it correctly, as my URL completely disappears. Below is my HTML/Javascript code: <p class="download"> <script type="text/javascript">document.write("<span style=\"text-decoration: underline;\"><a href=\"javascript:void(0);\" onclick=\"window.open( 'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache='+ Math.floor( Math.random()*11 ) );\" >The Child Magazines Media Kit</a></span> (PDF 1 MB) ");</script> <noscript><span style="text-decoration: underline;"><a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf" >The Child Magazines Media Kit</a></span> (PDF 1 MB)</noscript> </p> Thanks for any help, Michael Hi, I have the following code snippet: test.html ====== <script language="javascript" type="text/javascript"> var testVariable = "test"; </script> <script language="javascript" type="text/javascript" src="test.js"> </script> test.js ===== var testVariable = window.top.testVariable; In firefox, I'm able to access testvariable defined within test.html in test.js. But in chrome, test.js couldnot get the window.top.testVariable field defined in test.html. Can any one please let me know how i can make it work in chrome?. Am i missing something here?. Hi Guys, I am new at JavaScript and start to do some tutorials.What I am trying to do here is prompting user to input a name and if the name was valid the page(document) will display with all objects like the button.But if user enter a wrong name then the button will be disabled! I create the following code but it did not work <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>New Web Project</title> <script language="JavaScript" type=""> function changeColor(){ document.bgColor = "Gray"; } </script> </head> <body> <script language="JavaScript" type="text/javascript"> var person = ""; person = prompt('What is Your Name:'); if (person == "Foo") { document.write("<h1 />Welcome " + person); document.bgColor = "Yellow"; } else { document.write("<h1 />Access Denied!!!!"); document.bgColor = "Red"; document.getElementById("gree").disabled = true; } </script> <div> <p/><input id="gree" type="button" value="Gray " onClick="changeColor();"> </div> </body> </html> as you can see I used the: document.getElementById("gree").disabled = true; but it did not work , could you please give an idea how I can solve this problem? Thanks Hey, I've got to make the values of some textboxes change the co-ordinates of my sprite on a canvas and havent a clue on how to do it, Here is my form with the two textboxes and submit button: <form> x: <input type="text" name="x" /><br /> y: <input type="text" name:"y" /><br /> <input type="submit" value="Submit"/><br /> </form> And i need it so that they change the values of these: //this shows where my sprite will start on the canvas var block_x; var block_y; searched the internet for hours and cant really find anything i understand or works. any help is much appreciated Hi Guys I am trying to modify the functionality of my page. I want to be able to activate this piece of code using another javascript function. This is the code I want to activate: Code: <script type="text/javascript"><!-- $('#button-cart').bind('click', function() { $.ajax({ url: 'index.php?route=checkout/cart/update', type: 'post', data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea, .date_data input[type=\'text\']'), dataType: 'json', success: function(json) { $('.success, .warning, .attention, information, .error').remove(); if (json['error']) { if (json['error']['warning']) { $('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.warning').fadeIn('slow'); } for (i in json['error']) { $('#option-' + i).after('<span class="error">' + json['error'][i] + '</span>'); } } if (json['success']) { $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.success').fadeIn('slow'); $('#cart_total').html(json['total']); $('html, body').animate({ scrollTop: 0 }, 'slow'); } } }); }); //--></script> And this is how I want the format of the function to be: function testsession() { if there is a session called 'hiredate' { activate the script above } else { var el = document.getElementById("product_data"); } } I just dont know how to write this in javascript Could you help me if possible please I got an index.php Code: <html> <form action="bacakomik.php" method='post'> <select name="kodekomik"> <option value='../komik1/|23'>Judul Komik1</option> <option value="../komik2/|20">Judul Komik2</option> <option value="../komik3/|10">Juduk Komik3</option> <option value="../komik4/|20">Judul Komik4</option> </select> <input type="submit" /> </form> <?php echo ('<select>'); echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); echo ('</select>'); ?> </html> As you can see, each of the option brings specific value "../komik1/|23" komik1 is a directory | is a delimiter 23 is the pages in one chapter and can be considered also as how many images are there on a specific directory This is my bacakomik.php Code: <?php $dirkomik = $_POST['kodekomik']; $exploded = explode("|", $dirkomik); echo ($exploded[0]); //picture directory echo ("<br>"); echo ($exploded[1]); //total page in the comic $pagecount = (int)$exploded[1]; //Take last posted value, process it right away echo ('<FORM name="guideform"> '); echo ('<select name="guidelinks">'); $i=1; do { echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); $i= $i+1; }while($i <= $pagecount); //Printing option and select echo ("</select>"); ?> <input type="button" name="go" value="Go!" onClick="document.getElementById('im').src=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value+'.png';"> </FORM> <img src="img0.jpg" id="im"> With the current code on bacakomik.php, I only can change the img src of id "im" in the same directory only. What I want is that the Javascript could "add" the "$exploded[0]" variable so that the picture can be loaded from different directory. Anyone can do this? I believe that the fix should be somewhere on input tag inside OnClick, or do you know where? Anyway, I found this on the net http://p2p.wrox.com/php-faqs/11606-q...avascript.html Please help me to those who can... I want to insert this js snippet Code: function addText(smiley) { document.getElementById('message').value += " " + smiley + " "; document.getElementById('message').focus(); return false; } to a loaded iframe with name&id chtifrm. I can access it & change embed something in its html via using something like: Code: $(parent.chtifrm.document.body).append('<div id=\"smly\" style=\"cursor:pointer;float:left;top:200px;display:none;position:absolute;\"><\/div>'); .... Code: parent.chtifrm.document.getElementById('chatbox_option_disco').style.display == 'none' but how do I insert js in the head of loaded iframe? All -- I have a JavaScript config file called gameSetting.js which contains a bunch of variables which configures a particular game. I also have a shared JavaScript library which uses the variables in gameSetting.js, which I include like so: <script type="text/javascript" src="gameSetting.js" ></script> <script type="text/javascript" src="gameLibrary.js" ></script> In gameSetting.js I have: $(document).ready(function() { // call some functions / classes in gameLibrary.js } in Firefox, Safari, and Chrome, this works fine. However, in IE, when it's parsing gameSetting.js, it complains that the functions that live in gameLibrary.js aren't defined. When it gets to parsing gameLibrary.js, the variables in gameSetting.js are reported as not being defined. I've tried dynamically bootstrapping the gameLibrary file using this function in document.ready for dynamic load... $.getScript("gameLibrary.js"); However, the same problem still happens in IE, where when it parses the files individually it's not taking into context the file/variables that came before, so it's not an out of load order problem. My options a 1) collapsing all the functions in gameLibrary.js and variables in gameSetting.js into one file. However, this is not practical because this is dealing with literally hundreds of games, and having a gameLibrary.js in ONE location for ONE update is what makes most logical sense. 2) figure out a way to get this to work where variables in file1 are accessible to file2 in IE (as it seems they are in other browsers). jQuery seems to be able to have multiple plugins that all refer to the based jQuery-1.3.2.js, so I know there is a way to get this to work. Help appreciated. Nero I wrote a log function that took note of various function calls. Thinking that functions are first class objects, and objects have properties, I made the name of each logged function a property of that function, e.g., brightenInnerPara.name = "brightenInnerPara"; Every browser I tried (Firefox, MSIE, Opera, Chrome, Safari) accepted the assignment, no problem. In Firefox and MSIE, the result was what I wanted: brightenInnerPara.name == "brightenInnerPara" But in the others, the result was: brightenInnerPara.name == null Question 1. Which Javascript is correct here? I favor Firefox and MSIE, not merely because they were willing to give me what I wanted, but also because it makes no sense to accept an assignment statement without throwing an error and then give it a null semantics, like Chrome, Opera, and Safari did. I found a workaround, using assignments like this: brightenInnerPara.prototype.name = "brightenInnerPara"; To my surprise, that worked in every browser. But I don't know why. It seems that such assignments are enough to cause each function to have its own distinct prototype. Question 2. Just how inefficient is my workaround, and why does it work? All, I have the following bit of CSS: Code: ul li{background:url(images/marker.jpg) top left no-repeat; background-position:0 3px; margin:0; padding-left:13px; } So basically on my page whenever there is a bullet it displays this marker. I put in the following code to make the bullet become clickable: Code: <li onclick="javascript:showdesc('This is info about bulk delivery', 'bulk');">Bulk Delivery</li><div id="bulk"></div> I then have the following javascript to handle that: Code: <script type="text/javascript"> function showdesc(desc, type){ if(type=="bulk"){ document.getElementById("bulk").innerHTML = desc; } } </script> Is there a way to incorporate CSS into the JS that will allow me to use a different image (down arrow) and make that clickable to then make the <div id="bulk"></div> not have the desc in it anymore? Thanks in advance! I'm not sure if this is a javascript error or what. The webdeveloper toolbar says I have an error on my site which reads: Error: Permission denied for <http://googleads.g.doubleclick.net> to call method Location.toString on <http://www.*******************>. and also a few more saying undefined _popupControl I can't see what the problem is. The google ads are not showing on my site and I'm guessing these errors are the cause of that. Any help with this is much appreciated. Site: durkmusicbeats . com Thanks. I want to develop JavaScript application that will match customers with a car from their available rentals. Using an HTML form, the customer will enter details such as first, last names, how many passengers and items of luggage they have, and how long they want to rent for, and the application will feedback to the user telling them which cars match their preferences and the cost of the rental. An image of each matching car should also be displayed. I therefore shown in the information below. I already created an array but I don't know how to start. Please can someone help me Thanks in advance Car Fuel Consumption (Miles per Gallon) No. Passengers No. Items of Luggage Fuel Transmission Air Conditioning Day Hire Weekend Hire Weekly Hire var Peugeot = new Array("41","4","1","Petrol","Manual","No", "20", "90", "125") |