JavaScript - Need Help With Onclick Script..please
I'm a complete Noob to Java. Just retired and starting a new venture.
I need to add a sound effect to my image. I read the Onmouseover tutorial using HTML5 and its exactly what I need but as hard as I try I cannot make sense of it. My source code: Code: <html><head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>You Could Win BIG!</title> <script type="text/javascript"> //preload images first img1=new Image() img1.src="/images/themagicbutton.png" img2=new Image() img2.src="/images/themagicbutton5.png" </script> </head><body bgcolor="C4C996"> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <center><a href="http://bit.ly/tZ7iUv" onMousedown="document.images['example'].src=img2.src" onMouseup="document.images['example'].src=img1.src"> <img src="/images/themagicbutton.png" name="example" border=0></a> </body></html> I want to ad the following sound to my image above: magic-chime-03.mp3, magic-chime-03.wav, magic-chime-03.ogg as an OnClick. I need your expertise in setting this scipt up and where to place it in my source code. Any help I would be eternally grateful. Similar TutorialsI finished this code, the full code is not here, but when I ran it as a diagnostic the action did not occur when i clicked on the "process item" button. I believe it may have something to do with the script, but i am new to javascript and cannot seem to figure it out, it is supposed to multiply the price by the number to give the value of sale (sale). Any help would be much appreciated!!! Code: <html> <script language="javascript"> function test() { var Items,Price,Number,sale; Items = parselfloat(document.victoria.secondnumber.value); Price = parselfloat(document.victoria.price.value); Number = parselfloat(document.victoria.num.value); sale = Price*Number; document.victoria.val.value=sale; } </script> <body><form name ="victoria"> <center> <table border=40 bordercolor="yellow"> <tr><td>Customer Number <input name ="firstnumber" type="text" size="6" value="1" ></td> <td>Home Delivery <input name="customer_name" type="checkbox"Checked></td><tr> <tr><td>Items Purchased</td><td><center><input name="secondnumber" type="text" size="12"></center></td></tr> <tr><td>Item Number</td><td><center><input name="itemnum" type="text" size="12" value="1"></center></td></tr> <tr><td>Price</td><td><center><input name="price" type="text" size="12"></center></td></tr> <tr><td>Number Purchased</td><td><center><input name="num" type="text" size="12"></center></td></tr> <tr><td>Value of Sale</td><td><center><input name="val" type="text" size="12" value="0"></center></td></tr> <tr><td>Customer Total</td><td><center><input name="total" type="text" size="12" value="0"></center></td></tr> <tr><td></td><td><input type="button" value="Process Item" onclick="test()"></td></tr> </table> </center></form> </body></html> Have spent over 40 hours trying to make something like this work. Any help will be received with profound gratitude. Code: <!-- First, we reference a script whose purpose is to create a space for session variables similar to cookies. Works if it appears early in body of Drupal page, so this is not the issue (Drupal parses pages down for display so there is no user <head> tag). --> <script type="text/javascript" src="sessvars.js"></script> <script language = "javascript"> <!-- We create the variable whichpage because we will be creating a session variable sessvars.whichpage courtesy of the sessvars.js script--> var whichpage; <!-- Next, we create a lookup table: --> var myTable = new Array(); myTable[1] = "001_Front_Cover_jpg.jpg"; myTable[2] = "002_Inside_Front_Cover_jpg.jpg"; myTable[3] = "003_Frontispiece_Design_jpg.jpg"; </script> <!-- Next, we create a table with thumbnails; each thumbnail image is a hyperlink which, onClick, is supposed to run a script assigning a value to sessvars.whichpage, so when Drupal node 23 is reached, it can use the value of sessvars.whichpage to select the array (myTable) element which corresponds to the full-sized picture we want to load. Node 23 also has the lookup array (myTable). The node inserts the snippet contained in the myTable element into a URL of the picture to load. --> <!-- Here we define the table --> <!-- Next, we have a series of hyperlinks which present the table with thumbnails so clicking on the thumbnail assigns a value to sessvars. whichpage and then transfers to the node that uses that value: --> <a href="23" onClick="<script language = 'javascript'> sessvars.whichpage=1; </script>" <img> </img> </a> <a href="23" onClick="<script language = 'javascript'> sessvars.whichpage=2; </script>" <img> </img> </a> <a href="23" onClick="<script language = 'javascript'> sessvars.whichpage=3; </script>" <img> </img> </a> <!-- The problem is that this flat does not work. When we get to node 23 sessvars.whichpage shows as undefined. It used to work when I called a function instead of put the script into each link, but I found there was no simple way to get the value (1,2,3 etc.) to the function --> Is there an answer. Thank you so much in advance. Leon Malinofsky Hello Everyone, I am in the process of creating a billboard script for our company front page which will switch between two images. I am using the following script as a base: http://tympanus.net/codrops/2009/12/...query-and-css/ I am eager to learn coding, but am still a novice at it so I was wondering if anyone could assist me with adding the following functionality: 1. Rather than (or perhaps in addition to) having the two images change based on a timer, I'd like to be able to insert a "next" arrow. Therefore I will need assistance in coding a button to change the images from "ad_1" to "ad_2" which is currently done automatically by the interval timer 2. I'd like to make the images clickable with unique destinations (so when you click on "ad_1" it will take you to "link 1", "ad_2" will take you to "link 2" Below is my current code: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Rotating Billboard with jQuery</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8"/> </head> <body> <div class="palmtrees"></div> <div class="powerline"></div> <div class="city"></div> <div class="container"> <div class="ad"> <div id="ad_1" class="ad_1"> <img class="slice_1" src="ads/ad1_slice01.jpg"/> <img class="slice_2" src="ads/ad1_slice02.jpg"/> <img class="slice_3" src="ads/ad1_slice03.jpg"/> </div> <div id="ad_2" class="ad_2"> <img class="slice_1" src="ads/ad2_slice01.jpg"/> <img class="slice_2" src="ads/ad2_slice02.jpg"/> <img class="slice_3" src="ads/ad2_slice03.jpg"/> </div> </div> </div> <div class="billboard"></div> <a class="back" href="http://tympanus.net/codrops/2009/12/16/creating-a-rotating-billboard-system-with-jquery-and-css/"><a> <script src="jquery-1.3.2.js" type="text/javascript"></script> <script> $(function() { $('#ad_1 > img').each(function(i,e){ rotate($(this),500,10000,i); }); function rotate(elem1,speed,timeout,i){ elem1.animate({'marginLeft':'18px','width':'0px'},speed,function(){ var other; if(elem1.parent().attr('id') == 'ad_1') other = $('#ad_2').children('img').eq(i); else other = $('#ad_1').children('img').eq(i); other.animate({'marginLeft':'0px','width':'266px'},speed,function(){ var f = function() { rotate(other,speed,timeout,i) }; setTimeout(f,timeout); }); }); } }); </script> </body> </html> And here is a working example: http://www.santamarinas.com/RS/Tests/Billboard/ Thank you in advance for your help!! I'd like to place an AJAX call to load another SELECT menu in my form, and I'm having trouble finding a tutorial. Can someone point me to a good tute, or provide some guidance/examples here? For your Copying/Pasting pleasure , here's an example button for which I'd include the onclick(): Code: <button type="button" >Add</button> And here's an example SELECT menu: Code: <select id="idNumber" name="weekday_1['workPeriod_new'][] > <option value="1" >one</option> <option value="2" >2</option> </select> Thanks-a-bunch, ~ Mo NOTE: Overall, I'm pretty green in JS. Hi Guys, I am very new to java and current I am creating a button to open a window as a pop up. This window needs to load a asp page that I have already built. So on the parent page I have created a button. INPUT onclick=Somejava; type=button value=button I am not sure how to set the onclick to run some scripts and then set the href before doing a window.open The scripts it needs to run are as follows: Code: var urno=window.parent.parent.frames['patframe'].document.getElementById("BANNERRegistrationNo"); href="\\\\server\\folder$\\"+urno.value+"\\"; window.open If anyone could give me a hint of where to start... Do I put this in a separate script? If so how do I call it... Or is there an easier option? I'm currently working on a project and I am doing a bunch of image switching. I'm having a problem with the following... I have seven medium image objects and one small one. One is at the top and the other 7 are below. When one of the 7 is clicked, it then becomes the one up top and the one up top then takes the place of the image clicked. This needs to be able to happen no matter which of the seven i click. Also when you click one of the seven it runs a script to change 9 other images in the center of the page. this isnt too important because i have it working already. What i have is, each of the seven images run their function that changes the 9 center images and then it runs another function. What i need is for that function to determine which company for example(shaws, lowes, target) the top image belongs to and replace the image that was clicked with the top one. But i also need to replace the NAME="" and ONCLICK="function()" with the proper ones for the original company up top. Please if you can understand what im trying to do let me know, if you need further clarification i can do so. i can draw a picture of what im trying to do or the layout if needed but i cant necessarily show anyone the project due to a non-disclosure. Is it possible disable an onclick after clicking it and then enable it from another onclick by id Code: <img id="one" href="images/homepage/sliders/bonus_button.jpg" style="position:relative; top:30px; left:50px; height:30px; width:70px; float:left;"> This code runs when it is clicked: Code: $("#one").click(function() { runEffectB(); return false; }); What I would like to happen is for either runEffectB() to not run if it was just run or to disable the #one.click once it has run. I am assuming I will be able to re-enable it from another onclick running a similar function. This is jquery and jquery ui if that helps. Any ideas much appreciated. hi everybody.. i have this simple code: Quote: <html> <head> <script language="javascript" type="text/javascript"> document.write("<input type='button' value='push' onclick='hi()'/>"); function hi() { alert("hi"); document.write("<input type='button' value='enter' onclick='javascript: bye()'/>"); } function bye() { alert("bye"); } </script> </head> <body> </body> </html> if i try to run it on chrom its works well.. but on IE or FireFox its not define the bye() function.. whats the reason?! and how i can solve it?.. thanks very much.. Hey guys, OK, so I have two buttons (code below) that when a user clicks on it, it will place text in a textarea. You can view all the code below: Buttons: Code: <div id="newButton"> <a href="#"><img src="http://i49.servimg.com/u/f49/17/29/94/19/graphi10.png" alt="Request a Graphic"></a> <a href="#"><img src="http://i49.servimg.com/u/f49/17/29/94/19/review11.png" alt="Request a Review"</a> </div> The textarea ID is: Code: text_editor_textarea and this is the code that I would like to be placed inside the textarea: Code: Nature of Request: Creation Size: Primary Colors: Text To Insert: Donation: Extra Information: URL: I tried this, but the BBCode would not keep it's structure and would all end up on one line. EDIT: Oh...The BBCode is parsing inside the code box >.< Hello... Here is an example of a site I'm working on: http://mrmatthewreese.com/surine/custominlays.php notice the links for the alien cross bones, celtic knot etc...change colors once they are clicked on? Is it possible to have the top (alien crossbone) be set to black before it is clicked on then changed to the grey color once a different link is clicked? Just curious if anyone can help. Here is the javascript code: <script language="JavaScript" type="text/javascript"> /*<![CDATA[*/ var Lst; function CngClass(obj){ if (Lst) Lst.className=''; obj.className='boldlink'; Lst=obj; } /*]]>*/ </script> <a href="#" onclick='changeimage();'><span onclick="CngClass(this);">Alien Crossbones</span></a><br /> <a href="#" onclick='changeimage2()'><span onclick="CngClass(this);">Celtic Knot</span></a><br /> <a href="#" onclick='changeimage3()'><span onclick="CngClass(this);">Compass Rose</span></a><br /> <a href="#" onclick='changeimage4()'><span onclick="CngClass(this);">Fleurdelis</span></a><br /> <a href="#" onclick='changeimage5()'><span onclick="CngClass(this);">Geometrix</span></a><br /> <a href="#" onclick='changeimage6()'><span onclick="CngClass(this);">Modern Vine</span></a><br /> <a href="#" onclick='changeimage7()'><span onclick="CngClass(this);">Nouveau</span></a><br /> <a href="#" onclick='changeimage8()'><span onclick="CngClass(this);">Scorpion</span></a><br /> <a href="#" onclick='changeimage9()'><span onclick="CngClass(this);">Traditional Block</span></a><br /> <a href="#" onclick='changeimage10()'><span onclick="CngClass(this);">TrebleBass Clef</span></a> Hey. When a checkbox is checked, I want it to add the id number of what I've got in a PHP variable, to appear in a <input type="text" />. For example: The id is 1, 2, and 3. So 3 checkbox's. I click on the first, and it adds to another input field, '1'. I hit the second, and the same thing happens, except the id is 2. Of course, I know how to do the ID and all with PHP. All I need to do now, is where when you click a check box, it adds to another field, and adds & after every check. Here is my code: Code: <input type="checkbox" name="delete" onclick="this.checkedbox.style.display=(this.value=='checked' ? 'inline' : '2' )" /> <input type="text" name="checkedbox" /> Thanks. Hi i have a page that allows the user to enter details and also upload an image , I have onclick event on a submit button that goes off and performs a geocode on the postcode and saves the lat long to a database along with the other details they enter ( which all works fine) . The problem is that when i use the onclick event with the submit button it seems to bypass the onclick JS function and just go straight to the image upload bit. Can a button be a submit button and also have an onclick event or is there anything else i can do to fix the problem? <a href="#" onClick="showClubs(<% Response.Write x_ID_Nanny %>);" > Now this showclubs function shows a hidden div and at the end I have a return:false; but when you click on the link - it still seems to reload to the page and take you to the top how can I get it to just show the div without seeming to reload the page? 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 Hi, New to javascript. Doing web page with ASP/VB.NET. Have text boxes for UI on page. Two command buttons - Submit (for db update) and Cancel. I need the Cancel button to prompt the user to verify cancellation. Need OK/Cancel buttons on alert. If user selects Cancel-no action. If user selects OK then I want the text boxes cleared of user text input and focus returned to first text box. I think this may be the code but do not know how to apply it. function Clear() { var res=window.confirm("Please confirm cancellation-text boxes will be cleared"); if(res==true) { document.getElementById("StrtDte").value=""; document.getElementById("EndDte").value=""; document.getElementById("txtProjRegHrsAl").value=""; document.getElementById("txtProjOTHrsAl").value=""; document.getElementById("ddlRAS").focus(); } } Is this code valid or invalid for the events I need? How do I set it to fire when user clicks the ASP Cancel button? Thanks, John Hello Everyone! I have one link that I need to do two onclick events at once. At first I just tried writing them both but that obviously didn't work b/c I'm here! This would result in the first onclick event tacking place and not the second. So my question is could someone tell me how to write this code in javascript, so both events will take plack onclick, and then how I should reference that script within my link? Thank you for taking a look Code: <a href = "javascript:void(0)" onclick = "document.getElementById('light<?php echo $count;?>').style.display='none';document.getElementById('fade<?php echo $count;?>').style.display='none'" onclick = "document.getElementById('light<?php echo $count + 1;?>').style.display='block';document.getElementById('fade<?php echo $count + 1;?>').style.display='block'"> Previous </a> I need a code that makes the following: 1. I need a link to a certain website 2. If someone click that link it opens in new tab and it makes 1. link invisible and show a another link on the same place with a time delay of 5 seconds Ok so I have two images class1 & class2 which both have opacity:0.3; and filter:alpha(opacity=30); added with css. I am trying to get it so when I click on class1 it will either fade in (ideally) or display as 100% opacity. I do not want both class's to be able to be 100% so if one is clicked the other would be 30%. I also have multiple instances of class1 and class2. If anyone can help me I will praise you on the highest mountain! Thanks, B We have a function that validates a form and then does submit (and a bunch of other stuff) We called it using: Code: <td class="MyButtonStyle"> <a href="#" OnClick="MyFunction();" title="Save changes and continue">SAVE</a> </td> This worked fine on the browsers we were using (IE6 in the main), but we now find doesn't work on IE5.01, Mac and some others. OK, so having done some research I now realise I needed RETURN FALSE in OnClick. So ... faced with having to change a lot of pages I'd like to have the best possible syntax (by which I suppose I rellay mean most-browser-compatible), and I've seen a number of options; advice on picking a good'un would be much appreciated. Amongst the stuff I've seen is: Code: 1. href="#" onclick="MyFunction();return false;" 2. href="#null" onclick="MyFunction();return false;" 3. href="NoJavaScriptAbility.htm" onclick="MyFunction();return false;" 4. href="#" onclick="return MyFunction();" 5. href="javascript:;" onclick="return MyFunction();" 6. href="javascript://" onclick="return MyFunction();" 7. href="javascript:void(0);" onclick="return MyFunction();" 8. href="javascript:MyFunction();" What about what shows in the Status bar? Should I have an OnMouseOver event too to describe what MyFunction is going to do? Rather than displaying a meaningless link. Anything else to note? (This function is part of a library being reused for major web site development over the next however many years, and not for single-project build-and-throw-away, so all possible functionality, including The Kitchen Sink!, is up for consideration). Thanks Kristen i have a div that has a pointer cursor as the style. on click of the div, i'd like to change visibilities of some of my other divs, but i can't get it to run! can someone give me a push here? i think dw is telling me that there is an error in my code, but cant see it...
Code: function getCP() { if (document.getelementbyid('apdiv11').innerHTML == "VIEW CONTROL PANEL") { document.getelementbyid('apdiv11').innerHTML = "BACK TO WEBSITE"; document.getelementbyid('wb_marquee1').style.visibility = 'hidden'; document.getelementbyid('apdiv6').style.visibility = 'visible'; } else { document.getelementbyid('wb_marquee1').style.visibility = 'visible'; document.getelementbyid('apdiv6').style.visibility = 'hidden'; } } |