JavaScript - Switchmenu Help - Default First Item Open
Hi
I have copied and adapted the commonly found switchmenu script available widely on the web from Dynamic Drive. I understand that it might be dated now, but I am limited as to what I can do. Specifically, this code has to sit in a webpart within Sharepoint 2003, so no referencing external CSS or js files. The code below functions as desired, and opens the items one at a time, closing the previous before opening the next. However, what I want to do is have the first item default to being open. Any pointers? putting a onload in a body tag isn't an option (this code is popping into a webpart in sharepoint, so no access to the body tag). Many thanks -------------------------- <script type="text/javascript"> var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc) var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only if (document.getElementById){ //DynamicDrive.com change document.write('<style type="text/css">\n') document.write('.submenu{display: none;}\n') document.write('</style>\n') } function SwitchMenu(obj){ if(document.getElementById){ var el = document.getElementById(obj); var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change if(el.style.display != "block"){ //DynamicDrive.com change for (var i=0; i<ar.length; i++){ if (ar[i].className=="submenu") //DynamicDrive.com change ar[i].style.display = "none"; } el.style.display = "block"; }else{ el.style.display = "none"; } } } function get_cookie(Name) { var search = Name + "=" var returnvalue = ""; if (document.cookie.length > 0) { offset = document.cookie.indexOf(search) if (offset != -1) { offset += search.length end = document.cookie.indexOf(";", offset); if (end == -1) end = document.cookie.length; returnvalue=unescape(document.cookie.substring(offset, end)) } } return returnvalue; } function onloadfunction(){ if (persistmenu=="yes"){ var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname var cookievalue=get_cookie(cookiename) if (cookievalue!="") document.getElementById(cookievalue).style.display="block" } } function savemenustate(){ var inc=1, blockid="" while (document.getElementById("sub"+inc)){ if (document.getElementById("sub"+inc).style.display=="block"){ blockid="sub"+inc break } inc++ } var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid document.cookie=cookiename+"="+cookievalue } if (window.addEventListener) window.addEventListener("load", onloadfunction, false) else if (window.attachEvent) window.attachEvent("onload", onloadfunction) else if (document.getElementById) window.onload=onloadfunction if (persistmenu=="yes" && document.getElementById) window.onunload=savemenustate </script> Similar TutorialsDoes anyone know the default size of a popup window when using window.open()? Thanks Let me start of by saying that I'm a designer, not a programmer so I'll apologize in advance for having very little knowledge of javascript. I found a free script for a auto-advancing slideshow that allows you to give each image in the slideshow a unique link. My problem is that when you click on one of the pictures the link opens in a new window instead of loading in the default browser window. I have tried to search google for an answer but my lack of javascript knowledge has left me scratching my chin. Here's the code in the head of my page: Code: <script language="JavaScript1.1"> <!-- /* JavaScript Image slideshow */ var slideimages=new Array() var slidelinks=new Array() function slideshowimages(){ for (i=0;i<slideshowimages.arguments.length;i++){ slideimages[i]=new Image() slideimages[i].src=slideshowimages.arguments[i] } } function slideshowlinks(){ for (i=0;i<slideshowlinks.arguments.length;i++) slidelinks[i]=slideshowlinks.arguments[i] } function gotoshow(){ if (!window.winslide||winslide.closed) winslide=window.open(slidelinks[whichlink]) else winslide.location=slidelinks[whichlink] winslide.focus() } //--> </script> and here's the Body code: Code: <script> <!-- //configure the paths of the images, plus corresponding target links slideshowimages("images/services/3d_meter.jpg", "images/services/3d_prototype.jpg", "images/services/3d_stage_renderings.jpg", "images/services/atsite.jpg", "images/services/netstar.jpg", "images/services/photo_manipulation.jpg", "images/services/powerpoint.jpg") slideshowlinks("/", "/", "/", "/", "/", "/", "/") //configure the speed of the slideshow, in miliseconds var slideshowspeed=8000 var whichlink=0 var whichimage=0 function slideit(){ if (!document.images) return document.images.slide.src=slideimages[whichimage].src whichlink=whichimage if (whichimage<slideimages.length-1) whichimage++ else whichimage=0 setTimeout("slideit()",slideshowspeed) } slideit() //--> </script> fooling around with it, I think I have determined that my problem is the window.open in the function gotoshow, but again, I'm a designer who has little knowledge of how this actually works. If it helps, here is a link to my site where I have the slideshow, http://gravescreativedesign.com/services.html All of the images link to the index page for my site at the moment for testing purposes, but these images will eventually link to different urls within my portfolio section of my website. Hi Peers, i have a Drop down list with 10 choices (skillset). users must choose one skillset and the corresponding level (beginer/intermediate/master). ( they have to do this 10 times for all the sillsets) what i want is : 1 - i need to show up only one record (dropdowanlist) with level then have a button to add new skill and level if required 2- then when they choose the 1st skill from the dropdown , this one will not show up on the 2nd choice dropdown. is it possible any help ? thanks guys Hi, I want to restrict opening my popup window if it is already opened. For simple scenario, it is quite possible to do but in my case -- 1) When parent page is opening popup window, it is getting refreshed (required from client for some reason). 2) Once submit button is clicked from popup window, again parent page is getting refreshed (again its a requirement from client side). With these 2 conditions, I lost my saved value from variable and hence new popup is keep coming when the action is same. Currently I am using below code to open popup [CODE] function OpenWindow() { if(winPop && !winPop.closed) { alert("Popup is already open"); } else { winPop = window.open('MyPopupPage.aspx'); } } [CODE] Please help me to get rid of this problem. Thanks in advance. - Bhasker I do write some php, but have not much idea about JavaScript. I use window.open to open 10 pages simultaneously. I prefer to open them with a time delay from each other to put less load on the target server. This is my code with no delay. (I played around with setTimeout but can't get it to work.) PHP Code: <a href='http://www.".$new[9]."' onclick="window.open('http://www.".$new[0]."/'); window.open('http://www.".$new[1]."/'); window.open('http://www.".$new[2]."/'); window.open('http://www.".$new[3]."/'); window.open('http://www.".$new[4]."/'); window.open('http://www.".$new[5]."/'); window.open('http://www.".$new[6]."/'); window.open('http://www.".$new[7]."/'); window.open('http://www.".$new[8]."/')\" target='new300/'>Open 10</a> I am trying to impliment Javascript code to replace the MS Tabular data control. How do I go about creating a Fields collection object that has a default method of Item(idx) ie. myrs.Fields.Item(4).name is the same as myrs.Fields(4).name What I'm trying to do is to do something similar to what this person wanted on their question: http://www.webmasterworld.com/javascript/3338586.htm I already have it so when the user clicks on one of the links, then it changes to the active class. But now I would like to have the first link already have the active class (which is the effect the links will have when the user clicks on it) and then have the same effect happen thereafter the user clicks on the links. Here is the Javascript: Code: <script type="text/javascript"> var hrefs=document.getElementsByTagName("a"); var hrefs=document.getElementsByClassName("links"); var preA=""; for(var i=0;i<hrefs.length;i++){ hrefs[i].onclick=function(){ if(preA!="" && preA!=this){ preA.className="links"; } this.className="active"; preA=this; } } </script> Here is the CSS: Code: a.links:link { color: #FFF; text-decoration: none; } a.links:hover { color: #96C; text-decoration: none; } a.active { color: #96C; text-decoration: none; } Here is the HTML: Code: <a class="links" href="#">Curriculum Vitae</a> | <a class="links" href="#">Teaching Philosophy</a> | <a class="links" href="#">Artist Statement</a> Hello, I'm using pull downs for date but it always starts up "Dec" "31" "Year". How can I set it to start as "Month" "Date" "Year"? Thanks. PHP Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Main</title> </head> <body> <br> <form name="form1" id="startOfForm"> <table><tbody> <tr> <td class="question"><label for="birthdate">Select Birthdate</label></td> <td> <select name="selMonth" id="selMonth" > <option value=0 selected>Month</option> <option selected value="1">Jan</option> <option selected value="2">Feb</option> <option selected value="3">Mar</option> <option selected value="4">Apr</option> <option selected value="5">May</option> <option selected value="6">Jun</option> <option selected value="7">Jul</option> <option selected value="8">Aug</option> <option selected value="9">Sept</option> <option selected value="10">Oct</option> <option selected value="11">Nov</option> <option selected value="12">Dec</option> </select> <select name="selDate" id="selDate" > <option value=0 selected>Date</option> <option selected value="1">1</option> <option selected value="2">2</option> <option selected value="3">3</option> <option selected value="4">4</option> <option selected value="5">5</option> <option selected value="6">6</option> <option selected value="7">7</option> <option selected value="8">8</option> <option selected value="9">9</option> <option selected value="10">10</option> <option selected value="11">11</option> <option selected value="12">12</option> <option selected value="13">13</option> <option selected value="14">14</option> <option selected value="15">15</option> <option selected value="16">16</option> <option selected value="17">17</option> <option selected value="18">18</option> <option selected value="19">19</option> <option selected value="20">20</option> <option selected value="21">21</option> <option selected value="22">22</option> <option selected value="23">23</option> <option selected value="24">24</option> <option selected value="25">25</option> <option selected value="26">26</option> <option selected value="27">27</option> <option selected value="28">28</option> <option selected value="29">29</option> <option selected value="30">30</option> <option selected value="31">31</option> </select> <select name="selYear" id="selYear" > <option value=0 selected>Year</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> <option value="1989">1989</option> </select> </td> </tr> <tr> <td colspan=2><input type="submit" value="Submit form"></td> </tr> </tbody></table> </form> </body> </html> Hi all, I would really appreciate any help producing a slider bar that goes from 0 to 100 with step = 1 that has NO default value. Basically, I do not want to bias people in any way, and so do not want to have the default tab on the slider at 0 or 50 or whatever. The ideal slider bar would not have a tab initially and then a tab would appear once (and where) the user clicked on the slider bar. Thanks for any help, Adrian hai friends <script type="text/javascript"> function myfunction(x) { var xname = x.name; alert("gender - " +xname); } </script> </head> <body> <form action="index.php" method="post" name="frm2" id="frm2"> <input type="checkbox" name="male" onclick="myfunction(this)" /> male <input type="checkbox" name="female" onclick="myfunction(this)" /> female </form> when i use this code only check box which is selected will alerts me . i want all checkboxes names which are selected as alert plz help me Hi Ive got my menu displayed on this site http://valkesh.000space.com. The issue I am having is that I want the hover image (red part) to be displayed only when hovering the root li, and not all subsequent li items in the menu.. because as you may see now, even when hovering the li in the submenu the red gets displayed. The code I am using is the following Code: <script type="text/javascript"> $(document).ready(function () { $('#smoothmenu1 li').append('<div class="hover"></div>'); $('#smoothmenu1 li').hover( function() { $(this).children('div').fadeIn('500'); }, function() { $(this).children('div').fadeOut('500'); }).click (function () { $(this).addClass('selected'); }); }); </script> and Code: <div id="smoothmenu1" class="menu"> <ul> <li><a href="#">Page 1</a></li> <li><a href="#">Page 2</a> <ul> <li><a href="#">2.1</a> <ul> <li><a href="#">2.1.1</a></li> </ul> </li> <li><a href="#">2.2</a></li> <li><a href="#">2.3</a></li> </ul> </li> <li><a href="#">Page 3</a> <ul> <li><a href="#">3.1</a></li> <li><a href="#">3.2</a></li> <li><a href="#">3.3</a></li> </ul> </li> <li><a href="#">Page 4</a></li> </ul> </div> Is there a way to specify in the javascript functionality where to append the div to only the root li item? Thanks I'm trying to delete a item in a list. I'm getting a method not allowed error in IE8. Code: var selectOptions = document.getElementById('id_employees_cbo'); for (var i=0; i<selectOptions.options.length; i++) { if (selectOptions.options[i].selected == true) { selectOptions.options[i].remove(); break; } } Is there another way to do this? Thanks Hi, I have a list setup with links. The list scrolls with the css setting of overflow:auto. However, when a link in the list that is scrolled down to (that is hidden unless scrolled down to) is clicked, I'd like to hold the list at that list item so that the viewer can return to the same line in the list and click the next li. Right now, the list resets to the top after a li link is clicked... I have a feeling this is something simple, but I'm guessing it would be javascript...?? The site to view - click here and then see the left side scrolling list. Thanks!! This function is part of a page that will delete a product that a customer has selected. The question I have is what is the line line that actually removes the item from the list of products chosen? From my understanding, in order to establish an array, new array = elements[i] has to be added but Im thinking that elements[i] is the array that holds the product. Does the "0" in this line actually delete the item? document.template.elements[i].value = 0 ; Code: function del_item(X,msg) { // var msg = "Are you sure you want to delete this line item?" resp = confirm("Are you sure you want to " + msg + "?") ; if (resp) { var len = document.template.elements.length //loop to put into arrays for (var i = 0; i < len; i++) { var lname = document.template.elements[i].name ; if(lname == X) { document.template.elements[i].value = 0 ; process_order(0) ; document.template.loginpath.value = "CO" ; document.template.submit() ; } } } else { return ; } } Hello everyone. This a css code in <head>: Code: .pagination{ width: 530px; /*Width of pagination DIV. Total width should equal slider's outer width (400+10+10=420)*/ text-align: right; background-color: white; padding: 5px 10px; } .pagination a{ padding: 0px 5px; text-decoration: none; color: #410B38; font-weight:bold; font-family:Arial; background: white; } .pagination a:hover, .pagination a.selected{ color: white; text-decoration: none; font-weight:bold; font-family:Arial; background-color: #410B38; } for a div with class=pagination (below) which contains the pagination of mysql data display: Code: <div class="pagination"> <?php $sql = "SELECT COUNT(id) FROM tablename"; $rs_result = mysql_query($sql,$mysql_connection); $row = mysql_fetch_row($rs_result); $total_records = $row[0]; $total_pages = ceil($total_records / 5); for ($i=1; $i<=$total_pages; $i++) { echo "<a href='mysqldatadisplay.php?page=".$i."'>".$i."</a>"; }; ?> </div> I want everytime someone clicks on another number in order to change page, that clicked number to have different style than the other numbers as long as one stays on that page and when one clicks on a different number I want that number to behave in the same way. Someting like highlighting the navigational item that you're on. Thank you very much in advance! I need to clear the default value from a textarea when a user clicks on the textarea and then replace it if the user clicks away from the textarea without modifying it. I have managed to accomplish this with the textfields in my forms but I am struggling to get the textarea element to mimic this behavior. Here is the script I am using: Code: addEvent(window, 'load', init, false); function init() { var formInputs = document.getElementsByTagName('input'); for (var i = 0; i < formInputs.length; i++) { var theInput = formInputs[i]; if (theInput.type == 'text' && theInput.className.match(/\binput\b/)) { /* Add event handlers */ addEvent(theInput, 'focus', inputText, false); addEvent(theInput, 'blur', replaceDefaultText, false); /* Save the current value */ if (theInput.value != '') { theInput.defaultText = theInput.value; } } } } function inputText(e) { var target = window.event ? window.event.srcElement : e ? e.target : null; if (!target) return; if (target.value == target.defaultText) { target.value = ''; } } function replaceDefaultText(e) { var target = window.event ? window.event.srcElement : e ? e.target : null; if (!target) return; if (target.value == '' && target.defaultText) { target.value = target.defaultText; } } HTML: [HTML] <form action="#"> <fieldset> <legend></legend> <input type="text" value="Your Name" id="name" class="input" /> <label for="name">Name Required</label><br/> <input type="text" value="Your Email" id="email" class="input"/> <label for="email">E-mail Required</label><br/> <input type="text" value="Your Website" id="website" class="input"/> <label for="website">Website</label> <textarea rows="15" cols="71">Your Message Goes Here.</textarea> <input type="submit" value="Submit Comment" class="button" /> </fieldset> </form> [/HTML] I am really just trying to get this form to behave the way all other forms on the internet work- where text clears when a user clicks on a form element and replaces itself if the user doesn't enter new text. I have it working on the text field but no the textarea. Help! Okay, new to this magical thing called Javascript and LOVING it. Don't know how I avoided it all these years. Running into a stupid issue and I am sure it is just something I am missing. I have a hidden field in my page with the default value of HELLO. I am trying to make a change based on the default value, but I obviously am doing something wrong because it won't display my hidden field value. Any help would be greatly appreciated. Code: <html> <head> <script> function checkForm() { var testing = document.getElementById("testing").value; document.getElementById("result").innerHTML = testing; } </script> </head> <body> <input type="hidden" name="testing" value="HELLO" /> <input type="submit" value="submit" onClick="checkForm()"; /> <div id="result"></div> </body> </html> I am dynamically appending an img to the inner HTML of an element, to add in help in the form of a clickable icon next to select elements. When the img is added to an anchor the image of course becomes part of the link, and clicking the image invokes the anchor's action. The img has an onclick handler which triggers the dynamic help pop-up. My problem is that I can't seem to block the default anchor action, and thus the anchor is invoked also. The img onclick handler is called before the anchor event is processed (an alert popup will block the anchor's execution until the alert is dismissed), but returning false from it does not block the anchor's action. Any suggestions? I can move the img element to be a peer of the anchor element instead of a child, but I would like a programmatic fix instead of changing the way it interacts with the DOM if possible. Thanks. Is there a way to change the text from OK to CLOSE on an alert box ?
The code below is supposed to cancel the default form behavior when it finds certain info missing. Currently, however, in spite of detecting missing info it allows the form submission to continue. Anyone see what wrong? Thanks. Code: var DOM = YAHOO.util.Dom; YAHOO.util.Event.onDOMReady(init); function init() { YAHOO.util.Event.addListener("contact_form", "submit", checkForm); } function checkForm() { var fName = DOM.get('f_name'); var lName = DOM.get('l_name'); if (fName.value == "") { DOM.get('f_name_error').innerHTML = "This field is required!"; fName.focus(); return false; } |