JavaScript - Change Id Based On Width Of Image
I have a list of thumbnails generated by Wordpress. I've been trying to piece together a script that would change the ID of the parent element based on the image inside of it I can't seem to get anywhere, does anyone have a simple solution?
I need the id of the li to be "sm" or "smp" depending on the width of the image inside of it (landscape or portrait) Code: <li class="frame" id="sm"> <div class="frm" id="frame1"> <img src="image.jpg"> </div> </li> Similar TutorialsI am trying to write a custom BBcode for a forum I moderate. I don't have the licensing information because its not my forum and i am just a moderator. If anyone wants to verify the legitimacy of the forum I work for please PM me and I will try and get you any information I can. This code that I has works perfect in EditRocket, but when I add it to the custom BBcode the image does not resize. Original EditBucket Code: Code: <html> <head> <script type="text/javascript"> function show_confirm(testimg) { var theImg = document.getElementById('testimg'); var theWidth = theImg.width; var theHeight = theImg.height; if (theWidth<250) { theImg.width = theWidth; theImg.height = theHeight; } else { theImg.width = 250; theImg.height = theHeight*(250/theWidth); } } </script> </head> <body> <img id="testimg" onload="show_confirm(testimg)" src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Example.svg/600px-Example.svg.png"> </body> </html> vBulletin Custom BBcode: title: Test Image bbcode tag name: timage Replacement: Code: <script type="text/javascript"> function show_confirm(testimg) { var theImg = document.getElementById('testimg'); var theWidth = theImg.width; var theHeight = theImg.height; if (theWidth<250) { theImg.width = theWidth; theImg.height = theHeight; } else { theImg.width = 250; theImg.height = theHeight*(250/theWidth); } } </script> <body> <img id="testimg" onload="show_confirm(testimg)" src="{param}"> </body> Example: [timage]http://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Example.svg/600px-Example.svg.png[/timage] Description: Embed imaged inline with forum Option: no Hello, I just joined the forum. I'm hoping someone could help me out or point me in the right direction. I am trying to set up a simple interaction for users. The user would be required to select a width then height from two separate drop down menus. I used this as an example to work from: http://www.w3.org/TR/WCAG20-TECHS/wo...dynselect.html The list of heights would not be available until the user selects a width.(similar to the example link above). Each width would have slightly different heights associated with it. After the user selects a width then height an image would be displayed based on that combination. So for example if the user selects 12w/30h they would see "01.jpg" if the user selects 12w/36h they would see "02.jpg". This would all be done on the same page. The user should be able to update the image by combining the different width/height options indefinitely. If anyone has a link to an example or can provide a basic structure I could build of off I would be extremely grateful, thanks. Need to set the width of a Table that is being spit out by this god awful CMS... please help me... change the html attribute width! Hi, I'm trying to change the column from javascript using. cell.width='7'; or cell.style.width="7px"; when i set this. all the columns in each row within the table are resetting to this column width. How can i make sure that this reflects for only one row for which i set this property to. Please let me know. Hi Guys, I am looking for a script to change text on a page based on the time of day. From 9am - 5pm weekdays I would like the page to display 'Open', and outside of that window to display 'Closed'. I am using HTML & PHP. Any help would be greatly appreciated. Thanks, Matt I am trying to change a character limit based on items changed in a drop down menu. To do this I have one function that will change the posted count based on the currently selected option and another function that is a commonly used char count with a few tweaks. The main issue is getting the value of the currently selected option. I know that selectedIndex will return the position of the selected element rather than the actual value. I tried to code around that. I've tried every method I could find on google and nothing works. So, I may have a bigger problem on a higher level that I just don't understand. If any of you can take a look at my code and give me your thoughts I would be most appreciative. Thanks! Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title></title> <script type="text/javascript"> function checkTextArea(fromto){ var textstring = "textarea"; var id = textstring + fromto; var destination = document.forms["form1"].[id.selectedIndex].text; if (destination=="1") { var limit = "500"; } else { var limit = "1000"; } if (document.getElementById(id)){ var txt = document.getElementById(id).value; if (txt.length>limit){ document.getElementById(id).value = txt.substr(0,limit); } len = document.getElementById(id).value.length; span_id = "span" + id; if (document.getElementById(span_id)){ document.getElementById(span_id).innerHTML = (limit-len); } // if } //if } //function function chardisplay(fromto) { var deststring = "dest"; var identifier = deststring + fromto; // no idea how to make this work...seems to stop working whenever I try to assign it to any kind of variable // I have also tried assigning .value and .text // I have also tried naming it with document.forms["form1"].[identifier.selectedIndex] // also using .value and .text var harmless = document.getElementById('identifier').selectedIndex; alert("value="+document.getElementById('identifier').value); alert("text="+document.getElementById('identifier').options.[harmless].text); var spanstring = "spantextarea"; var spanidentifier = spanstring + fromto; if (harmless=="1") { document.getElementById(spanidentifier).innerHTML = "500"; } else { document.getElementById(spanidentifier).innerHTML = "1000"; } } </script> </head> <body> <form id="form1" name="form1" method="POST" action="myurl"> <p><span id="spantextareafrSOMENUMBER">500</span> characters left </p> <select name="destfrSOMENUMBER" onchange="javascript:chardisplay('frSOMENUMBER');\" onfocusout="javascript:chardisplay('frSOMENUMBER');\" onblur="javascript:chardisplay('frSOMENUMBER');\"> <option value="opt1">display option 1</option> <option value="opt2">display option 2</option> <option value="opt3">display option 3</option> </select> <textarea onkeyup="checkTextArea('textareafrSOMENUMBER');" name="mesgfrSOMENUMBER" id="textareafrSOMENUMBER" cols=50 rows=4></textarea> </form> </table> </body> </html> Hello, I am trying to change the value of #name and #category inputs based on the value of select. A friend gave me the code below, but I can't get it to work. Thanks so much for your help Code: <script type="text/javascript"> $('#Gift_Type').change(function(){ if ($(this).val() == 'Monthly'){ $('#name').val('Partnership') $('#category').val('Partnership') } else { $('#name').val('Donation') $('#category').val('Donations') } }) </script> Code: <SELECT NAME="sub_frequency" ID="Gift_Type" onchange="OnSelectionChanged (this)"> <OPTION VALUE="1m">Monthly</OPTION> <OPTION VALUE="">One Time</OPTION> </SELECT> Code: <input type="text" id="name" name="name" value="Partnership" /> <input type="text" id="category" name="category" value="Partnership" /> I want to set the width of a div to be the same width of the image inside the div. The following code works great. But... The images are different widths, so both wrappers are set to the width of the first image. Without having to add an ID to each wrapper or image, can the wrapper width be set to the image width using the name of the image as the unique identifier? Any help would be great! PHP Code: jQuery: $(document).ready(function(){ var newWidth = $('div.wrapper img').attr('width'); $('div.wrapper').width(newWidth); }); HTML: <div class="wrapper"> <p><img src="image1.jpg" width="200" /><br /> Caption</p> </div> <div class="wrapper"> <p><img src="image2.jpg" width="250" /><br /> Caption</p> </div> thanks anyway
I'm new to coding and recently undertook the position as my school district's webmaster. We use a six day schedule where the days are labeled A-F. I want to be able to display the Today is...A graphic based on the date. I tried some scripts from other forums, but it does not appear to be working. Any suggestions? TY <code> <script language="javascript"> <!-- var picture=''; mytime=new Date(); mymonth=mytime.getMonth()+1; mydate=mytime.getDate(); if (mymonth==9 && mydate==13){picture="<img src=/images/d.gif>"; } if (mymonth==9 && mydate==14){picture="<img src=/images/e.gif width=150 height=150 alt=E>"; } if (mymonth==9 && mydate==15){picture="<img src=/images/f.gif width=150 height=150 alt=F>"; } if (mymonth==9 && mydate==16){picture="<img src=/images/A.gif width=150 height=150 alt=A>"; } if (mymonth==9 && mydate==19){picture="<img src=/images/B.gif width=150 height=150 alt=B>"; } if (mymonth==9 && mydate==20){picture="<img src=/images/c.gif width=150 height=150 alt=C>"; } //--> </script></code> Hi guys I have a little problem. I have 2 textfields and I need to change a link href based on whatever is in those textfields. The link has to be in this format: Code: <a class="display" href="test.php?test1=textfield1&test2=textfield2">test</a> The reason for this is I need to launch fancybox and as far as im aware this is the best way to call it. So what im hoping is when I add type something in textfield1 this will be reflected in the url. And same for textfield2. I know this can be done easily if I submit the page but I dont want that. Hopefully some javascript/ajax can help me out? I hope im being clear but let me know if im not. Thanks so much! I am trying to customize this scrollbar so that it will fit all screen resolutions and I was wondering how I could do this by somehow customizing the JavaScript files created by Nathan Faubion or if I could do this using other JavaScript variables (var widthPercentage) to change the pixels to percentages? Please let me know what you think. Thank you very much! One of the pages on the website I'm using the JavaScript on: http://www.clintshipley.com/about.html Code: JavaScript file jsScroller.js: //Created by Nathan Faubion http://www.n-son.com/scripts/jsScrolling/ function jsScroller (o, w, h) { var self = this; var list = o.getElementsByTagName("div"); for (var i = 0; i < list.length; i++) { if (list[i].className.indexOf("scroller-content") > -1) { o = list[i]; } } //Private methods this._setPos = function (x, y) { if (x < this.viewableWidth - this.totalWidth) x = this.viewableWidth - this.totalWidth; if (x > 0) x = 0; if (y < this.viewableHeight - this.totalHeight) y = this.viewableHeight - this.totalHeight; if (y > 0) y = 0; this._x = x; this._y = y; with (o.style) { left = this._x +"px"; top = this._y +"px"; } }; //Public Methods this.reset = function () { this.content = o; this.totalHeight = o.offsetHeight; this.totalWidth = o.offsetWidth; this._x = 0; this._y = 0; with (o.style) { left = "0px"; top = "0px"; } }; this.scrollBy = function (x, y) { this._setPos(this._x + x, this._y + y); }; this.scrollTo = function (x, y) { this._setPos(-x, -y); }; this.stopScroll = function () { if (this.scrollTimer) window.clearInterval(this.scrollTimer); }; this.startScroll = function (x, y) { this.stopScroll(); this.scrollTimer = window.setInterval( function(){ self.scrollBy(x, y); }, 40 ); }; this.swapContent = function (c, w, h) { o = c; var list = o.getElementsByTagName("div"); for (var i = 0; i < list.length; i++) { if (list[i].className.indexOf("scroller-content") > -1) { o = list[i]; } } if (w) this.viewableWidth = w; if (h) this.viewableHeight = h; this.reset(); }; //variables this.content = o; this.viewableWidth = w; this.viewableHeight = h; this.totalWidth = o.offsetWidth; this.totalHeight = o.offsetHeight; this.scrollTimer = null; this.reset(); }; JavaScript on HTML page: <script type="text/javascript" src="Scripts/jsScroller.js"></script> <script type="text/javascript" src="Scripts/jsScrollbar.js"></script> <script type="text/javascript"> var scroller = null; var scrollbar = null; window.onload = function () { scroller = new jsScroller(document.getElementById("scroller"), 550, 275); scrollbar = new jsScrollbar (document.getElementById("scrollbar-content"), scroller, false); } </script> Hi All, I have a form that captures member registration details. In the admin section .. I would like to change the Status field of a record/s from NEW to PAYMENT DUE after 14 days from the data of submission. The status change should automatically trigger on the 15th day. So when the admin checks the list page he/she should be able to view the updated status field. Any pointers how to accomplish this? Thanks in advance. Vinny Hi Coders, I was wondering if anyone knows how you would create a link when clicked will change the width of the content. I have a feeling this will use jQuery? E.g. A link saying 'expand' will change the width of the body to 1000px and change the link to 'contract'. When the link 'contract' is clicked it will change the width back to 800px and change the link to 'expand' Thanks in advance! Haydn. Hi there, Where I work there are certain dates where nothing can be done, certain times where work can be done with caution, and dates where work can be done. I want to put on the site a traffic light that would change colours based on the calendar dates where work can/can't be done. For example, if April 11th there is stuff to do, the traffic light would be green. But April 12th, there isn't work to do, it would turn red. Do you know how I would go about doing this? Hi friends, What I have been trying to achieve is, On my index.htm, I have a horizontal cell named "memberarea" which originally shows username & password input fields. After the user logs in, this area changes itself to a "Welcome Name, Lastname" field. I want that this cell displays again the username and password input fields in case of the session of the user has expired. I have tried it with the following code (within the Iframe in index.htm): ----------------------------------------- <script> if ("<%=session("LoginFirstName")%>" == "") { var m = " <p align="center"> <font style="font-size: 8pt; font-weight: 700" face="arial"> Username:</font> <span style="font-size: 1pt"> <input type="text" name="uid" id="uid" size="14" style="width: 65; height: 17; font-size: 8pt"></span><font face="arial" style="font-size: 8pt"> </font><font style="font-size: 8pt; font-weight: 700" face="arial">Password:</font><font face="arial" style="font-size: 8pt"> </font><span style="font-size: 1pt"> <input type="password" name="pwd" id="pwd" maxlength="10" size="14" style="width: 65; height: 17; font-size: 8pt"></span><span style="font-size: 1px"> </span> <input type="submit" value="Enter" name="B1" style="width: 35; height: 17; font-size:9px" onclick="return login()">"; window.parent.document.getElementById('memberarea').innerHTML=m; } </script> -------------------------------------------------- This code gives me the error that on the 12xx'the line (which does not exist-the whole code is 5xx lines). there is a ";" missing which I could not found. Any ideas how to achieve this? Thank you for your comments Hi, what would be the best way to have a hidden array of possible text directed at a textarea and then if something is not within that array "onfocus", a certain select option is chosen within that form? Thanks http://www.***.com/5.html i cant get a caption specific to each image to display under the arrows when the image changes. it is especially hard for me because i have to edit the javascript which confuses the **** out of me. it seemed so simple.... thanks for any help ps i cant start an id with a digit? it doesnt seem to cause any problems...why is it stated that this cannot or shouldnot be done? I've been having problems getting my select option to change the options of another select option. I'm not much of a javacsript coder, so I'm at a lost. When I select the first option nothing appears in the second option. here's the javascript code: Code: function createOption(OptionText, OptionValue){ var temp = document.captcha_form("option"); temp.innerHTML = OptionText; temp.value = OptionValue; return temp; } function valChange(){ var firstList = document.getElementById("emailaddress"); var secondList = document.getElementById("subject"); while(secondList.hasChildNodes()) secondList.removeChild(secondList.childNodes[0]); switch(firstList.value){ case "1":{ secondList.appendChild(createOption("Report Site Browsing Issue", Report Site Browsing Issues)); secondList.appendChild(createOption("Report Page Errors", Report Page Errors)); secondList.appendChild(createOption("Other", Other)); break; } case "2":{ secondList.appendChild(createOption("Report Unauthorized Game", Report Unauthorized Game)); secondList.appendChild(createOption("Report Spam", Report Spam)); secondList.appendChild(createOption("Report Harassment", Report Harassment)); secondList.appendChild(createOption("Report Illegal Activities", Report Illegal Activities)); secondList.appendChild(createOption("Request Account Removal", Request Account Removal)); break; } // .... default:{ secondList.appendChild(createOption("Please select from the first list", "")); break; } } } window.onload = valChange; this is the form code Code: <div class="mailto_form"> <form method="POST" id="captcha_form" name="captcha_form" action="../includes/mailform.php"> <div style="padding-bottom: 1em;">Choose Recipient: <select name="emailaddress" id="emailaddress" onchange="valChange();"> <option value=""></option> <option value="1">Webmaster</option> <option value="2">Admin</option> </select> </div> <div style="padding-bottom: 1em;">Subject: <br /><select name="subject" id="subject"> </div> <div style="padding-bottom: 1em;">From: <br /><input type="text" name="email" id="email" value=""> </div> <div style="padding-bottom: 1em;">Enter the text contained in the image into the text box: <br /><img src="../includes/captcha.php" /> <br /><input type="text" name="userpass" value=""> </div> <div style="padding-bottom: 1em;">Message: <br /><textarea name="message" id="message" rows="10" cols="60"><?php echo "</tex" . "tarea>"; ?> </div> <div style="padding-bottom: 1em;"><input name="submit" type="submit" value="Submit"> </div> </form> </div> Link to the page http://www.netgamegurus.com/contact/ |