JavaScript - Any Advise Would Be Greatly Appreciated.
Hi all,
I have just stated university a few weeks ago and have never programmed before.I am really stuck on this assigment .In the programm you have to enter you date of birth throught prompt (22).then your year of birth (yyyy),then your month (nov). I am really stuck and have been for days in requards how to put the information gained through prompt function into a date object().So i can get the users day of birth .Heres the code i have written .the varibles num5+num9+num1 is the users input but i just dont know how to assign it to the date object I have tryed heaps of ways but carnt get any thing to work .Please Help. head> <script> var tit1=('<title> Get your Stats </title>'); var tit2=('<h1> IT\'s about time...</h1><br /> ') var num1 =(''); num1=prompt('Enter The Year You Were Born','19XX'); var currentTime = new Date() var year = currentTime.getFullYear() var ansVar = year-num1; //User input year calculation var ageEx = (ansVar/62.7)*100; // Life% calculation var num2=ansVar var num3= ansVar*365.2424; // Days calcuation var month =('janfebmaraprmayjunjulaugsepoctnovdec'); var num5 =(''); num5=prompt('Enter The Month You Where Born','jan'); num5=(num5.substring(0,3)); var lowCas=(num5.toLowerCase());//users input conmverted to lower case/ var num9=prompt ('Enter you date of birth','29'); var d = new Date (num5+num9+num1)//<<<<this random date entered here will give the day. alert (d); //STUCK HERE HOW DO I CONVERT num5+num9+num1 to a day????????:: document.write(tit1); //output document.write(tit2); document.write(('You have lived ')+ageEx.toFixed(0)+('% of your life.<br />')); document.write(('You are ')+ansVar+(' years old.<br />')); document.write (('You are ')+num3.toFixed(0)+(' days old.')); </script> </head> </html> Any advise would be appreciated thanks Shayne darcy. Similar TutorialsI have been given files for my site and would like to know what the following script does or could do ? Code: function parseScript(_source) { var source = _source; var scripts = new Array(); // Strip out tags while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) { var s = source.indexOf("<script"); var s_e = source.indexOf(">", s); var e = source.indexOf("</script", s); var e_e = source.indexOf(">", e); // Add to scripts array scripts.push(source.substring(s_e+1, e)); // Strip from source source = source.substring(0, s) + source.substring(e_e+1); } // Loop through every script collected and eval it for(var i=0; i<scripts.length; i++) { try { eval(scripts[i]); } catch(ex) { window.execScript(scripts[i]); } } return source; } this is one of the calls to this script I found in the other site files. Code: document.getElementById(element).innerHTML=parseScript(xmlhttp.responseText); is there a possible security risk on this ? any help on this is grately appreciated. Hi all, The following code is an assigment.I have it running with out any errors.It has to take the array (arrayToshuffle) and through running though the end of the (arrayToshuffle) the string has to be shuffled.We havent learnmt shuffle() yet.) I think the problem is these lines. arrayToShuffle[index]=arrayToShuffle[swapIndex]; arrayToShuffle[swapIndex]=arrayToShuffle[index]; But no matter what varibles I put in these lines and how much i fiddle I carnt seem to get it to run without repeating the same elements in the output. I dont want anyone to fix it for me just advise on where I could look for problems. Am i missing somthing here? Heres the program if you run it you will see what I mean. <html> <head> <script> var arrayToShuffle = new Array('Ace','2','3','4','5','6','7','8','9','10','Jack','Queen','King'); var arraySize = arrayToShuffle.length; document.write('<h1>Array shuffling</h1>'); document.write('<p>Before shuffle: '+arrayToShuffle+'</p>'); SWAPS_TO_MAKE = 30; var index=0; var self_swaps=0; var counter = 0; while(counter < SWAPS_TO_MAKE) { var swapIndex = Math.floor(Math.random()*arraySize+1); arrayToShuffle[index]=arrayToShuffle[swapIndex]; arrayToShuffle[swapIndex]=arrayToShuffle[index]; if(index =swapIndex) { self_swaps++; } counter++; index = (index+1 % arraySize); } document.write('<p>After shuffle: '+arrayToShuffle+'</p>'); document.write('<ul>'); document.write('<li>Swaps made: '+SWAPS_TO_MAKE+'</li>'); document.write('<li>Self swaps: '+self_swaps+'</li>'); document.write('<li>Effective swaps: '+(SWAPS_TO_MAKE-self_swaps)+'</li>'); document.write('<li>Effective rate: '+((SWAPS_TO_MAKE-self_swaps)/SWAPS_TO_MAKE)+'</li>'); document.write('</ul>'); </script> </head> <body> </body> </html> Thanks heaps Shayne Darcy Hello, Iam currently experimenting with Java Scripting and have hit a wall about the use of Functions. I am trying to create a difference function which would work out the difference between two numbers. e.g. 14 and 18 I am able to create a function and if statement to find the larger number of a argument but am having trouble writing one to find the difference between two numbers. Iam also confused (i know probably a silly question) but is the operator used the same for this function. Hope people can make sense of that. Thanks, Hi, I am having a slight difficulty and hope someone can easily set me straight. I am trying to use the following code to track a button click and the second onclick event, the urchin tracking is not being completed but the first function is.... can someone please hopefully set me straight easily on the code? Many thanks Steve123. Code: <input type="submit" name="Submit" value="Buy Product" class="buy" onClick="document.form.submit();javascript:urchinTracker('/html/productdeals_button.asp')"> Hi guys, Just a simple question, Since we can't delete object created with document.createElement(), and just let javascript internal garbage collection do the work. I would much appreciate if anybody would advise me, whether we should nullify the object first, for complete deletion by this collector? Thanks for reading, and advising... Hendra. I have a page that takes nodes from drupal and pulls the athletes information and renders it into a roster page via a PHP array. initially the page did not have a logical sort and basically was rendered in the order of the node creation. I added sorttable.js to the file and you could then sort based on the header. However, our head coach wanted it to be sorted onLoad by player number (first column) so I added datatable and set aasorting to 0, asc and it actually sorts the second column (name) instead of column 1. No matter which column I set it to it only sorts the name column. If I could get some advice about how to fix this I would appreciate it. Code: <style type="text/css">table.sortable th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sorttable_nosort):after { content: " \25B4\25BE" } </style> <script src="/jscript/sorttable.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#roster').dataTable( { "aaSorting": [[ 0, "asc" ]] } ); } );</script> <table width="100%" cellpadding="2" cellspacing="2" border="1" class="sortable" id="roster" style="border-bottom:1"> <thead> <tr> <?php if( ! empty($vars['sport']->field_sport_show_number) && 1 == $vars['sport']->field_sport_show_number['und'][0]['value'] ): ?> <th class="style4, sortBy" style="width: 14px;" data-sortType="numeric" id="number"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">#</span></th> <?php endif; ?> <th class="style4" style="width: 14px;" ><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Name</span></th> <?php if( ! empty($vars['sport']->field_show_class) && 1 == $vars['sport']->field_show_class['und'][0]['value'] ): ?> <th class="style4" style="width: 14px;"><span style="font-family: Arial, Helvetic Hi there I've just completed a lovely slideshow script on my homepage. It works great in Firefox, but doesn't display at all in IE. It's on a live test page he http://www.modern-wedding-ideas.co.uk/index2.html I'm sure I'm just missing something really simple. Any help would be greatly appreciated. Also, this is a copy and paste job: I'm a newbie to javascript! So please be gentle. Many thanks Nicola I have to design a javascript program to capture five different numbers (monetary values), and save it in memory. Then another one that converts that value to, let's say, Euros, and display interest and commisions (which are values I'll have to add later, but the actual coding for the calculation is what's confusing to me. Let's just say, take 10% out of the initial value for interest, and 15% for commission). I would appreciate any help
Hey. Right, so I've just paid a guy to design and code just the layout files, not the content, panels, etc. I've coded a panel which will allow my staff to post news articles which will be displayed on the main website. Adding, Editing, Deleting news and all the rest works 100% fine however it appears that the designer has coded the news displayer into a .JS (javascript) file. The news displayer looks like this: ^ This is what it looks like when you hover over one of the 3 news items shown on the right. The image (blue box) changes depending on which news item you hover over This is what it looks like when you then hover over the image for that article: The HTML: Code: <div class="left"> <div id="headline_image_box"> <a href="#"> <img name="imagename" src="_images/_headlines/1.png" alt="Description" /> <span class="desc" id="description"> <script type="text/javascript">writetext(firsttext)</script> </span> </a> </div> </div> <div class="middle"> <a href="#"> <div class="headline" onMouseover="document.imagename.src=image1.src, writeDesc(desc1)" onMouseout="document.imagename.src=image1.src"> <strong>So far so good for Wiggins</strong><br /> Team Sky's Bradley Wiggins says he's going from strength to strength at the Vuelta a Espana. </div> </a> <a href="#"> <div class="headline" onMouseover="document.imagename.src=image2.src, writeDesc(desc2)" onMouseout="document.imagename.src=image2.src"> <strong>Spurs locked in Cahill talks</strong><br /> Bolton Wanderers and Tottenham Hotspur are locked in talks regarding a deal for Gary Cahill. </div> </a> <a href="#"> <div class="headline" onMouseover="document.imagename.src=image3.src, writeDesc(desc3)" onMouseout="document.imagename.src=image3.src"> <strong>Santon set for medical</strong><br /> Italy international Davide Santon has arrived in England to finalise a move to Newcastle United. </div> </a> </div> The Javascript File: Code: if (document.images) { image1 = new Image image2 = new Image image3 = new Image image1.src = "_images/_headlines/1.png" image2.src = "_images/_headlines/2.png" image3.src = "_images/_headlines/3.png" } var desc1='<strong>13th AUG</strong>Description 1' var desc2='<strong>12th AUG</strong>Description 2' var desc3='<strong>11th AUG</strong>Description 3' function writeDesc(what){ document.getElementById('description').innerHTML=''+what+''; } Database Structu Code: CREATE TABLE IF NOT EXISTS `news` ( `id` int(2) NOT NULL AUTO_INCREMENT, `title` varchar(100) NOT NULL, `author` varchar(100) NOT NULL, `category` varchar(100) NOT NULL, `article` varchar(50000) NOT NULL, `image` varchar(500) NOT NULL, `j` varchar(5) NOT NULL, `M` varchar(5) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; j = Date with letters on end. Eg. 4TH M = 3 character form of month. ALL details submit into database fine, that is not my issue. My issue is that I want to get the latest three articles from the database and echo the values from the database into the javascript however this stuffs up the script completely. I'm not very experienced with using Javascript & PHP together but I noticed something was wrong when I echoed it into the script. Anyone with any ideas/suggestions it'd be very helpful and appreciated! I'd prefer not to have to change to a completely new script, so if you have a way to integrate the MySQL information into the Javascript it'd be great! Hi All, I have two scripts which I want to try and integrate. I am using a nice gallery script to show thumbnails which are appended to a an image wrapper which on click of the thumbnail shows the larger image in the image wrapper, I am trying to implement cloud zoom which is a plugin which uses image srcs to then point to an anchor href to show another larger zoom image either in the same place.. which is what I am trying to do or in another div beside. I have had to set me img srcs up in a certain way to easily enter some product details. and I need to try an manipulate the code to make it work to suit my file layout. I am using a var= images [ with a series of file locations and info such as below { src: 'romanticabride/thumbs/tn_Shauna.jpg', srcBig: 'romanticabride/images/Shauna.jpg', title: 'Shauna', longDescription: '<b><H1>Shauna</H1></b><br><b>Romantica Of Devon <br><br><h2>Sizes Available:</h2><br> 6 - 32.<b><br><b><br><b><b><b><H2>Colours Available:</h2><b><br>Various<br>Please Enquire Below<br><br><br><br><a href="mailto:tracy@cherishbridal.co.uk?subject=Web Enquiry Regarding Romantica Shauna Bridal Gown"class="enquiry rose glow" >Click To Enquire About This Item </a>' }, what I need is for cloud zoom to work when the main image wrapper is hovered over which means it will need to add a class or when the whichever srcBig: is hovered over it gets wrapped by href to make the script work . one of my pages is http://www.cherishbridal.co.uk/romaticabride.html the cloud zoom script is at http://www.professorcloud.com/mainsite/cloud-zoom.htm.. I am happy to share a jsfiddle with someone or explain further or post some code. Thank you in advance |