JavaScript - .js File Contains A Line That Moves An Image Improperly
Hey everyone, I'm working on a website, and I have one page that uses a forum that is supplied by tal.ki. The forum works fine, but the .js file that the forum uses is grabbing the image that I am using as my header on the page (not in the header of the html, just on top of the page) and moves it down and right from where it is supposed to be. My apologizes for the file being so long, but I have no idea which line it is that makes the image move. If needed, I have pictures of how it looks in the program that I use, vs. how it looks when viewed in a browser.
Thanks so much (in advance) for any help. Code: if (!window.chatter) { window.chatter = function() { return this; }(); } if (!window.chatter.embeds) { window.chatter.embeds = {}; } window.chatter.embed = function(host, args) { var host = host; var cid = Math.floor((Math.random())*1000000000).toString(); var default_height = 1600; var embed_url = window.location.href.split('#')[0]; var current_path = window.location.hash.substr(1); var disable_path = current_path && current_path[0] != "/"; disable_path |= (window != top); if (!current_path || disable_path) { if (!current_path && !disable_path) { location.href = embed_url + "#/"; } current_path = "/"; } if (window.gadgets) embed_url = ''; // Don't let the site change the hash window.chatter.embeds[cid] = this; handleCommand = function (cmd) { if (cmd[0] == 'ch_resize') { resizeFrame(cmd[1]); } else if (cmd[0] == 'ch_load') { if (disable_path) current_path = cmd[1]; else { current_path = window.location.hash.substr(1); if (current_path != cmd[1]) { current_path = cmd[1]; location.href = embed_url + "#" + current_path; } } } else if (cmd[0] == 'ch_unload') { if (window.attachEvent || findPosScroll('chatterframe'+cid) < 0) document.getElementById('chatterframe'+cid).scrollIntoView(true); // resizeFrame(default_height); } else if (cmd[0] == 'ch_scrollto') { window.scrollTo(0, findPos('chatterframe'+cid)+parseInt(cmd[1], 10)); } else if (cmd[0] == 'ch_delfoot'){ var a = document.getElementById(cmd[1]); a.parentNode.removeChild(a); } } if (window.postMessage) { function onMessage(e) { var cmd = e.data.split(':'); var frame = document.getElementById('chatterframe'+cid); if (frame.contentWindow != e.source) return; handleCommand(cmd); } if (window.addEventListener) window.addEventListener("message", onMessage, false); else window.attachEvent("onmessage", onMessage); } else { /* Fall back for browsers that don't support HTML5's postMessage */ var msg_seq = null; function checkMessages() { var chatter_frame = window.frames['chatterframe'+cid]; if (!chatter_frame) return; try { var bus = chatter_frame.frames.msg_frame; var hash = bus.location.hash.substr(10); } catch(e) { return; } var cmd = hash.split(':'); var seq = cmd[0]; if (msg_seq == seq) return; msg_seq = seq; cmd.splice(0, 1); handleCommand(cmd); } setInterval(checkMessages, 300); } function checkHash() { var path = window.location.hash.substr(1); if (!path) path = "/"; if (path != current_path) { current_path = path; window.frames['chatterframe'+cid].location.replace(buildURL(path)); } } if (!window.gadgets) { if (!disable_path) { if ("onhashchange" in window) { if (window.addEventListener) window.addEventListener("hashchange", checkHash, false); else window.attachEvent("onhashchange", checkHash); } else { setInterval(checkHash, 300); } } } function buildURL(path) { return 'http://' + host + path + "?" + args + "&cid=" + cid + "&eh=" + encodeURIComponent(embed_url); } function resizeFrame(height) { var el = document.getElementById('chatterframe'+cid); el.style['height'] = height + "px"; if (window.gadgets) { gadgets.window.adjustHeight(); } } function findPosScroll(id) { var node = document.getElementById(id); var curtop = 0; var curtopscroll = 0; if (node.offsetParent) { do { curtop += node.offsetTop; curtopscroll += node.offsetParent ? node.offsetParent.scrollTop : 0; } while (node = node.offsetParent); return curtop - curtopscroll; } return -1; } function findPos(id) { var node = document.getElementById(id); var curtop = 0; if (node.offsetParent) { do { curtop += node.offsetTop; } while (node = node.offsetParent); return curtop; } return -1; } //--Auto Theming: try{ var theme_args = ''; if (window.chatter_options) { if ('css_append' in window.chatter_options) { theme_args = '&cssa='+encodeURIComponent(window.chatter_options['css_append']); } else if ('css_replace' in window.chatter_options) { theme_args = '&cssr='+encodeURIComponent(window.chatter_options['css_replace']); } } if (theme_args === '') { document.write("<span id='probe"+cid+"'></span>"); var op = document.getElementById('probe'+cid); var p = op; var i = 0; var color = null; var font = null; while (i < 1000){ p = p.parentNode; if (window.getComputedStyle) { var style = window.getComputedStyle(p, null); color = style.getPropertyValue('background-color'); } else { color = p.currentStyle.backgroundColor; } if(color != 'transparent' && color != '' && color != 'rgba(0, 0, 0, 0)') { break; } color = null; i++; } if (window.getComputedStyle) { var style = window.getComputedStyle(op, null); font = style.getPropertyValue('font-family'); } else { font = op.currentStyle.fontFamily; } //ie8 no like this //delete op.parentNode.removeChild(op); if (font) font = font.replace(/['"]/g,''); theme_args = '&f='+encodeURIComponent(font) +'&t='+encodeURIComponent(color)+'&nocss=1'; } } catch(e) { } var forum_code = "<iframe id='chatterframe"+cid+"' name='chatterframe"+cid+"' src='" + buildURL(current_path) + theme_args + "' style='width:100%; height:" + default_height + "px; border:0;' scrolling='no' frameborder='0' border='0' width='100%' height='" + default_height + "'></iframe>"; document.write(forum_code); return this; }; try { if (window.location.hash.substr(0, 9) != "#msgframe") window.chatter.embed('qcx1quj3rz.embed.tal.ki', ''); } catch(e) { document.write("<div style='background-color:white; color:black';>Forum failed to load: " + e + "</div>"); } Similar TutorialsHi, I am still designing the website and want some flexibility. I am capturing the mouse clicks fine on top of an image, but the coordinates are absolute and not relative to the image. How can I capture mouse clicks relative to the image so that I can move the image anywhere in my website? Thanks! Hello. I'm trying to get a script (and an html page, I guess) to run constantly, and I'm pretty sure I should be using setInterval() to do this. But I'm not familiar enough with Javascript to know what I'm doing wrong, or what I need to fix. This is the code... Code: <html> <head> <script type="text/javascript" src="wz_jsgraphics.js"></script> <script type="text/javascript"> <!-- function initialize_field() { var jg = new jsGraphics(); var pixel_spacer = 10; var field_length = 1000; var field_width = 600; jg.drawRect(pixel_spacer,pixel_spacer,field_length,field_width); //... return jg } function main() { our_field = initialize_field(); dateobj = new Date(); current_time = dateobj.getMilliseconds(); our_field.drawString("Hello world!",current_time,500); our_field.paint(); } --> </script> </head> <body onload="main(); setInterval('main()', 250 )"> </body> </html> If I understand setInterval() correctly, this should cause the page to run the main() function every 250 seconds. And within main(), the "Hello world!" string is being drawn at some point between 0 and 1000 pixels, depending upon the number of milliseconds, so it should essentially be scrolling across the screen. But I can only get it to "scroll" if I hammer F5 to repeatedly load the page. How can I get the main() function to run repeatedly? I tried calling main() from main(), but that did not work well... Thanks for any suggestions you have! Hey guys I export data from Javascript to Xml file. I have tried several ways to break a line in xml file like document.write("<br/>"); or document.writeln(); etc, but seem it is impossible. Maybe you can give me a solution...... Look at below: XML File: <?xml version="1.0"?> <DATA> <Cust>< Select>Debit Card</Select> </Cust ><Cust>[ User>Jan</User ></Cust> <DATA> I want to break <Cust> from another <Cust>. Javascript: function ok_click() { var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0"); xmlDoc.async = false; xmlDoc.load("data.xml"); if (xmlDoc.readyState == 4 && xmlDoc.parseError.errorCode == 0) { var root = xmlDoc.documentElement; var e1 = document.getElementById("Select1"); var _account_type = xmlDoc.createTextNode(e1.options[e1.selectedIndex].value); var e2 = document.getElementById("Select2"); var _user = xmlDoc.createTextNode(e2.options[e2.selectedIndex].value); var account_type = xmlDoc.createNode(1, "Select", ""); var user = xmlDoc.createNode(1, "User", ""); account_type.appendChild(_account_type); user.appendChild(_user); var cust = xmlDoc.createNode(1, "Cust", ""); cust.appendChild(account_type); document.write("<br/>"); cust.appendChild(user); root.appendChild(cust); SaveXML(xmlDoc, "data.xml"); alert("Save!"); } } Your help would much appreciated Thanks Natz I'd like to create a website similar to http://www.picfog.com which displays images posted to Twitpic and Yfrog via Twitter. Could anyone help me with the following: Given a feed/list of messages containing links to images, display the images that are linked to. For example, take these two Twitter messages: omgsage: http://twitpic.com/cw3i3 - This is the cutest kitty ever ellievolia: Our evening! http://twitpic.com/cw3hx Using Javascript how do I extract the link part of each message, convert this to point to the actual thumbnail and then display the thumbnails on the web page? Thanks in advance! Hi, I'm having trouble figuring out why my image is disappearing when the user clicks on the arrow image to expand text for viewing. The arrow image only disappears if the link text is is more than one line. It remains if the link is only one line of text. Here is the code: HTML code: Code: <div class="ws-webpart> <div class="hidecat1"></div> <div class="hidecat1"> <!--This comment line added please dont remove this comment line --> <a class="hidecat2" id="za0.91" onclick="showHide('a0.91')" href="javascript:void(0)">Lorem ipsum dolor sit amet</a> </div> <div style="display:none;" id="a0.91"> <!--This comment line added please dont remove this comment line --> <div class="hideqst1"> <a id="sb0.913.92" class="hideqst2" onclick="showHide('b0.913.92')" href="javascript:void(0)"> Sed lectus lectus, varius quis vestibulum non, molestie vel est. Integer enim quam, elementum vel ornare non, egestas non augue. Ut varius vulputate mi, </a> </div> <div style="display:none;" id="b0.913.92"> <!--This comment line added please dont remove this comment line --> <div class="hideAns"> <p>Fusce suscipit tempus magna eget eleifend. Ut lacinia, turpis ac tempus euismod, nulla ipsum vehicula sem, et laoreet augue nunc in neque. Maecenas porttitor lacinia risus, et rhoncus felis vestibulum eget. Sed nec turpis nulla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In fringilla mollis leo sed auctor. </p> </div> </div> <div class="hideqst1"> <a id="sb0.9134.65" class="hideqst2" onclick="showHide('b0.9134.65')" href="javascript:void(0)"> Integer non urna vel ligula interdum?</a> </div> <div style="display:none;" id="b0.9134.65"> <!--This comment line added please dont remove this comment line--> <div class="hideAns"> <p>Suspendisse pretium gravida tortor, id blandit elit hendrerit porttitor. Mauris at purus id neque mollis placerat vitae in tortor. Morbi porta tincidunt sagittis. Nam quis augue justo, id euismod nisl.</p> <p>• Donec sit amet urna felis. Praesent at erat ligula, eget porttitor diam.<br> • Quisque quis sapien leo. Proin sit amet sem et lectus gravida iaculis a non turpis. Vivamus at metus quis odio mattis </p> </div> </div> </div> CSS code: Code: div.ws-webpart{margin-bottom:15px;clear:both;} .ws-webpart.hidecat1{padding-top:7px;} .ws-webpart.hidecat2{padding-left:2.2ex;color:#000;font-weight:700;text-decoration:underline;background:url(../images/layout/link_arrow.gif) no-repeat 0 3px;} .ws-webpart.hidecat3{padding-left:2.2ex;color:#000;font-weight:700;text-decoration:none;background:url(../images/layout/link_arrow_down.gif) no-repeat 0 3px;} .ws-webpart.collapseqst1{padding-top:7px;padding-left:2.2ex;} .ws-webpart.hideqst2{padding-left:2.2ex;color:#7C902C;padding-right:0;background:url(../images/layout/link_arrow.gif) no-repeat 0 3px; zoom:1;} .ws-webpart.hideqst3{padding-left:2.2ex;color:#7C902C;padding-right:0;background:url(../images/layout/link_arrow_down.gif) no-repeat 0 3px;} .ws-webpart.hideAns{color:#000;padding-left:4.4ex;padding-right:1.5ex;padding-top:7px;} Javascript code: Code: <script language="javascript" > // Function for Collapsible Link function showHide(ID) { if (document.getElementById(ID).style.display == "block"){ document.getElementById(ID).style.display = "none"; if(ID.charAt(0)=="a"){ document.getElementById("z"+ID).className="hidecat2"; } if(ID.charAt(0)=="b"){ document.getElementById("s"+ID).className="hideqst2"; } } else { document.getElementById(ID).style.display = "block"; if(ID.charAt(0)=="a"){ document.getElementById("z"+ID).className="hidecat3"; } if(ID.charAt(0)=="b"){ document.getElementById("s"+ID).className="hideqst3"; } } } </script> I have attached the images. Thanks in advance So I have a gallery which is displaying images from an array called imgList. When they are displayed I want the user to be able to link directly to the image. Is there a simple way to do this? The JavaScript: Code: //<!-- var imgList = new Array( "images/gallery/1.jpg", "images/gallery/2.jpg", "images/gallery/3.jpg", "images/gallery/5.jpg", "images/gallery/6.jpg", "images/gallery/duo.jpg" ); var clientData = new Array( '', '', '', '', '', '', '' ); var currentMain = 0; var currentMainT = 0; var current_position=0; var all_links=""; function init(){ all_links=document.getElementById('gallery').getElementsByTagName('a'); all_links[0].style.color="#7d3d3d"; ShowMain(current_position); } function color_me(element,color){ element.style.color=color; } function Prev(){ color_me(all_links[current_position],'#000000'); if((current_position-1)>-1){ current_position=current_position-1; } else{ current_position=(all_links.length-1); } ShowMain(current_position); // ShowMainT(current_position); color_me(all_links[current_position],'#7d3d3d'); } function direct_selection(number){ all_links[current_position].style.color="#000000"; current_position=number; ShowMain(current_position); all_links[current_position].style.color="#7d3d3d"; } function Next() { color_me(all_links[current_position],'#000000'); if((current_position+1)<all_links.length){ current_position++; } else{ current_position=0; } ShowMain(current_position); // ShowMainT(current_position); color_me(all_links[current_position],'#7d3d3d'); } function ShowMain(which){ currentMain = which; currentMainT = which; if ( currentMain < 0 ) currentMain = 0; if ( currentMainT < 0 ) currentMainT = 0; if ( currentMain > imgList.length-1) currentMain = imgList.length-1; if ( currentMainT > clientData.length-1) currentMainT = clientData.length-1; document.getElementById('mainImg').src = imgList[currentMain]; document.getElementById('mainText').innerHTML = clientData[currentMainT]; var PD = document.getElementById('Pg'); var PD2 = document.getElementById('Pg2'); document.getElementById("mainText").style.display = 'inline'; // return false; } onload = function() { ShowMain(0); } onload = function() { ShowMainT(0); } //--> //<!-- function preloader(){ // counter var i = 0; // create object imageObj = new Image(); // set image list images = new Array(); images[0]="images/gallery/1.jpg"; images[1]="images/gallery/2.jpg"; images[2]="images/gallery/3.jpg"; images[3]="images/gallery/5.jpg"; images[4]="images/gallery/6.jpg"; images[5]="images/gallery/duo.jpg"; // start preloading for(i=0; i<=3; i++){ imageObj.src=images[i]; } } //--> The HTML where it is displayed: Code: <img id="mainImg" src="images/gallery/1.jpg" style=" border: solid #7d3d3d 5px;" alt="galleryimage" /> Open this in FF. http://agrozoo.net/jsp/statistics_ag...on=11000,11100 Note check box in left vertical column, at top, encapsuled between a and b, click, click, click. That is what it should do. Open in IE, clicking same thing, nothing happens. The recipe for anything to happen is: 1. refresh 2. check the check box encapsuled between a and b 3. Click first checkbox to the right Getting nowhere here, as far as I see IE reports no js errors. ? EDIT: I susspect that onchange is somehow different in IE and FF. Howdy. Have an asp.net form where the textboxes have had the onblur attribute added. Though VS2008 still barks it's an invalid attribute... However, my problem is primarily w/the txtFICODate field. When testing using 10/10/2009 in this field, the code displays the appropriate msg based on format param. However, on exiting the isValidDate function in debug mode, I see that the code does not stop at the txtFICODate html but moves to the txtDOBB isValidDate function. Here the param is MM/DD/YYYY and it loops back into the function but now displays a different format message. Previous code (ValidateFICODate(obj)) below also caused the same looping error. Debugging the same code with the txtDOBB field (10/10/56), I see it enter the function, display the appropriate message and exit. However, in debug, the code comes back to the function and then selects the field contents. Appreciate any suggestions/comments on how to fix problem so code stops at the txtFICODate field . Using xp Pro SP3, visual studio 2008 (c#). in the process of writing this, I searched other post here related to onblur + loop. So changed the event to onchange...and while the looping does not now occur, the focus just moves to the next field. Huh? Thanks, Rey Code: On page load code(if (!isPostBack)): txtFICODate.Attributes.Add("onblur", "isValidDate(this, 'MM/DD/YY');"); txtDOBB.Attributes.Add("onblur", "isValidDate(this, 'MM/DD/YYYY');"); txtDOBC.Attributes.Add("onblur", "isValidDate(this, 'MM/DD/YYYY');"); Code: <asp:TextBox ID="txtDOBB" runat="server" Font-Bold="true" Text="" Columns="10" TextMode="SingleLine" AutoPostBack="false" onblur="return isValidDate(this, 'MM/DD/YYYY');" Width="120px"></asp:TextBox> <asp:TextBox ID="txtDOBC" runat="server" Font-Bold="true" Text="" Columns="10" TextMode="SingleLine" AutoPostBack="false" onblur="return isValidDate(this, 'MM/DD/YYYY');" Width="120px"></asp:TextBox> <asp:TextBox ID="txtFICODate" runat="server" Font-Bold="true" AutoPostBack="false" onblur="return isValidDate(this, 'MM/DD/YY');" Text="" Columns="6" TextMode="SingleLine" Width="120px" ></asp:TextBox> Code: function isValidDate(ctrl, fmt) { // retrieved 9/11/09 // from http://www.dotnetspider.com/resources/20790-Validatin-date-MM-DD-YY-Format-using-javascript.aspx // modified to pass in format (mm/dd/yy, mm/dd/yyyy so msg is appropriate if incorrect // also removed - option for dates, i.e. 09-11 var dateStr = ctrl.value; var datePat; //var datePat = /^(\d{1,2})(\/)(\d{1,2})\2(\d{2}|\d{4})$/; if (fmt.toString().toUpperCase() == 'MM/DD/YY') { datePat = /^(\d{2})(\/)(\d{2})\2(\d{2})$/; } if (fmt.toString().toUpperCase() == 'MM/DD/YYYY') { datePat = /^(\d{2})(\/)(\d{2})\2(\d{4})$/; } var matchArray = dateStr.match(datePat); // is the format ok? if (matchArray == null) { if (fmt.toString().toUpperCase() == 'MM/DD/YY') { alert("Invalid date format.\n" + "Please enter the date in the MM/DD/YY format (example: 1/15/08).") ctrl.focus(); ctrl.select(); return false; } if (fmt.toString().toUpperCase() == 'MM/DD/YYYY') { alert("Invalid date format.\n" + "Please enter the date in the MM/DD/YYYY format (example: 1/15/2008).") ctrl.focus(); ctrl.select(); return false; } } // match breaks date down month = matchArray[1]; // parse date into variables day = matchArray[3]; year = matchArray[4]; if (month < 1 || month > 12) { // check month range alert("Month must be between 1 and 12."); return false; } if (day < 1 || day > 31) { alert("Day must be between 1 and 31."); return false; } if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) { alert("Month " + month + " doesn't have 31 days!") return false } if (month == 2) { // check for february 29th var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day > 29 || (day == 29 && !isleap)) { alert("February " + year + " doesn't have " + day + " days!"); return false; } } return true; // date is valid } // **************************************************** function ValidateFICODate(obj) { var dateFormat = 'MM/DD/YY'; var isSuccess = false; var objID = obj.id; var hidFICODate = document.getElementById('hidFICODate').value; if (obj.value == '') { alert('Please enter FICO date.' + '\n' + 'Required field.'); //document.frmCustInfo + '.' + obj.id + '.' + focus(); obj.focus(); obj.select(); return false; } // now check if valid date isSuccess = isValidDate(obj, dateFormat); if (!isSuccess) { obj.focus(); obj.select(); return false; } if (isSuccess) { if (obj.value != hidFICODate) { document.getElementById('hidFICODate_Updated').value = 'UPDATED'; document.getElementById('hidFICODate').value = obj.value; } } return isSuccess; } Hi, I have a problem with a small div of mine, namely: Code: <div id="mui" class="disk" onmousedown="mouse_down(event, 'mui');" onMouseUp="mouse_up()"> <div id="mui_image"></div> <div>MUI</div> </div> I am using some javascript to move it and the first time I press down the mousebutton on it and move around, it works fine! Usually if I release the mouse button and then hold it down again on the same div to continue moving.. Then instead I select the div with id="mui_image" instead, so that one gets dragged away just as if you select some text and drag it. My div just stay put then. If I instead were to move it once, then click outside the div, and then try to move the div again, everything works like a charm. How to solve this problem? Oh yeah, only try it in FF, works even worse in Safari. Code: <html> <head> <script src="geut.js"> </script> <style type="text/css"> body { margin: 0px; margin-top: 13px; padding: 0; font-family: georgia, times, "times new roman", serif; font-size: 12; color: #000; background-color: #959595; overflow: hidden; } p { margin: 0; padding: 0; } img { margin: 0; padding: 0; display: inline; } #mui { position: absolute; left: 850px; top: 110px; } #mui_image { width: 43px; height: 23px; background-image:url(disk_up.png); background-repeat: no-repeat; background-position: relative; } .disk { text-align: center; height: 63; width: 50; } </style> </head> <body onload="resizeMainWindow()" onmousemove="mousemove(event)"> X: <span id="X-coord"></span><br> Y: <span id="Y-coord"></span><br> Message : <span id="message"></span><br> Diverse: <span id="diverse"></span> <div id="mui" class="disk" onmousedown="mouse_down(event, 'mui');" onMouseUp="mouse_up()"> <div id="mui_image"></div> <div>MUI</div> </div> </body> </html> Code: var x; var y; var xcor=0; var ycor=0; var xcor_old=0; var ycor_old=0; var being_dragged = false; var element; function mousemove(event) { if(event.offsetX || event.offsetY) { //For Internet Explorer x=event.offsetX +xcor; y=event.offsetY +ycor; } else { //For FireFox x=event.pageX +xcor; y=event.pageY +ycor; } document.getElementById('X-coord').innerHTML = x +'px'; document.getElementById('Y-coord').innerHTML = y +'px'; if(being_dragged == true) { // if((y > 14)) { document.getElementById(element).style.top = y +'px'; // } else { document.getElementById(element).style.top = 14; } document.getElementById(element).style.left = x +'px'; // } // } function mouse_down(event, ele_name) { if(being_dragged) return; being_dragged = true; element = ele_name; if((document.getElementById(ele_name).offsetLeft - x) != 0) { document.getElementById('message').innerHTML = "ms !=0)" +document.getElementById(element).offsetLeft + "||" +(document.getElementById(element).offsetLeft - x); xcor = document.getElementById(element).offsetLeft - x; ycor = document.getElementById(element).offsetTop - y; } else { xcor = xcor_old; ycor = ycor_old; } document.getElementById(element).style.cursor = 'move'; document.getElementById('X-coord').innerHTML = x +'px' + xcor; document.getElementById('Y-coord').innerHTML = y +'px' + ycor; x=event.pageX +xcor; y=event.pageY +ycor; } function mouse_up() { if(being_dragged) { being_dragged = false; document.getElementById(element).style.cursor = 'auto'; document.getElementById(element).style.top = y +'px'; document.getElementById(element).style.left = x +'px'; xcor_old = xcor; ycor_old = ycor; xcor = 0; ycor = 0; } } I am trying to grab the file name of an image generated by a PHP file. I first tried loading the image in an iframe, letting it load, and then grabbing the src; but IE and Fx security measures denied me access to both the src and the href of the iframe. Then, I tried storing the iframe in an object variable after loading and reading the src / href of the variable, but it was always null. Finally, I decided to replace the iframe with an image tag...and it actually started to work. I could access the src after the image had loaded! The only problem is...it is giving me the original src, when what I want is the src generated by the php file that I am using as the image src. As a last personal attempt, I stored the image tag into an Image object, and then used the name method to try and get the file name of the image inside of the tag, but again...that is just returning the src of the php file. Here is where the code is loading: http://avatars.imvu.com/GetInfo Can anyone tell me how to get the file name of an image? Code: <script type="text/javascript"> var UserID=''; var aviName=''; var aviPicBegin = 'http://www.imvu.com/catalog/web_av_pic.php?av='; var aviPicFull=''; var aviPic2=''; var myIMG = imgDisplay; function input() { aviName = fInput.txtAviName.value; aviPicFull = aviPicBegin + aviName; document.getElementById('imgDisplay').src=aviPicFull; } function display() { myIMG = imgDisplay; //aviPic2 = imgDisplay.src; //myIMG.src = aviPic2; alert("img src = " + myIMG.src); //userID=; // document.fOutput.txtID.value = userID; //document.fOutput.txtHP.value = ""; //document.fOutput.txtBlock.value = ""; //document.fOutput.txtAdd.value = ""; //document.fOutput.txtReport.value = ""; } </script> <center> <FORM name=fInput> Avi Name: <input type="text" name="txtAviName"></input><br/><br/> <input type="button" name="Operation" value="Get Info" OnClick="input();"></button> </FORM> <br/> <br/> <img src="/catalog/web_av_pic.php?av=GetInfo" id="imgDisplay" width="160px" height="220px" scrolling="no" padding="0" MARGINWIDTH="0" OnLoad="display();"></img> <br/><br/> <FORM name="fOutput"> ID: <input name="txtID"></input><br/> HP: <input name="txtHP"></input><br/> Block: <input name="txtBlock"></input><br/> Add: <input name="txtAdd"></input><br/> Report: <input name="txtReport"></input> </FORM> <br/><br/> </center> Thanks to everyone who took the time to read this. Hey, I need some JavaScript code which will display the width and height of an image, before it is created on the page, so from the file itself.
I have a form that allows photos to be uploaded. I am using Perl to do this, and it works fine. Now I want to validate that the size of the image does not exceed a certain limit BEFORE it actually uploads. I can do that in Perl using something like the code below. But, I would rather do this in Javascript. I already have a routine that validates that the image file name does not contain embedded spaces. I would like to add this there. Can this be done in Javascript? Code: if ($ENV{'CONTENT_LENGTH'} > 100000) { print "SIZE EXCEEDS LIMIT!" } I have almost 300 photos that I want to have in a gallery that is easy to use. I would like to avoid making 300 list items (as is necessary with all of the auto rotators and other jquery plug ins that I've found) but to have the images load straight from the folder after the rest of the website has loaded. It wold be nice if maybe there was a pretty horizontal scroll bar or something and the image in the middle of the page was biggest if possible, but I'm really not picky. I don't know what the best way is to display so many photos! They don't need captions or anything. Any ideas??? Thanks! Hi, I am new to this forum but I am in dire need of help. I am sorry if this isn't they way you normally do things. I read through some of the rules, but it is late and I am in a hurry. Any help would be greatly appreciated. I need the image file names in my array to be shown in the text box. I am not quite sure how to do this. I have been trying for some time but cannot figure it out. Here is my code. <head> <title>Asn4CStartup.htm by Todd Bowman</title> <style type="text/css" > h1, h2, h3 {font-family: 'arial black';} .controls { font-family: 'arial black'; font-size:10pt;} </style> <script type="text/javascript"> /* <![CDATA[ */ // Note: variables declared inside a function // using the var keyword are all local variables. It means that these // variables are only known inside the function. Other functions cannot see // the values. // On the other hand if a variable is declared outside any function, these are global // variables. The values of global variables are available in all other functions. // Other function can change the values of global variables. // Declare a global var n: var n=0; // we will use this global variable to keep track of exactly which element of the array // is being displayed now. When the user clicks Next button, we will add 1 to n and // then display the image file in the nth element of the array // Declare a global array that will contain the names of image files. var imgArray = new Array(); // The following function will be triggered on the onload event of the page. function fillArray() { // alert ("Hello on load"); imgArray[0]="Bus1.jpg"; imgArray[1]="Bus2.jpg"; imgArray[2]="Fam1.jpg"; imgArray[3]="Fam2.jpg"; imgArray[4]="Honey1.jpg"; imgArray[5]="Honey2.jpg"; imgArray[6]="Map1.png"; // for ( i in imgArray) // alert (imgArray[i]); } function showNext() // This function will be triggered on click of the Next button { // alert ("Hello showNext"); // alert(n); n = n+1; //alert (n); if (n > imgArray.length-1) { alert ('You are already on the last image'); n = n-1; } else document.getElementById('imgPic').src='images/'+imgArray[n]; } // end showNext() function showPrevious() // This function will be triggered on click of the Previous button { // alert("Hello Previous"); // alert(n); n = n-1; // alert (n); if (n < 0) { alert ('You are already at the first image'); n = n+1; } else document.getElementById('imgPic').src='images/'+imgArray[n]; } // end showPrevious() function showFirst() //This function will be triggered on click of the First button { // alert (n); if (n == 0) { alert ('You are already on the first image'); } else document.getElementById('imgPic').src='images/'+imgArray[0]; } function showLast() { // alert (n); if (n > imgArray.length-1) { alert ('You are already on the last image'); } else document.getElementById('imgPic').src='images/'+imgArray.length-1; } /* ]]> */ </script> </head> <body onload="fillArray();"> <div> <h1> Asn4CStartup.htm by Mesbah Ahmed </h1> <h2>Windsurf Image Navigation </h2> Name of the image file shown below:   <input type="text" id="imageName" size="20" readonly="readonly" /> <br/><br/> <img id="imgPic" src = "images/Bus1.jpg" alt="picture" width="500px" height="350px" /> <br/> <input type="button" value="Next" class="controls" onclick="showNext();" /> <input type="button" value="Previous" class="controls" onclick="showPrevious();" /> <input type="button" value="First" class="controls" onclick="showFirst();" /> <input type="button" value="Last" class="controls" onclick="showLast();" /> <br/> <p> <img src="http://www.w3.org/Icons/valid-xhtml11.png" alt="Valid XHTML 1.1!" height="31px" width="88px" /> <img src="http://jigsaw.w3.org/css-validator/images/vcss-blue.png" alt="Valid CSS!" height="31px" width="88px" /> </p> </div> </body> </html> I'm try to set up a webpge that will play a live flash video on the left-hand side(got that part working) and display one slide of a presentation(jpg) to the right of the video. I would like to be able to control when the slide image changes by having some js check a text file on my server. The text file could contain something as simple as "Slide1.jpg". I will manipulate the text file with some code I've already written. Is there some simple js code I can put in my page that will cause it to check the text file every 5 seconds, and if the content of the file has changed, to refresh the image on the page with the new image? I'm try to get away from the "clicking" sound that is caused by doing a simple refresh of an Iframe. I'm a complete novice at js, so any help would be appreciated. I'm also open to other solutions that would accomplish the same thing. Thanks, Mike I've created a javascript version of the classic game SOKOBAN. Basically what happens is you move the man around the "warehouse" and he must push the boxes into the target area. Copy the code and try it yourself to see what I have so far (note-he can't move the boxes yet). My question is: Right now, my map consists of solid color blocks. What I WANT them to be is image files (for example: box.png, wall.png, floor.png) to add a little versatility and life to the map. I am not sure how to make this switch though. I suspect I make the change somewhere in the tile array in the initialize function, but I am not sure what.. Also, how can I get the boxes to actually MOVE? I.e. when my man pushes them, they move around in the direction he pushes? Any help would be much appreciated. Thank you kindly Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Sokoban</title> <style type="text/css"> body { font-family: Arial; font-size: 48px; } #warehouse { width: 680px; height: 400px; position: relative; } .box { background-size: contain; } .box, #man { margin: 0; padding: 0; display: inline-block; width: 40px; height: 40px; float: left; } </style> <script type="text/javascript"> var map_width = 17; var map_height = 10; var grid; var player_x; var player_y; var tile; function initialize() { grid = new Array(); grid[0] = new Array(0,0,0,0,0,5,5,5,5,5); grid[1] = new Array(0,0,0,0,0,5,2,5,2,5); grid[2] = new Array(0,0,0,0,0,5,2,2,2,5); grid[3] = new Array(0,0,0,0,0,5,1,1,1,5); grid[4] = new Array(0,0,0,0,0,5,1,1,1,5); grid[5] = new Array(0,0,0,0,0,5,1,1,1,5); grid[6] = new Array(0,0,0,0,0,5,1,1,1,5); grid[7] = new Array(0,0,0,0,0,5,5,1,5,5); grid[8] = new Array(5,5,5,5,5,5,5,1,5,0); grid[9] = new Array(5,1,1,1,5,1,1,1,5,0); grid[10] = new Array(5,1,3,1,1,1,3,1,5,0); grid[11] = new Array(5,1,5,1,1,1,3,1,5,0); grid[12] = new Array(5,1,1,1,3,5,3,1,5,0); grid[13] = new Array(5,1,1,1,1,1,1,1,5,0); grid[14] = new Array(5,1,5,5,5,5,1,1,5,0); grid[15] = new Array(5,5,5,0,0,5,1,1,5,0); grid[16] = new Array(0,0,0,0,0,5,5,5,5,0); player_x = 14; player_y = 1; tile = new Array( 'green', /* grass */ '#202020', /* interior floor */ 'red', /* target */ 'brown', /* crate */ 'brown', /* crate sitting on target */ 'orange' /* brick */ ); draw_background(); position_man(); } function draw_background() { for (var y = 0; y < map_height; ++y) { for (var x = 0; x < map_width; ++x) { var box = document.getElementById('box_' + x + '_' + y); box.style.backgroundColor = tile[grid[x][y]]; } } } function position_man() { var man = document.getElementById('man'); man.style.position = 'absolute'; man.style.left = 40 * player_x + 'px'; man.style.top = 40 * player_y + 'px'; } function safe_check(x, y) { if (x >= 0 && x < map_width && y >= 0 && y < map_height) return grid[x][y]; return -1; } function handle_key(e) { var move_x = 0; var move_y = 0; switch(String.fromCharCode(e.which).toLowerCase()) { case 'w': move_y = -1; break; case 'a': move_x = -1; break; case 's': move_y = 1; break; case 'd': move_x = 1; break; default: return false; } var s = safe_check(player_x + move_x, player_y + move_y); if (s > 2) { return true; } player_x += move_x; player_y += move_y; position_man(); return true; } </script> </head> <body onkeypress="handle_key(event)"> <div id="warehouse"> <img src="man.png" id="man" /> </div> <table> <tr> <th>up</th> <th>left</th> <th>down</th> <th>right</th> </tr> <tr> <th>W</th> <th>A</th> <th>S</th> <th>D</th> </tr> </table> <script type="text/javascript"> var warehouse = document.getElementById('warehouse'); for (var y = 0; y < map_height; ++y) { for (var x = 0; x < map_width; ++x) { var box = document.createElement('div'); box.id = "box_" + x + "_" + y; box.className = "box"; warehouse.appendChild(box); } } initialize(); </script> </body> </html> I can get this code to take two separate sections of a file which are not beside each other and write them into another file. It always comes up as a single full line of the code instead of the sections I want. The code includes the student number first name last name and three results of assignments. I want the code to write the student number and three results of all the students into a file and then work out the average of the student results. Can you help? Code: try{ while (in.hasNextLine()) { String line = in.nextLine(); out.println( line); int i=0; if(!Character.isDigit(line.charAt(i))) { i++; } studentStringNumber = line.substring(0, i); String stringResult = line.substring(i); studentStringNumber = studentStringNumber.trim(); stringResults = stringResults.trim(); double stringResultsValue = Double.parseDouble(stringResults.trim()); stringResults = in.nextLine(); studentStringNumber = in.nextLine(); studentNumber = Integer.parseInt(studentStringNumber); if(in.hasNextInt()) { int value = in.nextInt(); } results = Double.parseDouble(stringResults); if(in.hasNextDouble()) { double value = in.nextDouble(); } Scanner lineScanner = new Scanner(line); studentStringNumber = lineScanner.next(); while(!lineScanner.hasNextDouble()) { studentStringNumber = studentStringNumber+ " " +lineScanner.next(); } stringResultsValue = lineScanner.nextDouble(); } } Hi, Can someone tell me what I am doing wrong. Script works on the first attachment but not the other two? Code: <script type="text/javascript" language="JavaScript"><!-- function ExtensionsOkay() { var extension = new Array(); var fieldvalue = new Array(); fieldvalue[0] = document.customApp.attachment_1.value; fieldvalue[1] = document.customApp.attachment_2.value; fieldvalue[2] = document.customApp.attachment_3.value; extension[0] = ".doc"; extension[1] = ".docx"; extension[2] = ".txt"; extension[3] = ".pdf"; // No other customization needed. for(var f = 0; f < fieldvalue.length; f++) { var thisext = fieldvalue[f].substr(fieldvalue[f].lastIndexOf('.')); for(var i = 0; i < extension.length; i++) { if(thisext == extension[i]) { return true; } } alert("Your upload field " + f + " contains an unapproved file name."); return false; } } //--></script> i have image button i need to display image .if the size of the image button is 100*100 and image size is 50*50 .the remaining space of the image button should be empty.the image should not stretch. can any one guide me i am new to programming Thanks in advance!!! Does anyone know how to accomplish this? I got the html file to show but none of the text in the file will show.
|