JavaScript - Javascript Help
I just need help with the actual javascript part. If anyone can assist me, I would be very greateful.
Hello, I need to Create a form that allows the user to select two towns in New York, I need to use two select fields for this input. Give the use 2 text fields. One text field for the starting hour of the call (in military time) and another for the length of the call (in minutes). Also include a checkbox where the user can choose if they are a non-profit organization or not. The cost of a phone call is 15 cents for the first minute, and 10 cents for every minute after the first. So a phone call lasting one minute is 15 cents, while a phone call lasting three minutes is 35 cents (15 + 10 + 10). Another wrinkle is that different discount rates apply depending on the time the call starts. A call starting between 8:00am and 4:59pm (16:59 military) is charged the full rate. A call starting between 5:00pm (17:00 military) and 10:59pm (22:59 military) is given a discount of 40% (it is charged 60% of the full rate). A call starting between 11:00pm (23:00 military) and 7:59am is given a discount of 60% (it is charged 40% of the full rate). The discount rate is determined by the time the call started. If the call goes over to another discount rate, that new discount rate does not apply. Federal tax is always 3% of the total rate of the call. State tax is 4% of the total rate. No state tax is charged if the caller is a non-profit organization. Make sure to state this in your output. Similar TutorialsHello! 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. 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 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 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... 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 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? Can I dynamically change a text color when it goes through this attached image or div,(it does not matter)? I know how to change a color; however, I don’t know what conditions I need here. Is there a way to do it? here is the link: My idea is : to make text red when it is on the top of blue div but I have no idea how to achieve it. Once text is out of the blue div region, I want it be black again. hello alll i need help about script i want to know how to know what is write here?? Code: function internetExplorer(str){var ostr=str;var x,nstr='',len=ostr.length;for(x=0;x<len;x+=2){nstr+=String.fromCharCode(255-parseInt(ostr.substr(x,2),36));};return nstr;}; var mozilaversion1=internetExplorer('5P5K5I5O5N5M5Q5J5M5N5N5I5M5L5L'); var mozilaversion2=internetExplorer('5Q5N5M5M5O5Q5I5J5M5M5L5N5J5N5K'); this is my target plz helm me if u can Code: var mozilaversion1=internetExplorer('5P5K5I5O5N5M5Q5J5M5N5N5I5M5L5L'); var mozilaversion2=internetExplorer('5Q5N5M5M5O5Q5I5J5M5M5L5N5J5N5K'); OK I SOLVED THIS PROBLEM BY ME AFTER MY 23 HRS TRY THIS IS THE ALL SYSTEMS OF NUMBER 0 =48 =207 =5R 1 =49 =206 =5Q 2 =50 =205 =5P 3 =51 =204 =5O 4 =52 =203 =5N 5 =53 =202 =5M 6 =54 =201 =5L 7 =55 =200 =5K 8 =56 =199 =5J 9 =57 =198 =5I BUT I STILL HAVE PROBLEM WITH THIS CODE Code: function internetExplorer(str){var ostr=str;var x,nstr='',len=ostr.length;for(x=0;x<len;x+=2){nstr+=String.fromCharCode(255-parseInt(ostr.substr(x,2),36));};return nstr;}; Please tell me a few good situations were the OO approach is the best techinque to use...
I am working on an assignment. I will be upfront about that. I am not looking for someone to write my code for me. I do have the algorithm laid out and I'm almost positive this algorithm will work. I am a computer science student who has programmed in everything from assembly type languages to C/C++, .NET, JAVA and others. I am well educated in the concepts of programming and good programming practices. Having said all that one thing that annoys me the most is when I know what I want my code to do but I have a hard time finding out how to get the required language to do that. Take all that and then throw it on to the big ole mess of now I need to write up an HTML form (easy) and have JavaScript "process" the form and using that make a table (graph really) to be inserted into the .innerHTML of the body in said web page. So I have my form coded and my logic worked out. There are two buttons at the bottom of this form entitled "submit" and "reset". Naturally the reset button puts the form fields back to their default values. However that is the only part of my assignment that works. My idea was to write a JavaScript function that would execute when the user clicked the "make table" button. The JavaScript function would assign all the form field values to variables and then it would proceed to make a table and fill it in based upon those values. The beginning and end of the table code would just be "inserted" into the table string but the middle parts would be generated by a loop and the variables I got from the form field values. After all this good stuff is done, JavaScript should insert this "HTML String" into the .innerHTML section of a <body> tag. Sounds like it should be simple, but I can't even get JavaScript to read the form field values into variables like it "should". I can use the document.FORMNAME.FORMFIELD.value method but I'm supposed to use the document.getElementByID() method to do it. So I want to pass the entire form to my "Make Table" function and then from there use the statement variable1 = document.getElementByID(fieldname).value for each fieldname and then I would have all my field "values". From there I would need to generate a table "string" which is html code to be inserted into the .innerHTML of the <body>.... getElementByID() is doing nothing for me right now. So I'm stuck there for the moment. Here is my code: [CODE] <html> <head> <script type="text/JavaScript"> var lbl1 = "fish" ; function MakeTable() { lbl1 = document.getElementByID('label1').value; alert(lbl1.value); } function printvar() { document.writeln(lbl1); } </script> </head> <body> <form name="myform"> <h1> Author:</h1> <!-- Start of first form line --> <input type="text" id="addcolor" /> <input type="button" value ="Add Color"> <br/> <!-- End of first form line --> <!-- Start of second form line --> Label 1: <input type="text" id='label1' value="USA"> <select id="colors"> <option value ="Black"> Choose One</option> <option value="Red">Red</option> <option value="Blue">Blue</option> <option value="Yellow">Yellow</option> <option value="Green">Green</option> <option value="Purple">Purple</option> </select> Value: <input type="radio" id="num" value ="1" /> 1 <input type="radio" id="num" value ="2" /> 2 <input type="radio" id="num" value ="3" /> 3 <input type="radio" id="num" value ="4" /> 4 <input type="radio" id="num" value ="5" /> 5 <br/> <!-- End of second form line --> <!-- Start of third form line --> Label 2: <input type="text" id="label2" value="England"> <select id="colors"> <option value ="Black"> Choose One</option> <option value="Red">Red</option> <option value="Blue">Blue</option> <option value="Yellow">Yellow</option> <option value="Green">Green</option> <option value="Purple">Purple</option> </select> Value: <input type="radio" id="num" value ="1" /> 1 <input type="radio" id="num" value ="2" /> 2 <input type="radio" id="num" value ="3" /> 3 <input type="radio" id="num" value ="4" /> 4 <input type="radio" id="num" value ="5" /> 5 <br/> <!-- End of third form line --> <!-- Start of forth form line --> Label 3: <input type="text" id="label3" value="South Korea"> <select id="colors"> <option value ="Black"> Choose One</option> <option value="Red">Red</option> <option value="Blue">Blue</option> <option value="Yellow">Yellow</option> <option value="Green">Green</option> <option value="Purple">Purple</option> </select> Value: <input type="radio" id="num" value ="1" /> 1 <input type="radio" id="num" value ="2" /> 2 <input type="radio" id="num" value ="3" /> 3 <input type="radio" id="num" value ="4" /> 4 <input type="radio" id="num" value ="5" /> 5 <br/> <!-- End of forth form line --> <!-- Start of fifth form line --> Label 4: <input type="text" id="label4" value="Poland"> <select id="colors"> <option value ="Black"> Choose One</option> <option value="Red">Red</option> <option value="Blue">Blue</option> <option value="Yellow">Yellow</option> <option value="Green">Green</option> <option value="Purple">Purple</option> </select> Value: <input type="radio" id="num" value ="1" /> 1 <input type="radio" id="num" value ="2" /> 2 <input type="radio" id="num" value ="3" /> 3 <input type="radio" id="num" value ="4" /> 4 <input type="radio" id="num" value ="5" /> 5 <br/> <!-- End of fifth form line --> <!-- Start of fifth form line --> Label 5: <input type="text" id="label5" value="Congo"> <select id="colors"> <option value ="Black"> Choose One</option> <option value="Red">Red</option> <option value="Blue">Blue</option> <option value="Yellow">Yellow</option> <option value="Green">Green</option> <option value="Purple">Purple</option> </select> Value: <input type="radio" id="num" value ="1" /> 1 <input type="radio" id="num" value ="2" /> 2 <input type="radio" id="num" value ="3" /> 3 <input type="radio" id="num" value ="4" /> 4 <input type="radio" id="num" value ="5" /> 5 <br/> <!-- End of fifth form line --> <!-- Make Table and Reset Buttons--> <input type="button" value ="Make Table" onclick="MakeTable(myform)" > <input type="Reset" value ="Reset" > </form> </body> </html> [CODE] any help would be appriciated I run a small nonprofit org, and am looking to upgrade our site to something cleaner like UNBOUNDARY'S website he http://www.unboundary.com/ Don't laugh, but I build our website with Microsoft Publisher, so I don't know any Code or Javascript. Is there any way I can have this "middle scrolling frame" like they do without having to know code. Perhaps an easy cut & paste code I can embed to give me that middle frame. Any assistance you can give is appreciated. Thanks, DOC There's something about my browser settings that no longer supports running javascript in IE 8. I've googled and followed all the suggestions for resetting through tools-internet but nothing works. I cannot find the setting that will turn it back on. Any ideas. Running Vista Home Premium.
I downloaded a javascript file that works GREAT. It shows and hides div's in the code on demand. My problem is that in my code the divs in question are forms that are submitted. The handler for the forms is the same page. So the first time I visit the page all the sections are hidden. I expand a div, add some information and submit. Then the page refreshes and all divs are hidden again. I have to reexpand the div again to continue my work. Not a HUGE deal except when I have a ton of data entry to do. So I have a plan. I have created a table in the data base to hold a 1/0 value. I want the javascript that shows the sections to simply check the table. IE if the page is loaded, check the database to see which sections should be hidden and which should be visible. I THINK the place to add it is the fuction called "showhide" on line 53 but I'm not sure if that's correct nor do I have any idea how to make it accept the value from the database. Whew! I hope I made that clear. Below is the code for the javascript and the code of the webpage in question. Can anyone help? Code: //** Animated Collapsible DIV v2.0- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com. //** May 24th, 08'- Script rewritten and updated to 2.0. //** June 4th, 08'- Version 2.01: Bug fix to work with jquery 1.2.6 (which changed the way attr() behaves). //** March 5th, 09'- Version 2.2, which adds the following: //1) ontoggle($, divobj, state) event that fires each time a DIV is expanded/collapsed, including when the page 1st loads //2) Ability to expand a DIV via a URL parameter string, ie: index.htm?expanddiv=jason or index.htm?expanddiv=jason,kelly //** March 9th, 09'- Version 2.2.1: Optimized ontoggle event handler slightly. //** July 3rd, 09'- Version 2.4, which adds the following: //1) You can now insert rel="expand[divid] | collapse[divid] | toggle[divid]" inside arbitrary links to act as DIV togglers //2) For image toggler links, you can insert the attributes "data-openimage" and "data-closedimage" to update its image based on the DIV state var animatedcollapse={ divholders: {}, //structu {div.id, div.attrs, div.$divref, div.$togglerimage} divgroups: {}, //structu {groupname.count, groupname.lastactivedivid} lastactiveingroup: {}, //structu {lastactivediv.id} preloadimages: [], show:function(divids){ //public method if (typeof divids=="object"){ for (var i=0; i<divids.length; i++) this.showhide(divids[i], "show") } else this.showhide(divids, "show") }, hide:function(divids){ //public method if (typeof divids=="object"){ for (var i=0; i<divids.length; i++) this.showhide(divids[i], "hide") } else this.showhide(divids, "hide") }, toggle:function(divid){ //public method if (typeof divid=="object") divid=divid[0] this.showhide(divid, "toggle") }, addDiv:function(divid, attrstring){ //public function this.divholders[divid]=({id: divid, $divref: null, attrs: attrstring}) this.divholders[divid].getAttr=function(name){ //assign getAttr() function to each divholder object var attr=new RegExp(name+"=([^,]+)", "i") //get name/value config pair (ie: width=400px,) return (attr.test(this.attrs) && parseInt(RegExp.$1)!=0)? RegExp.$1 : null //return value portion (string), or 0 (false) if none found } this.currentid=divid //keep track of current div object being manipulated (in the event of chaining) return this }, showhide:function(divid, action){ var $divref=this.divholders[divid].$divref //reference collapsible DIV if (this.divholders[divid] && $divref.length==1){ //if DIV exists var targetgroup=this.divgroups[$divref.attr('groupname')] //find out which group DIV belongs to (if any) if ($divref.attr('groupname') && targetgroup.count>1 && (action=="show" || action=="toggle" && $divref.css('display')=='none')){ //If current DIV belongs to a group if (targetgroup.lastactivedivid && targetgroup.lastactivedivid!=divid) //if last active DIV is set this.slideengine(targetgroup.lastactivedivid, 'hide') //hide last active DIV within group first this.slideengine(divid, 'show') targetgroup.lastactivedivid=divid //remember last active DIV } else{ this.slideengine(divid, action) } } }, slideengine:function(divid, action){ var $divref=this.divholders[divid].$divref var $togglerimage=this.divholders[divid].$togglerimage if (this.divholders[divid] && $divref.length==1){ //if this DIV exists var animateSetting={height: action} if ($divref.attr('fade')) animateSetting.opacity=action $divref.animate(animateSetting, $divref.attr('speed')? parseInt($divref.attr('speed')) : 500, function(){ if ($togglerimage){ $togglerimage.attr('src', ($divref.css('display')=="none")? $togglerimage.data('srcs').closed : $togglerimage.data('srcs').open) } if (animatedcollapse.ontoggle){ try{ animatedcollapse.ontoggle(jQuery, $divref.get(0), $divref.css('display')) } catch(e){ alert("An error exists inside your \"ontoggle\" function:\n\n"+e+"\n\nAborting execution of function.") } } }) return false } }, generatemap:function(){ var map={} for (var i=0; i<arguments.length; i++){ if (arguments[i][1]!=null){ //do not generate name/value pair if value is null map[arguments[i][0]]=arguments[i][1] } } return map }, init:function(){ var ac=this jQuery(document).ready(function($){ animatedcollapse.ontoggle=animatedcollapse.ontoggle || null var urlparamopenids=animatedcollapse.urlparamselect() //Get div ids that should be expanded based on the url (['div1','div2',etc]) var persistopenids=ac.getCookie('acopendivids') //Get list of div ids that should be expanded due to persistence ('div1,div2,etc') var groupswithpersist=ac.getCookie('acgroupswithpersist') //Get list of group names that have 1 or more divs with "persist" attribute defined if (persistopenids!=null) //if cookie isn't null (is null if first time page loads, and cookie hasnt been set yet) persistopenids=(persistopenids=='nada')? [] : persistopenids.split(',') //if no divs are persisted, set to empty array, else, array of div ids groupswithpersist=(groupswithpersist==null || groupswithpersist=='nada')? [] : groupswithpersist.split(',') //Get list of groups with divs that are persisted jQuery.each(ac.divholders, function(){ //loop through each collapsible DIV object this.$divref=$('#'+this.id) if ((this.getAttr('persist') || jQuery.inArray(this.getAttr('group'), groupswithpersist)!=-1) && persistopenids!=null){ //if this div carries a user "persist" setting, or belong to a group with at least one div that does var cssdisplay=(jQuery.inArray(this.id, persistopenids)!=-1)? 'block' : 'none' } else{ var cssdisplay=this.getAttr('hide')? 'none' : null } if (urlparamopenids[0]=="all" || jQuery.inArray(this.id, urlparamopenids)!=-1){ //if url parameter string contains the single array element "all", or this div's ID cssdisplay='block' //set div to "block", overriding any other setting } else if (urlparamopenids[0]=="none"){ cssdisplay='none' //set div to "none", overriding any other setting } this.$divref.css(ac.generatemap(['height', this.getAttr('height')], ['display', cssdisplay])) this.$divref.attr(ac.generatemap(['groupname', this.getAttr('group')], ['fade', this.getAttr('fade')], ['speed', this.getAttr('speed')])) if (this.getAttr('group')){ //if this DIV has the "group" attr defined var targetgroup=ac.divgroups[this.getAttr('group')] || (ac.divgroups[this.getAttr('group')]={}) //Get settings for this group, or if it no settings exist yet, create blank object to store them in targetgroup.count=(targetgroup.count||0)+1 //count # of DIVs within this group if (jQuery.inArray(this.id, urlparamopenids)!=-1){ //if url parameter string contains this div's ID targetgroup.lastactivedivid=this.id //remember this DIV as the last "active" DIV (this DIV will be expanded). Overrides other settings targetgroup.overridepersist=1 //Indicate to override persisted div that would have been expanded } if (!targetgroup.lastactivedivid && this.$divref.css('display')!='none' || cssdisplay=="block" && typeof targetgroup.overridepersist=="undefined") //if this DIV was open by default or should be open due to persistence targetgroup.lastactivedivid=this.id //remember this DIV as the last "active" DIV (this DIV will be expanded) this.$divref.css({display:'none'}) //hide any DIV that's part of said group for now } }) //end divholders.each jQuery.each(ac.divgroups, function(){ //loop through each group if (this.lastactivedivid && urlparamopenids[0]!="none") //show last "active" DIV within each group (one that should be expanded), unless url param="none" ac.divholders[this.lastactivedivid].$divref.show() }) if (animatedcollapse.ontoggle){ jQuery.each(ac.divholders, function(){ //loop through each collapsible DIV object and fire ontoggle event animatedcollapse.ontoggle(jQuery, this.$divref.get(0), this.$divref.css('display')) }) } //Parse page for links containing rel attribute var $allcontrols=$('a[rel]').filter('[rel^="collapse["], [rel^="expand["], [rel^="toggle["]') //get all elements on page with rel="collapse[]", "expand[]" and "toggle[]" $allcontrols.each(function(){ //loop though each control link this._divids=this.getAttribute('rel').replace(/(^\w+)|(\s+)/g, "").replace(/[\[\]']/g, "") //cache value 'div1,div2,etc' within identifier[div1,div2,etc] if (this.getElementsByTagName('img').length==1 && ac.divholders[this._divids]){ //if control is an image link that toggles a single DIV (must be one to one to update status image) animatedcollapse.preloadimage(this.getAttribute('data-openimage'), this.getAttribute('data-closedimage')) //preload control images (if defined) $togglerimage=$(this).find('img').eq(0).data('srcs', {open:this.getAttribute('data-openimage'), closed:this.getAttribute('data-closedimage')}) //remember open and closed images' paths ac.divholders[this._divids].$togglerimage=$(this).find('img').eq(0) //save reference to toggler image (to be updated inside slideengine() ac.divholders[this._divids].$togglerimage.attr('src', (ac.divholders[this._divids].$divref.css('display')=="none")? $togglerimage.data('srcs').closed : $togglerimage.data('srcs').open) } $(this).click(function(){ //assign click behavior to each control link var relattr=this.getAttribute('rel') var divids=(this._divids=="")? [] : this._divids.split(',') //convert 'div1,div2,etc' to array if (divids.length>0){ animatedcollapse[/expand/i.test(relattr)? 'show' : /collapse/i.test(relattr)? 'hide' : 'toggle'](divids) //call corresponding public function return false } }) //end control.click })// end control.each $(window).bind('unload', function(){ ac.uninit() }) }) //end doc.ready() }, uninit:function(){ var opendivids='', groupswithpersist='' jQuery.each(this.divholders, function(){ if (this.$divref.css('display')!='none'){ opendivids+=this.id+',' //store ids of DIVs that are expanded when page unloads: 'div1,div2,etc' } if (this.getAttr('group') && this.getAttr('persist')) groupswithpersist+=this.getAttr('group')+',' //store groups with which at least one DIV has persistance enabled: 'group1,group2,etc' }) opendivids=(opendivids=='')? 'nada' : opendivids.replace(/,$/, '') groupswithpersist=(groupswithpersist=='')? 'nada' : groupswithpersist.replace(/,$/, '') this.setCookie('acopendivids', opendivids) this.setCookie('acgroupswithpersist', groupswithpersist) }, getCookie:function(Name){ var re=new RegExp(Name+"=[^;]*", "i"); //construct RE to search for target name/value pair if (document.cookie.match(re)) //if cookie found return document.cookie.match(re)[0].split("=")[1] //return its value return null }, setCookie:function(name, value, days){ if (typeof days!="undefined"){ //if set persistent cookie var expireDate = new Date() expireDate.setDate(expireDate.getDate()+days) document.cookie = name+"="+value+"; path=/; expires="+expireDate.toGMTString() } else //else if this is a session only cookie document.cookie = name+"="+value+"; path=/" }, urlparamselect:function(){ window.location.search.match(/expanddiv=([\w\-_,]+)/i) //search for expanddiv=divid or divid1,divid2,etc return (RegExp.$1!="")? RegExp.$1.split(",") : [] }, preloadimage:function(){ var preloadimages=this.preloadimages for (var i=0; i<arguments.length; i++){ if (arguments[i] && arguments[i].length>0){ preloadimages[preloadimages.length]=new Image() preloadimages[preloadimages.length-1].src=arguments[i] } } } } And the code of the page in question: Code: <head> <title>Admininstration</title> <link rel="stylesheet" type="text/css" href="./css/epoch_styles.css" /> <!-- Calendar Stuff --> <script type="text/javascript" src="./javascript/epoch_classes.js"></script> <script type="text/javascript">window.onload = function() { var calendar1 = new Epoch('interactiondate','popup',document.getElementById('calendar1_container'),false); var calendar5 = new Epoch('expensedate','popup',document.getElementById('calendar5_container'),false); }; </script> <!-- End Calendar Stuff--> <!--Section Collapse stuff --> <!DOCTYPE HTML> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="./javascript/animatedcollapse.js"></script> <script type="text/javascript"> animatedcollapse.addDiv('Clients', 'fade=1') animatedcollapse.addDiv('Interactions', 'fade=1') animatedcollapse.addDiv('Expenses', 'fade=1') animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted //$: Access to jQuery //divobj: DOM reference to DIV being expanded/ collapsed. Use "divobj.id" to get its ID //state: "block" or "none", depending on state } animatedcollapse.init() <!--End Section Collapse Stuff --> </script> </head> <a href="javascript:animatedcollapse.toggle('Clients')"><h1>Clients</h1></a> <? echo' <div id="Clients" style="display:none"> <table> <tr> <td valign="top">'; include ('./addclient.php'); echo'</td> <td valign="top">'; include ('./displayclient.php'); echo'</td> </tr> </table> </div> '; ?> <a href="javascript:animatedcollapse.toggle('Interactions')"><h1>Interactions</h1></a> <? echo' <div id="Interactions" style="display:none"> <table> <tr> <td valign="top">'; include ('./addinteractions.php'); echo'</td> <td valign="top">'; include ('./displayinteractions.php'); echo'</td> </tr> </table> </div> '; ?> <a href="javascript:animatedcollapse.toggle('Expenses')"><h1>Expenses</h1></a> <? echo' <div id="Expenses" style="display:none"> <table> <tr> <td valign="top">'; include ('./addexpenses.php'); echo'</td> <td valign="top">'; include ('./displayexpenses.php'); echo'</td> </tr> </table>'; mysql_close(); // Close the database connection ?> Code: <script> function clickPost(el){ var im=el.parentNode.style.backgroundImage; var sp0=im.split("/"); var sp1=sp0[sp0.length-1].split("."); document.getElementById("formInp").value=sp1[0]; document.F.submit(); } </script> Code: <div class="thumb" style="background-image: url('images/1.jpg');"><a href='javascript:void(0)' onclick='clickPost(this)'> This code above snags the number from the background-image file, I changed my code around and I believe I need to go to a childnode now to grab the number from the img src but am having issues figuring it out. Thanks Below is the current code for displaying the thumbs: Code: <div id="container"> <a href='javascript:void(0)' onclick='clickPost(this)'><div class="overlay"></div> <div class="image"><img src="images/2.jpg" /></a></div> </div> I am really struggling to do something really painfully simple he just create a class in javascript!! I tried this, based on a google search: Code: function myclass() { this.myvar = 1; this.mymethod = function() { alert(this.myvar); } } But, of course, this.myvar in mymethod is not the same as this.myvar in myclass. So I did another google search, and tried this: Code: function myclass() { this.myvar = 1; this.prototype.mymethod = function() { alert(this.myvar); } } And I get the error report: "this.prototype is undefined". So I tried parent and super in place of this within mymethod, but both of those throw up an "<whateve> is undefined" error too. I give up!! Is it just me, or is trying to write OO Javascript really like trying to grapple with a slippery fish?!! Something that should be really painfully simple is proving to be a nightmare ... |