JavaScript - I Have The Code. How To Make It Work?
I have this javascript code in this html page and it works fine. As soon as I try to add it to an existing page, it doesn't work. I have tried every position for the form and the script that I can think of but to no avail.
I would greatly appreciate soon expert guidance. Frank. The code page is here. The page that I am trying to add it to is here. Similar TutorialsSo I have made a website that you need a password to get into. The following javascript code works in Internet Explorer but, I need it to work in Safari also. Can anyone please rewrite this code, as simple as possible, to work in both Safari and Internet Explorer ? [CODE ]<!--// function mainpass() { if (pass.value=="password") {location="correct.HTML"}; else{location="wrong.HTML"}; } //--> [/CODE] Thanks in advance... Code: <script type="text/javascript"> <!-- NS4 = (document.layers) ? true : false; function launchVsee2() { try { location='vsee:'; } catch (err) { location='http://www.vsee.com'; return true } } //--> </script> This app works as a URI and can be triggered to run in an address bar, when launched it will launch the app. Now, I can get this script to run in Firefox; it will test for the URI and if not avail it will redirect to the site website of that app. However when I run this in IE it will just load a page that says the site is in valid and not redirect. Anyone have any tips on how to get this working in IE. ALSO in addition this will not run in Safari either; same issue as IE. Thanks in advance I am terrible at this. I want to get this functionality seen here http://davidlynch.org/js/maphilight/docs/demo_usa.html (image map areas highlighting on mouseover) to work on this here http://scratchitrich.com/test/ can anybody walk me through how to make this work? Thanks! I have 3 HTML form inputs fields that is dynamically generated by a "add more" button, with naming for the fields name as fieldName, fieldName1, fieldName2, fieldName3, and so on. Now, I'm trying to retrieve the value from this fields with JavaScript, using the script below. var bookingForm = document.forms['formName']; var qty = bookingForm.fieldName +'i'.value; with the 'i' been a generated numeric number by a for loop when I use alert(qty), it returns NaN, when I'm expecting the value for fieldName1, fieldName2, and so on. But when I use; var qty = bookingForm.fieldName.value I can get the value in that field but get NaN when I try to concatenate 1,2,3, with the fieldName. Any help will be very much appreciated. Hello! I have the following code that I just can't seem to get to work. Here are the issue that aren't working: 1. The items that are stored in the users account aren't showing up as selected when you enter the page. (They work in IE, not Chrome) 2. When you click the items, nothing happens. (It used to work and would add the item to the top image) If you need any more info, or more of the code, let me know. I removed most of the PHP to simplify it for revising, and I didn't include it's CSS. Code: <div id="avatar_form" width="95" height="141"> </div> <div id="avatar_stack"> <p> <img src="hs/news/Upload/images/blankx.png" alt="" /><input name="avatar[Extras]" type="radio" value="blank" <? if($prof[base]==blank) echo("checked='checked'");?> /> </p> <p> <img src="hs/news/Upload/images/skin1.gif" alt="" /><input name="avatar[Skin Tone]" type="radio" value="body1" <? if($prof[skin]==body1) echo('checked="checked"');?> <? if($prof[skin]==blank) echo("checked='checked'");?> /> </p> <p> <img src="hs/news/Upload/images/blankx.png" alt="" /><input name="avatar[Hair]" type="radio" value="blank" <? if($prof[hair]==blank) echo("checked='checked'");?> /> </p> <p> <img src="hs/news/Upload/images/girlface.gif" alt="" /><input name="avatar[Face]" type="radio" value="girlface" <? if($prof[face]==girlface) echo("checked='checked'");?> /> </p> <p> <img src="hs/news/Upload/images/blankx.png" alt="" /><input name="avatar[Hand Item]" type="radio" value="blank" <? if($prof[handitem]==blank) echo("checked='checked'");?> /> </p> <p> <img src="hs/news/Upload/images/shirt6.gif" alt="" /><input name="avatar[Shirt]" type="radio" value="shirt6" <? if($prof[shirt]==shirt6) echo("checked='checked'");?> /> </p> <p> <img src="hs/news/Upload/images/blankx.png" alt="" /><input name="avatar[Hat]" type="radio" value="blank" <? if($prof[hat]==blank) echo("checked='checked'");?> /> </p> <p> <img src="hs/news/Upload/images/pants7.gif" alt="" /><input name="avatar[Pants]" type="radio" value="pants7" <? if($prof[pants]==pants7) echo("checked='checked'");?> /> </p> <p> <img src="hs/news/Upload/images/blankx.png" alt="" /><input name="avatar[Shoes]" type="radio" value="blank" <? if($prof[shoes]==blank) echo("checked='checked' checked");?> /> </p> <p> <img src="hs/news/Upload/images/blankx.png" alt="" /><input name="avatar[Accessories]" type="radio" value="blank" <? if($prof[accessory]==blank) echo("checked='checked' checked");?> /> </p> <p> <img src="hs/news/Upload/images/blankx.png" alt="" /><input name="avatar[Costume]" type="radio" value="blank" <? if($prof[costume]==blank) echo("checked='checked' checked");?> /> </p> </div> <BR><BR><BR> <script type="text/javascript"> var avatar_layers = new Array('Extras', 'Skin Tone', 'Hair', 'Face', 'Hand Item', 'Shirt', 'Hat', 'Pants', 'Shoes', 'Accessories', 'Costume') var layer_colours = new Array('#fff', '#fff', '#fff', '#fff', '#fff', '#fff', '#fff', '#fff', '#fff', '#fff', '#fff') var inactive_tab_background_colour = '#fff' var inactive_tab_bottom_border_colour = '#fff' var stack_height = 1 var on_top = 0 var key = null onload = layout function layout() { if(!document.getElementById('avatar_section')) return document.onkeydown = keyhit tabs() hide_radio_buttons(document.getElementById('avatar_stack')) StackImageHolders('avatar_stack'); P = document.getElementById('avatar_stack').getElementsByTagName('p')[on_top] P.style.backgroundColor = layer_colours[on_top] P.style.zIndex = stack_height++ LIs = document.getElementById('avatar_section').getElementsByTagName('li') for(i=0; i<LIs.length; i++) { LIs[i].style.backgroundColor = inactive_tab_background_colour LIs[i].style.borderBottomColor = inactive_tab_bottom_border_colour } LIs[on_top].style.backgroundColor = layer_colours[on_top] LIs[on_top].style.borderBottomColor = layer_colours[on_top] LIs[on_top].focus() IMGs = document.getElementById('avatar_stack').getElementsByTagName('img') for(i=0; i<IMGs.length; i++) { IMGs[i].className = 'black_border' IMGs[i].style.cursor = 'pointer' IMGs[i].onclick=function(){ChangeGarment(this)} } avatar_preview_and_hotkey_text() update_avatar(document.getElementById('avatar_stack').firstChild) /* I added the following two lines because Internet Explorer wasn't updating the display properly after loading */ document.getElementsByTagName('body')[0].style.width='95'; document.getElementsByTagName('body')[0].style.width='95'; } function keyhit(e) { thisKey = e ? e.which : window.event.keyCode alt_key_down = e ? e.altKey : window.event.altKey ctrl_key_down = e ? e.ctrlKey : window.event.ctrlKey shift_key_down = e ? e.shiftKey : window.event.shiftKey switch (thisKey) { case 37: key = 'LEFT' break case 39: key = 'RIGHT' break default: key = null } if(key && alt_key_down && ctrl_key_down) { IMGs = document.getElementById('avatar_stack').getElementsByTagName('p')[on_top].getElementsByTagName('img') for(i=0; i<IMGs.length; i++) { if(IMGs[i].className == 'red_border') { if((key == 'LEFT') && (i > 0)) { i-- ChangeGarment(IMGs[i]) return } if((key == 'RIGHT') && (i < (IMGs.length - 1))) { i++ ChangeGarment(IMGs[i]) return } } } } else if(key && alt_key_down && shift_key_down) { LIs = document.getElementById('avatar_section').getElementsByTagName('li') if((key == 'LEFT') && (on_top > 0)) { on_top-- bring_to_the_top(LIs[on_top]) return } if((key == 'RIGHT') && (on_top < (LIs.length - 1))) { on_top++ bring_to_the_top(LIs[on_top]) return } } } function tabs() { list = document.createElement('ul') for(i=0; i<avatar_layers.length; i++) { list_item = document.createElement('li') list_item.appendChild(document.createTextNode(avatar_layers[i])) list_item.onmouseover=function(){this.className='mouse'} list_item.onmouseout=function(){this.className=''} list_item.tab_number=i;//faux attributes to "stick" the indexes i and j values list_item.onclick=function(){ bring_to_the_top(this) } list_item.onfocus=function(){ bring_to_the_top(this) } list.appendChild(list_item) } document.getElementById('avatar_section').insertBefore(list, document.getElementById('avatar_stack')) } function hide_radio_buttons(caller) { INPUTs = caller.getElementsByTagName('input') for(i=0; i<INPUTs.length; i++) { if(INPUTs[i].type == 'radio') { INPUTs[i].style.display = 'none'; } } } function StackImageHolders(caller) { Ps = document.getElementById(caller).getElementsByTagName('p') for(i=0; i<Ps.length; i++) { Ps[i].className = 'stack' } } function avatar_preview_and_hotkey_text() { for(i=0; i<avatar_layers.length; i++) { preview = document.createElement('img') preview.id = avatar_layers[i] preview.className = 'preview' preview.width = '95px' preview.height = '141px' preview.alt = 'avatar preview image' document.getElementById('avatar_stack').appendChild(preview) } hotkey_text = document.createElement(' ') hotkey_text.className = 'hotkeys' hotkey_text.appendChild(document.createTextNode('')) document.getElementById('avatar_stack').appendChild(hotkey_text) } function update_avatar(caller) { INPUTs = caller.parentNode.getElementsByTagName('input') for(i=0; i<INPUTs.length; i++) { if(INPUTs[i].type == 'radio') { if(INPUTs[i].checked) { document.getElementById(INPUTs[i].name.match(/^.*[(.*)]$/)[1]).src='hs/news/Upload/images/' + INPUTs[i].value + '.gif' INPUTs[i].previousSibling.className = 'red_border' } else { INPUTs[i].previousSibling.className = 'black_border' } } } } function ChangeGarment(caller) { inputs = caller.parentNode.getElementsByTagName('input') for(i=0;i<inputs.length;i++) { inputs[i].checked=false } caller.nextSibling.checked=true update_avatar(caller) } function bring_to_the_top(caller) { tabs = document.getElementById('avatar_section').getElementsByTagName('li') for(i=0; i<tabs.length; i++) { tabs[i].style.backgroundColor = inactive_tab_background_colour tabs[i].style.borderBottomColor = inactive_tab_bottom_border_colour } on_top = caller.tab_number caller.style.backgroundColor = layer_colours[caller.tab_number] caller.style.borderBottomColor = layer_colours[caller.tab_number] put_on_top = document.getElementById('avatar_stack').getElementsByTagName('p')[caller.tab_number] put_on_top.style.zIndex = stack_height++ put_on_top.style.backgroundColor = layer_colours[caller.tab_number] } </script> I am trying to make the following fill the value box when the page loads as opposed to pressing the button. I cant seem to do it. Any ideas?? PHP Code: <script> var keylist="abcdefghijklmnopqrstuvwxyz123456789" var temp='' function generatepass(plength){ temp='' for (i=0;i<plength;i++) temp+=keylist.charAt(Math.floor(Math.random()*keylist.length)) return temp } function populateform(enterlength){ document.pgenerate.output.value=generatepass(enterlength) } </script> <form name="pgenerate"> <input type="text" size=18 name="output"> <input type="button" value="Generate Password" onClick="populateform(this.form.thelength.value)"><br /> <b>Password Length:</b> <input type="text" name="thelength" size=3 value="7"> </form> How would I go about having this work for Firefox. Is there away to have JQuery work with it? Code: <script type="text/javascript"> region=[//2 dimensional array containing area codes and region pairs ["201","nj"], ["202","dc"], ] function getRegion(code){ index=0; while(true){ console.log(index); if(region[index][0]==code){ return(region[index][1]); } index++; if(index>=region.length){ return(undefined); } } } function getLocation(number){ out=document.getElementById('output'); var answer; if(number.length<3){ return(void(0)); } else{ var code=number.substring(0,3); answer=getRegion(code) if(answer==undefined){ out.innerText="unknown area code"; } else{ out.innerText=answer; } } } </script> ... <form> <input type="text" id="number" onkeyup="getLocation(this.value)"> </form> <div id="output"> </div> Right now, it only works with IE. This goes in the header... Quote: <script language="JavaScript1.2"> function makevisible(cur,which){ strength=(which==0)? 1 : 0.2 if (cur.style.MozOpacity) cur.style.MozOpacity=strength else if (cur.filters) cur.filters.alpha.opacity=strength*100 } </script> and this goes in the image: Quote: <img style="filter:alpha(opacity=20);-moz-opacity:0.2" onMouseover="makevisible(this,0)" onMouseout="makevisible(this,1)" src="SOURCE OF IMAGE"> It works great in IE, but not firefox or chrome. Any way I can alter this to get it to work in all 3 or at least Firefox and IE. Thanks for the help! Hi-- I have a link that has an mp3 sound as its href: Code: <a href="sounds/genealogy.mp3" class="track track-default">this is a link</a> Unfortunately, I also need that same link to go to a part on the site (href=#greenhouse) so that the sound plays on that part of the site. Does anyone know how to accomplish this? I am imagining it would be with javascript, but honestly, I do not know. Any help would be greatly appreciated. Many thanks...! I've got this listbox full of hundreds of employee names. Clicking on a name executes a function using onchange. Because of the length of the list I decided a search function would be really handy and I finally found one that works. Now the search function, when you type in the input box, scrolls the list to the first matching entry. And that's good, that's what I wanted. The problem comes in when you try to click on the name the search function found. Nothing happens ofcourse because the onchange tag in the list reacts to changes, not direct clicks. <select onchange="display.apply(this, this.value.split(','))" multiple="multiple" id="People" name="People" style="border-style: none; height:260px; width:220px; margin-bottom: 15px;"> <option selected="selected">Loading</option> </select> The list is populated by java but for testing I disabled the function that clears the "Loading" option and I set it to selected. That way the loading option is highlighted by default and the search function is free to highlight something else, then when I click on the search result it works like it's supposed to. But keeping a highlighted option at the top of the list for that sole purpose isn't very elegant, especially since if you click on it the onchange function tries to execute and generates errors. The only solution I can think of is to use java to generate another option way at the bottom of the list that has the selected attribute but I don't quite know how to do that. Does anyone have any thoughts on what I can do? Hi guys, first of all im sorry cause i dont know the javascript name and what should this call. i wanted to make a Helps and Guides look like this website http://fnatic.com/ Feedback that located on the left side. If can totally make like them then i hope the script can open a new window with custom size and address bar. I hope someone can help me... i will change my topic tittle if i know what is this call. sorry im a pure newbie in web programming. hopes you all can help me. thanks alot. just started learning scripting. This bookmarklet essentially takes the domain name of the tab currently open when one pressses it & runs a search query through Google prefixing the related: search operator. As evident, here it shows the result in the same page replacing the earlier one. I would like it to open in a new tab. Can you please tell me how to do so. Self-learning it. At an initial stage of learning, I am. Code: javascript:location.href='https://www.google.com/search?q=related%3A'+encodeURIComponent(location.host) Hi everyone, Kind of new to this but I can't get my page to work in IE, works fine in all other browsers though. Any help would be greatly appreciated! the site is sthfilm.com and the code is below: Code: <html> <head> <title>Shortcut to Heaven</title> <link rel="stylesheet" href="style.css"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" charset="utf-8"> </script> <script type="text/javascript"> <!-- Activate cloaking device var randnum = Math.random(); var inum = 4; var rand1 = Math.round(randnum * (inum-1)) + 1; images = new Array images[1] = "img/bg.jpg" images[2] = "img/bg2.jpg" images[3] = "img/bg3.jpg" images[4] = "img/bg4.jpg" var image = images[rand1] // Deactivate cloaking device --> $(function(){ var menu = $('#menu'), pos = menu.offset(); $(window).scroll(function(){ if($(this).scrollTop() > pos.top+menu.height() && menu.hasClass('default')){ menu.fadeOut('fast', function(){ $(this).removeClass('default').addClass('fixed').fadeIn('fast'); }); } else if($(this).scrollTop() <= pos.top && menu.hasClass('fixed')){ menu.fadeOut('fast', function(){ $(this).removeClass('fixed').addClass('default').fadeIn('fast'); }); } }); }); $(function(){ var bar = $('#bar'), pos = bar.offset(); $(window).scroll(function(){ if($(this).scrollTop() > pos.top+bar.height() && bar.hasClass('default2')){ bar.fadeOut('fast', function(){ $(this).removeClass('default2').addClass('fixed2').fadeIn('fast'); }); } else if($(this).scrollTop() <= pos.top && bar.hasClass('fixed2')){ bar.fadeOut('fast', function(){ $(this).removeClass('fixed2').addClass('default2').fadeIn('fast'); }); } }); }); </script> </head> <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <script language="JavaScript"> <!-- Activate cloaking device document.write('<img src="' + image + '" class="bg">') // Deactivate cloaking device --> </script> <div id="navi"> <div id="bar" class="default2" align=center> <div id="menu" class="default" align=center> <!--code of floating bar goes here--> <h1>For additonal information on this project please contact ...</a></h1> </div> </div> </div> </body> </html> function paymentmeth() { for (i = 0; i < document.merch.payway.length; i++){ if (document.merch.payway[i].checked == true){ //a loop that is used to determine the paymethod and checks to see if data has been entered method = document.merch.payway[i].value } } if (method == false) { alert("You forgot to select Pay Method.") } } For some reason it does not work. It should when a player value is = NaN than the players NaN value should be equal to the players value before he was NaN Code: <script type="text/javascript"> function start(){ var t=setTimeout("roll()",500); var t=setTimeout("p11()",1000); var t=setTimeout("roll()",3001); var t=setTimeout("p12()",4002); var t=setTimeout("roll()",5003); var t=setTimeout("p13()",6004); var t=setTimeout("roll()",7005); var t=setTimeout("p14()",8006); var t=setTimeout("roll()",9006); var t=setTimeout("start()",9007); } function roll(){ var a = randoma=Math.floor(Math.random()*7); var b = randomb=Math.floor(Math.random()*7); document.getElementById("r1").value = a; document.getElementById("r2").value = b; } </script> <script type="text/javascript"> function p11(){ if (document.getElementById("r1").value == document.getElementById("r2").value ) { document.getElementById("n1").value == document.getElementById("p1").value ; document.getElementById("p1").value = "NaN"; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; } if (document.getElementById("r1").value < document.getElementById("r2").value ) { document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; } if (document.getElementById("r1").value > document.getElementById("r2").value ) { document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; } } </script> <script type="text/javascript"> function p12(){ if (document.getElementById("r1").value == document.getElementById("r2").value ) { document.getElementById("n2").value == document.getElementById("p2").value ; document.getElementById("p2").value = "NaN"; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; } if (document.getElementById("r1").value < document.getElementById("r2").value ) { document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; } if (document.getElementById("r1").value > document.getElementById("r2").value ) { document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; } } </script> <script type="text/javascript"> function p13(){ if (document.getElementById("r1").value == document.getElementById("r2").value ) { document.getElementById("n3").value == document.getElementById("p3").value ; document.getElementById("p3").value = "NaN"; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; } if (document.getElementById("r1").value < document.getElementById("r2").value ) { document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; } if (document.getElementById("r1").value > document.getElementById("r2").value ) { document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; } } </script> <script type="text/javascript"> function p14(){ if (document.getElementById("r1").value == document.getElementById("r2").value ) { document.getElementById("n4").value == document.getElementById("p4").value ; document.getElementById("p4").value = "NaN"; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; } if (document.getElementById("r1").value < document.getElementById("r2").value ) { document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; } if (document.getElementById("r1").value > document.getElementById("r2").value ) { document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; } } </script> Code: Player 1 $<input type="text" value="0" id="p1" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> Player 2 $<input type="text" value="0" id="p2" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> Player 3 $<input type="text" value="0" id="p3" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> Player 4 $<input type="text" value="0" id="p4" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> <input type="button" value="Roll" onclick="start()"/> <br/> <input type="hidden" value="0" id="r1" size="1" /> <input type="hidden" value="0" id="r2" size="1" /> Player 1 NaN $<input type="text" value="0" id="n1" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> Player 2 NaN $<input type="text" value="0" id="n2" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> Player 3 NaN $<input type="text" value="0" id="n3" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> Player 4 NaN $<input type="text" value="0" id="n4" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> Hi, i got good help with this last time but i still wonder if its possible to make this work in ie explorer. The script is a expandable menu where the submenus still shall be shown if javascript is disabled for some reason, it works in firefox but i in ie it shows all links as submenus on load . i wonder if it would be possible to show the menus unexpanded on load in i explorer to . note that the submenus should only be visible on load if javascript is disabled. Im posting the code below i would aprreciate some help <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> .menu1{ margin-left:25px; padding-left:20px; padding-top:2px; padding-bottom: 2px; display:block; text-decoration: none; color: #000000; height: 20px; width: 200px; background-color: #03C; border: thin solid #FFF; } .submenu{ background-image: url(images/submenu.gif); display: block; height: 19px; margin-left: 38px; padding-top: 2px; padding-left: 7px; color: #333333; } .hide{ display: none; } .show{ display: block; } </style> </head> <body> <a class="menu1" onclick="showHide('mymenu1')">Menu 1</a> <div id="mymenu1" class="show"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <a class="menu1" onclick="showHide('mymenu2')">Menu 2 </a> <div id="mymenu2" class="show"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <a class="menu1" onclick="showHide('mymenu3')">Menu 3 </a> <div id="mymenu3" class="show"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <a class="menu1" onclick="showHide('mymenu4')">Menu 4 </a> <div id="mymenu4" class="show"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <a class="menu1" onclick="showHide('mymenu5')">Menu 5 </a> <div id="mymenu5" class="show"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <script type="text/javascript"> menu_status = new Array(); function showHide(theid){ var switch_id = document.getElementById(theid); if(menu_status[theid] != 'show') { switch_id.className = 'show'; menu_status[theid] = 'show'; } else { switch_id.className = 'hide'; menu_status[theid] = 'hide'; } } var divs=document.getElementsByTagName('div'); var menudivs=[]; for(i=0;i<divs.length;i++) { if(divs[i].id.indexOf('mymenu')!=-1) menudivs.push(divs[i]); } function hideDivs() { for(i=0;i<menudivs.length;i++) { menudivs[i].className='hide'; menu_status[menudivs[i]]='hide'; } } window.addEventListener('load',hideDivs,false); //window.attachEvent('onload',hideDivs) - add this within an "if IE" statement </script> </body> </html> Hi, i have this code that works, but takes like 3 seconds to load when using it on the website. Is there a better way to code this to make it faster? Code: function onTaskChange(num) { if( num = 1) { var stask = document.forms[0].task11.value; setSelectValue("forms[0].task21", stask); setSelectValue("forms[0].task31", stask); setSelectValue("forms[0].task41", stask); setSelectValue("forms[0].task51", stask); for( i = 0; i < 7; i++) tblProjectHours[i][6]=stask; onTaskChange(4); onTaskChange(7); onTaskChange(10); onTaskChange(13); } else if( num = 2) { var stask = document.forms[0].task12.value; setSelectValue("forms[0].task22", stask); setSelectValue("forms[0].task32", stask); setSelectValue("forms[0].task42", stask); setSelectValue("forms[0].task52", stask); for( i = 7; i < 14; i++) tblProjectHours[i][6]=stask; onTaskChange(5); onTaskChange(8); onTaskChange(11); onTaskChange(14); } else if( num = 3) { var stask = document.forms[0].task13.value; setSelectValue("forms[0].task23", stask); setSelectValue("forms[0].task33", stask); setSelectValue("forms[0].task43", stask); setSelectValue("forms[0].task53", stask); for( i = 14; i < 21; i++) tblProjectHours[i][6]=stask; onTaskChange(6); onTaskChange(9); onTaskChange(12); onTaskChange(15); } else if( num = 4) { var stask = document.forms[0].task21.value; for( i = 21; i < 28; i++) tblProjectHours[i][6]=stask; } else if( num = 5) { var stask = document.forms[0].task22.value; for( i = 28; i < 35; i++) tblProjectHours[i][6]=stask; } else if( num = 6) { var stask = document.forms[0].task23.value; for( i = 35; i < 42; i++) tblProjectHours[i][6]=stask; } else if( num = 7) { var stask = document.forms[0].task31.value; for( i = 42; i < 49; i++) tblProjectHours[i][6]=stask; } else if( num = 8) { var stask = document.forms[0].task32.value; for( i = 49; i < 56; i++) tblProjectHours[i][6]=stask; } else if( num = 9) { var stask = document.forms[0].task33.value; for( i = 56; i < 63; i++) tblProjectHours[i][6]=stask; } else if( num = 10) { var stask = document.forms[0].task41.value; for( i = 63; i < 70; i++) tblProjectHours[i][6]=stask; } else if( num = 11) { var stask = document.forms[0].task42.value; for( i = 70; i < 77; i++) tblProjectHours[i][6]=stask; } else if( num = 12) { var stask = document.forms[0].task43.value; for( i = 77; i < 84; i++) tblProjectHours[i][6]=stask; } else if( num = 13) { var stask = document.forms[0].task51.value; for( i = 84; i < 91; i++) tblProjectHours[i][6]=stask; } else if( num = 14) { var stask = document.forms[0].task52.value; for( i = 91; i < 98; i++) tblProjectHours[i][6]=stask; } else if( num = 15) { var stask = document.forms[0].task53.value; for( i = 98; i < 105; i++) tblProjectHours[i][6]=stask; } } OK I am stumped. I am creating a little html to check my js file. I want to have the user enter two parameters and then call the function using those two paramaters and then display the answer on the screen. Here is the html file <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>HomeWork3</title> <script type="text/JavaScript" src="grosspay.js"> </script> </head> <body> <script type="text/javascript"> <![CDATA[ var hoursWorked = parseInt(prompt("Enter the Number of Hours You Worked", "40")); var hourlyRate = parseInt(prompt("Enter the Number of Hours You Worked", "10")); function grossPay(hoursWorked, hourlyRate){ document.writeln(grossPay + " Is your normal amount of your check before taxes are taken out"); } ]]> </script> </body> </html> Here is the JS file function grossPay (hoursWorked, hourlyRate) { if (hoursWorked > 40){ var overTimeHrs = (hoursWorked - 40) var overTimePay = (overTimeHrs * 1.5 * hourlyRate) var regPay = (40 * hourlyRate) var grossPay = regPay + overTimePay return grossPay }else { var grossPay = (40 * hourlyRate) return grossPay} } CAN SOMEONE PLEASE HELP Hi, I have a javascript I created to compare the textbox value to the array and write something on the textbox but somehow it is giving me a syntax error. I am not good in javascript so I am really not sure which one is giving me problem. Can someone please help? Thanks. My logic is to check if my 18 textbox is not empty and if not then get the label of each textbox and compare to my array listed below. If the value of each label in the textbox exist, then write and equal word in the hidden textbox and if it doesn't exist, increment to the value of 1 to the textbox. Here is my javascript code: Code: function CalculateTotal(){ var homelessness = new Array (); homelessness[0] = "70250", homelessness[1] = "70260", homelessness[2] = "70750", ); var financial = new Array (); financial[0] = "96580", financial[1] = "96500", financial[2] = "96580", ); var emergency = new Array (); emergency[0] = "79660", emergency[1] = "80105", emergency[2] = "96020", ); for (i=3; i<18; i++) for (var k=3; k<18; k++) { if((amounts[i] != "") && (amounts[i] == desig[k])) { var issueId = impact.charAt(k); var impact_txt = document.getElementById(issueId).value; for ( var x = 0; x < homelessness.length; x++ ) { var myArray[ homelessness[ x ] ] = homelessness[ x ]; if ( myArray[impact_txt] == homelessness[] ) && (document.getElementById('impact1').value == "")) { document.getElementById('impact1').value = "Homelessness"; } } for ( var x = 0; x < financial.length; x++ ) { var myArray[ financial[ x ] ] = financial[ x ]; if ( myArray[impact_txt] == financial[] ) && (document.getElementById('impact2').value == "")) { document.getElementById('impact2').value = "Financial Stability and Independence"; } } for ( var x = 0; x < emergency.length; x++ ) { var myArray[ emergency[ x ] ] = emergency[ x ]; if ( myArray[impact_txt] == emergency[] ) && (document.getElementById('impact2').value == "")) { document.getElementById('impact3').value = "Emergency Crisis and Services"; } } } } } } //body code <table> <tr> <td style="width:380px;text-align:left"><label for="d" id="D" name="D" title="80104">Crime and Drug Use <a href="javascript:alert('');">what is this?</a></label></td> <td style="float:right"> $<input id="d" name="d" class="text" type="text" value="<?php safeEcho($form['d'])?>" style="width:90px;" onChange="CalculateTotal();" /> <?php helper_error('d');?> </td><td> <input name="impact1" id="impact1" type="text" value="" onclick="CalculateTotal();" /> </td> </tr> <tr> <td style="width:380px;text-align:left"><label for="e" id="E" name="E" title="80101">Early Childhood Development <a href="javascript:alert('');">what is this?</a></label></td> <td style="float:right"> $<input id="e" name="e" class="text" type="text" value="<?php safeEcho($form['e'])?>" style="width:90px;" onChange="CalculateTotal()" /> <?php helper_error('e');?> </td><td> <input name="impact2" id="impact2" type="text" value="" onclick="CalculateTotal();" /> </td> </tr> <tr> <td style="width:380px;text-align:left"><label for="f" id="F" name="F" title="80105">Emergency and Crisis Services <a href="javascript:alert('');">what is this?</a></label></td> <td style="float:right"> $<input id="f" name="f" class="text" type="text" value="<?php safeEcho($form['f'])?>" style="width:90px;" onChange="CalculateTotal()" /> <?php helper_error('f');?> </td><td> <input name="impact3" id="impact3" type="text" value="" onclick="CalculateTotal();" /> </td> </tr> Hope you can help me to make my javascript work. Thanks. |