JavaScript - Extracting Data From .getcontext('2d')
I'm trying to get some average rgb values from an image in one canvas object and apply them via fillstyle to a rectangle in another canvas object.
I have a dropdown that loads an image onChange()="ChangeBaseWood()" into a canvas object. The second canvas object is to be filled with an average color based on the content of the first canvas onClick="GetBaseColor()". For simplicity I've replaced the for loop with just the values of pixel 0,0. Where I think I am assigning the rgb values, the error console keeps reporting that var sample is undefined at the line "var redpart = sample[0]. Code: function ChangeBaseWood(){ var dropdown = document.getElementById('woodvalue'); var woodcanvas = document.getElementById('basewood'); var woodctx = woodcanvas.getContext('2d'); var woodimage = new Image(); woodimage.onload = function(){ woodctx.drawImage(woodimage, 0, 0,256,256); }; woodimage.src = dropdown.value; }; function GetBaseColor(){ var woodcanvas = document.getElementById('basewood'); var woodctx = woodcanvas.getContext('2d'); var sample = woodctx.data var redpart = sample[0]; var grnpart = sample[1]; var blupart = sample[2]; var staincanvas = document.getElementById('stainbase'); var stainctx = staincanvas.getContext('2d'); stainctx.fillStyle = 'rgb('+redpart+','+grnpart+','+blupart+')'; stainctx.fillRect(0,0,256,256); }; I've tried various things to assign the redpart,grnpart and blupart but I'm missing something basic. Many Thanks Similar TutorialsHi there... I have a question for the following code (a callback func for ajax) Code: function callBackFunctionForAddAdmin(data) { alert(data); } If we get the following alert message Quote: <result><error>the given userid is already admin.please enter another one.. </error></result> How do i extract the data inside the "error" tag?? (first checking if it exists and then if so extracting it) Hi there, I am trying to extract all of the values from the 5th column (Assignee) in this HTML table http://bugzilla.maptools.org/buglist...icksearch=test and don't know how to proceed. Is there a clever way of getting the entire col class: <col class="bz_op_sys_column"> before putting into an array. thanks, kev Hi, I have a bit of a problem and as my javascript is a rather poor I'm struggling to come up with a solution. Basically I need to split the variable "#country" into two parts and call the second half as the "this" value for '#int-dc'. Using '+' as the start point end ending at the end of the string. For instance 'this' returns 12+44 I want to split it to "12" and "+44" the latter (+44) replacing 'this' in the code below. Code: $(function() { $("#country").change(function() { $("#int-dc").val ($(this).val()); }); }); Thanks in advance. Hiya! Trying to figure out how to use javascript to extract all links on a page that have a certain class: e.g. - extract only links with a class of 'tools', ignore all other links: Code: <a href="http://www.google.com" class="tools">Search</a> <a href="http://www.tripod.com" class="grapes">Searched</a> <a href="http://www.dogpile.com">Searches</a> Any help would be appreciated, I'm guessing I probably have to use something like getelementbyclass("tools")? would it be better to place the javascript into a .js file or just place the js code somewhere else in the html? How should it look? Code: <div style="width: 225px; height: 155px; float: left; height: 16px; background-color: #000000; color: #FFFFFF; margin-left: 0px; margin-bottom: 0px; font-size: small; padding-left: 0px;"> <img alt="" src="images/news.png" height="16" width="222" /><div style="width: 225px; height: 155px; float: left;"><script type="text/javascript">// <![CDATA[if(document.layers){document.write('<ilayer id="ns4div" width="'+swidth+'" height="'+sheight+'" bgcolor='+sbcolor+'><div id="ns4div1" width="'+swidth+'" height="'+sheight+'" onmouseover="sspeed=0;" onmouseout="sspeed=rspeed"></div></ilayer>')} if(document.getElementById||document.all){document.write('<div style="position:relative;overflow:hidden;width:'+swidth+'px;height:'+sheight+'px;clip:rect(0 '+swidth+'px '+sheight+'px 0);background-color:'+sbcolor+';" onmouseover="sspeed=0" onmouseout="sspeed=rspeed"><div id="iens6div" style="position:relative;width:'+swidth+'px;"></div></div>');} // ]]></script> </div></div> Hi, I'm pretty new to Javascript, by about two weeks, I'm looking for help with a problem I have with the following.... <td title='text1;text2;text3'>text4</td></tr> I'm trying to display text1-3 in a table cell on a rotation, I have this to count through the cells to get to the relevent one... [CODE] function rotateCell() { var delayed = document.getElementsByTagName('td'); //.title.split(';'); for (var i=24;i<24;i++) [CODE] This should allow me to identify the location/cell 24 but can some one tell me how I then extract the tittle data and have them alternate within the cell? I'm not allowed to edit the HTML. Very gratefull for any help PeteW I need to extract a particular part of a string: Code: var str=(document.images('flag').src); <img id="flag" src="../../../../img/ip/041-080/049p.png"> I only want the "041-080/049" part. It needs to be read from the right, not the left because the preceding left part will vary in length. How do I approach this? Hello all, this is my first posting and I am happy to have found this forum :-) I have the following question: Is it possible to extract information which is located in a predefined area on the screen from a java platform? For example, there is java based platform which I can see on my screen. This platform contains numbers/letters. The location of these numbers/letters does not change, i.e. the script would not need to be adjusted if the field, which contains the info, would move. Lets assume the screen would look like that: 1234 I 12.20 Love I 1.30 Lake I 32.00 The info between the fields would be clearly separated. Now I would like to extract the infos from all the fields and paste the info for example in EXCEL so that I can see "Valerie12345" in .xls field A1 / 12.20 in A2 / Love in B1 etc... Does anybody of you know if that is possible to extract? Thank you very much in advance, Valerie From this string: "(EVAL)(H:somestring)Other Text here" I need to extract (H:somestring) and somestring into variables where somestring will could be and set of characters. Below is not working. Code: <script type="text/javascript"> var x = "(EVAL)(H:pines)Some other Text here"; alert(x.match(/H\:(.*?)/g)); </script> Thanks for any help or information. I have the following string "d3-23-76-546" I'm looking for a regular expression that will match everything in this string before 546 so that I can replace it with an empty string and just be left with 546. The string could be of any length and contain any number of hyphens. EDIT: Great...I already screwed up the title. It's not a div class but anchor class :s I've got previous programming experience but unfortunately none with javascript. I was hoping to get Fancybox working on my website. It actually is already but there's a small problem with dynamic varibles I haven't been able to resolve. I've described the problem in the comment line in the code section. Must be a really simple solution, after all I'm a complete js noob. Note that I've simplified the code by removing parts unnecessary in understanding what I'm after. Code: <html> <head> <script type="text/javascript"> $(document).ready(function() { var title1 = "This is title no 1", title2 = "This is title no 2", title3 = "This is title no 3"; $("a#example_video").click(function() { $.fancybox({ 'title' : 'title' + this.className.replace("video", "") // "title" should equal to "title1", "title2" or "title3" depending on which link a user has clicked. How to accomplish this? </script> </head> <body> <a class="video1" id="example_video" href= .....>Video1</a> <a class="video2" id="example_video" href= .....>Video2</a> <a class="video3" id="example_video" href= .....>Video3</a> </body> </html> Also the only reason for using classnames on anchors is to be able to distinguish between different video clips. Is there a better method I should use? Hello, I'm working on a project that involves extracting values from a series of select boxes and then working out the result. The select boxes contain the following: Code: <select name="select_Col1_Row1"> <option value="blue">Blue</option> <option value="green">Green</option> <option value="red>Red</option> </select> <select name="select_Col1_Row2"> <option value="blue" selected="selected">Blue</option> <option value="green">Green</option> <option value="red>Red</option> </select> <input type="text" name="RedSum"> <input type="text" name="BlueSum"> <input type="text" name="GreenSum"> </select> As you can see by my code, I'm early days at this and guessing the steps on the way. I tried using getElementsByTagName on the select and then on the option but had no luck with that. The code below does a wonderful job of returning blue for both select statements... Code: <script type="text/javascript"> function getElements() { var table = document.getElementById("x"); var x = table.getElementsByTagName("option"); for (var i = 0; i < x.length; i++) { var status = x[i].getAttribute("selected"); alert(status); if (status == "selected") { var statushcap = x[i].getAttribute("id"); var statusvalue =x[i].getAttribute("value"); if (statusvalue == "blue") { alert(statusvalue); } } } alert(x.length); } </script> If someone could suggest some way to map the select tag and then extract its option value to being the user selected value, I'd most appreciate it. I can probably do the rest of it. Can you extract additional information from the id of the option that is selected as I'd like to sum additional information from the user's choice. Best, John Hi, I have a div "bigPicture" which contains an image of Thai food. Image can change based on a users onclick of thumbnails. Each image as it passes through div "bigPicture" needs to have the values: price, description and Date,Time associated with it. How do I assign those values and use them later in a Shopping Cart environment. I have tried getelementbyId.innerHTML using alert to see what I can get but it is too much information. website address is http://www.kohchangbookingandinforma.../ATT/index.asp Thanks for your consideration Robby Hi, I am trying to pass data from one page to the next using a search. I have a search engine and im trying to get it to pass the data of the search to the search results page. im using this code
Code: <script type="text/javascript"> window.onload = function (){ try{document.getElementById('q').focus();}catch(e){} } function search() { var search_text = document.getElementById('q').value; window.location = '/search/'+encodeURI(search_text)+'/'; return false; } </script> and I am using this for the search Code: <form action="/search/" method="post" onSubmit="return search();"> <input type="text" id="q" name="q" value="" class="searc" style="width:350px; height:30px; font-size:18px; color:#C19051" /> <input type="submit" style="height:30px;" value="Search" class="submit"/> </form> Can anybody help me with this? Thanks Anyone that can help on this one it would be greatly appreciated... I need to make a form parses a result from column 1 of txt/csv file that has 7 columns. Column 1 is pay, column 2-7 are how many and the associated rows are the answers. In short 1 2 3 4 5 6 700 50 55 62 75 80 99 so if the customer enters i make 700 and i need 2 the result would be 55 as the output. Any idea on how to make that work with javascript? if (pay <=700 && widgets = 2) { document.write(55) elseif (pay <=700 && widgets = 1) document.write(50) is this doable and is it the easiest way to accomplish this? A minor modification to the http://smoothiecharts.org/ example. line2.append(new Date().getTime(), Math.random()); becomes line2.append(new Date().getTime(), updist()); var x = 0; function updist() { x = ("<?PHP phpread() ?>"); return (x); } <?php function phpread() { $t=$x=$y=$z=0; $fd = fopen ("/tmp/seis", "r"); // /tmp/seis is a single line that changes 20/sec $foo = fscanf ($fd, "%s", &$t); fclose($fd); $i = explode (",", $t); echo "$i[2]"; // should go: 2 7 9 4 0 -1 -8 -4 -5 2....... instead I get 2 2 2 2 2 2 2 2 } ?> ---------------- So "line2.append..." calls updist which calls phpread which works fine - once. It's as if the phpread caches the results of the read and never rereads the file. I'm snowed. Thanks Chuck Code: rownumber = 2; detailsTable = document.getElementsByName("detailsTable"); detailsRow = detailsTable.getElementsByTagName("tr")[rownumber]; name = detailsRow.getElementsbyTagName("td")[0]; address = detailsRow.getElementsbyTagName("td")[1]; address2 = detailsRow.getElementsbyTagName("td")[2]; phone = detailsRow.getElementsbyTagName("td")[3]; email = detailsRow.getElementsbyTagName("td")[4]; alert(name); I have been told if I want to get the text from each cell I can use: alert(name.firstChild.nodeValue); But I don't understand how to do this for what I am wanting to do. Here is my HTML: Code: <table border="0" name="detailsTable"> <tr> <td>a</td> <td>b</td> <td>c</td> <td>d</td> <td>e</td> </tr> </table> Hello, Im new to JavaScript and this forum, right now im looking for a simple JS script, that will get the data out from the url and print it on my webpage: http://www.asecurecart.net/server/ca...report=1&xml=1 I think it should looks like this: Mypage.htm Code: < Some JavaScript Code Im looking for> <html> Your shopping cart: <br> Items: <script type="text/JavaScript"><!--document.write(item_total)//--> </script> <br> Order Total: <script type="text/JavaScript"><!--document.write(order_total)//--> </script> </html> Any help would be very appreciated. Thanks. Html Code Code: <div id="itemStockUnit"> Qty <input type="text" size="2" value="1" class="quantity"> <select id="stockUnit" style="width:100%"> <option rel="Window1;7-10;153.00;140.24;">615W x 705H (mm)</option> <option rel="Windows2;7-10;187.00;171.09;">625W x 745H (mm)</option> <b>Delivery:</b> <span id="itemDeliveryTime">7-10</span> days <br> <small><b>RRP:</b> £<span id="itemRRPPrice">153.00</span></small> <br> <b>Our Price: <span id="itemOurPrice">£140.24</span></b> </div> JavaScript Code: <script type="text/javascript"> google.setOnLoadCallback(function() { $("#stockUnit").change(function(){ var data = ($("option:selected",this).attr("rel")).split(";"); $("#itemDeliveryTime").fadeOut().html(data[1]).fadeIn(); $("#itemRRPPrice").fadeOut().html(data[2]).fadeIn(); $("#itemOurPrice").fadeOut().html(data[3]).fadeIn(); }); }); </script> I have set data types to each option however the javascript above doesnt make it change any help? Hi guys, I'm trying to run this sample file that i got from the google docs. I want to write a stock ticker from google finances xml feed and this is a sample they had. Code: <?xml version="1.0" encoding="utf-8"?> <Module> <ModulePrefs title="hellofinance"> <Require feature="finance"/> </ModulePrefs> <Content type="html"> <![CDATA[ Hello world! Here is your portfolio:<br/> GOOG: <span id=_IG_SYM1_l></span> (<span id=_IG_SYM1_c></span>)<br/> AAPL: <span id=_IG_SYM2_l></span> (<span id=_IG_SYM2_c></span>)<br/> INTC: <span id=_IG_SYM3_l></span> (<span id=_IG_SYM3_c></span>)<br/> <script> var quote = new google.finance.Quote(); quote.enableDomUpdates( { 'GOOG' : '_IG_SYM1', 'AAPL' : '_IG_SYM2', 'INTC' : '_IG_SYM3' } ); quote.getQuotes(["GOOG", "AAPL", "INTC"]); </script> ]]> </Content> </Module> my problem is i don't know how to execute it so i can see how it works. I tried sticking this code within a php file and it returns an error on the first line for unexpected t-string. So i tried changing the extension to xml and it just displays the code but does not execute. I'm stumped. Any help is appreciated. Thanks P.S. - Yes i do have the zend gdata framework installed and running on my server and is working correctly according to their test. |