JavaScript - Please I Have Problem With This Code..help Me.
Hi,
Please i have this code which is not working correctly,please can somebody help write it incorrect order for me. When i write it on a separate notepad then it works but when i write or combine them on a single notepad like what is here it do not work. Help me please,here is the code <html> <body> <script type="text/javascript"> function calculate(){ A=Number(document.frmone.txtfirstnumber.value) B=Number(document.frmone.txtsecondnumber.value) A=Number(A) B=Number(B) C=A+B document.frmone.txtthirdnumber.value=C if(Number(A) && Number(B)){ A=Number(A) B=Number(B) C=A+B document.frmone.txtthirdnumber.value=C } else{ alert("Enter a number in both boxes") } } // here is another subtraction code to calculate function calculate(){ A=Number(document.frmone2.txtfirstnumber.value) B=Number(document.frmone2.txtsecondnumber.value) A=Number(A) B=Number(B) C=A-B document.frmone2.txtthirdnumber.value=C if(Number(A) && Number(B)){ A=Number(A) B=Number(B) C=A-B document.frmone2.txtthirdnumber.value=C } else{ alert("Enter a number in both boxes") } } // here is a palindrom code function palinChecker() { var string = document.palindrome.input.value; document.palindrome.palindrometext.value = reverseString(string); if (isPalindrome(string)) { alert("That IS a palindrome."); } else { alert("That is NOT a palindrome."); } } <p>Here is palindrome checker code</p> function isPalindrome (inputString) { var reversedString = reverseString(inputString); return (reversedString==reverseString(reversedString)); } function reverseString(stringToReverse) { stringToReverse = stringToReverse.toUpperCase(); var reversedString=""; var length= stringToReverse.length-1; var ch; for (var i=length; i>=0; i--) { ch = stringToReverse.charAt(i) if(ch >='A' && ch <='Z') { reversedString += ch; } } return reversedString; } </script> </head> <body> <form name=frmone> Value one: <input type=text name=txtfirstnumber size=5 value=""/> value two: <input type=text name=txtsecondnumber size=5 value=""/> Total:<input type=text name=txtthirdnumber size=5 value=""/> <input type="button" value="Add Numbers" onclick="calculate()"/> <p>this is a subtraction text field,just enter a number and get a result</p> <form name=frmone2> Value one: <input type=text name=txtfirstnumber size=5 value=""/> value two: <input type=text name=txtsecondnumber size=5 value=""/> Total:<input type=text name=txtthirdnumber size=5 value=""/> <input type="button" value="Subtract Numbers" onclick="calculate()"/> <p>Here is palindrome form filed</p> <form name="palindrome"> <p>Enter phrase: <input type="text" name="input"><br> <input type="button" name="check" value="Check if palindrome" onclick="palinChecker();"><br> <input type="text" name="palindrometext" value=""></p> </form> </body> </html> Thank you. Clement Osei. Similar Tutorialshi guys " I made very simple code to find the average of array : PHP Code: <script> var sum = 0; var gradesArray = [95,80,75]; for (var i = 0; i <= 3; i = i+1) { sum = sum + gradesArray[i]; } document.write('Your average is ' + sum / 3); </script> the output is : Your average is NaN how I can fixt it. document.thisform1.q_no.value=<%=out.print(Questions.getMaxQuesNo(%>document.write(paper_id);<%)%>
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <style type="text/css"> .showHideDivs { display: none } </style> <script type="text/javascript"> function showHideDivs(){ var job = ''; for(i=0; i < oRadBtns.length; i++){ if(oRadBtns[i].checked){ job = oRadBtns[i].value; } } switch (job){ case 'yes': document.getElementById("nombre").style.display = "none"; document.getElementById("apellido").style.display = "none"; document.getElementById("empresa").style.display = "block"; document.getElementById("contacto").style.display = "block"; break; case 'no': document.getElementById("nombre").style.display = "block"; document.getElementById("apellido").style.display = "block"; document.getElementById("empresa").style.display = "none"; document.getElementById("contacto").style.display = "none"; } } window.onload=function(){ oRadBtns = document.getElementById('radBtnCont').getElementsByTagName('input'); for(i=0; i < oRadBtns.length; i++){ oRadBtns[i].onclick = showHideDivs; } showHideDivs(); } </script> </head> <body> <div id="radBtnCont"> <input type="radio" value="yes" name="job" checked="checked" />Yes <br /> <input type="radio" value="no" name="job" />No </div> <div id="nombre" class="showHideDivs">This is nombre div</div> <div id="apellido" class="showHideDivs">This is apellido div</div> <div id="empresa" class="showHideDivs">This is empresa div</div> <div id="contacto" class="showHideDivs">This is contacto div</div> </body> </html> Hello! There is something wrong in the code below. What is it? Can you help me please? The form validation was working just fine when I added the last 'if' for zip code validation. The function didn't work and returned true. The code is: Code: <script type="text/javascript"> function validateForm() { var y=document.forms["form"]["firstname"].value; var f=document.forms["form"]["zipcode"].value; var x=document.forms["form"]["email"].value; var atpos=x.indexOf("@"); var dotpos=x.lastIndexOf("."); if (y==null || y=="NAME") { alert("First name must be filled out"); return false; } if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { alert("Not a valid e-mail address"); return false; } } var re='/(^\d{5}$)/'; if (f!=re) { alert ("Not a valid address"); return false; } } </script> Any ideas or advice? Thank you in advance! Hi there, I am new to javascript and have been working on this code to randomly shuffle a playlist of Youtube videos which are in an array. I have tried to implement a next and previous function, which I have managed to some success however, there is a problem. I have a system where there are two arrays: one is for the 'upcoming' videos and the other is for 'previous' videos. When the next button is pressed, the last element of the 'upcoming' array is added to the 'previous' array and I use the pop() function to return and delete that element from the 'upcoming' array and so on. When the previous button is pressed it puts the last element into the 'upcoming' array and uses the pop function as well, and so on. It works well except one thing, when previous is pressed the current video will load again, then on the second press it will go to the true previous video. The same happens when you click next after clicking previous. This is my code: PHP Code: <html> <span id = "displayarea"></span> <script type = "text/javascript"> var Varray = []; Varray[0] ='<object width="420" height="315"><param name="movie" value="http://www.youtube.com/v/007VM8NZxkI?version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/007VM8NZxkI?version=3&hl=en_US" type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>'; Varray[1] ='<iframe width="420" height="315" src="http://www.youtube.com/embed/DfDBZUb3mvI" frameborder="0" allowfullscreen></iframe>'; Varray[2] ='<object width="420" height="315"><param name="movie" value="http://www.youtube.com/v/T9TmmF79Rw0?version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/T9TmmF79Rw0?version=3&hl=en_US" type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>'; Varray[3] ='<object width="420" height="315"><param name="movie" value="http://www.youtube.com/v/I1edDfzluXE?version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/I1edDfzluXE?version=3&hl=en_US" type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>' Varray[4] ='<object width="420" height="315"><param name="movie" value="http://www.youtube.com/v/qXLxM0u1aJw?version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/qXLxM0u1aJw?version=3&hl=en_US" type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>' Varray[5] ='<object width="420" height="315"><param name="movie" value="http://www.youtube.com/v/UyOaTo_MiFE?version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/UyOaTo_MiFE?version=3&hl=en_US" type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>' var Vprevious = []; Varray.sort(function(){return Math.round(Math.random());}); function showit() { Vprevious.push((Varray[Varray.length-1])); document.getElementById("displayarea").innerHTML=Varray.pop(); } function previousit() { Varray.push((Vprevious[Vprevious.length-1])); document.getElementById("displayarea").innerHTML=Vprevious.pop(); } Vprevious.push((Varray[Varray.length-1])); document.getElementById("displayarea").innerHTML=Varray.pop(); </script> <input type = "button" id = "NextB" value = "Next" onclick = "showit();"> <input type = "button" id = "previousB" value = "previous" onclick = "previousit();"> </html> and the link to the test site is http://www.musicrate.org/rotate I have tried playing around with things and trying to use splice() to select the video one before the last, however I have not succeeded. Any help on the matter would be appreciated. It is probably something simple and obvious so I apologize in advance if that is the case. Thanks Hello to everyone, . Im a new user and i have a question. Here is a code from a WebPage, in the page there is a button that called "Check Flaps" when i click it is need to run a javascript code and show me the results on the same window, but it not worked. The javascript code: Code: javascript:document.getElementsByTagName('html')[0].innerHTML.replace(/<!--|-->/g,'') Is Working only when i open a new window and copy & paste the code and hit enter. I want it to show me the results on the same window. Here is the method: Code: </ul> <div id="brakeline"></div> <div id="fs"> <form action="https://isp-012:qwerty123!!@cows-isp.hot.net.il/cgi-bin/cm_result.html?MAC=" name="frm2" method="get" id="cows" target="bottom"> <h5>#MAC</h5> <input class="textinput" type="text" name="MAC" id="MAC"> <div id="brakeline5"></div> <input class="submitc2" id="sumb" type="submit" value="Check"> </form> <form action="javascript:document.getElementsByTagName('html')[0].innerHTML.replace(/<!--|-->/g,'')" target="bottom"> <input class="submitc" id="ChkFlap" type="submit" value="Check Flaps"> </form> </div> Thanks. Hello everyone, I am just beginning to learn javascript, and I am trying to create a little game where when a user hovers over a picture it changes, and things like that. At the moment I have been trying to make it so that the pictures tile so they fill the whole page area, dynamically so that it changes depending on the users browser size (px). The images have many attributes so I can't just tile them with css as they need to be actual elements. The problem is the code doesn't run, and I can't work out why. I think all the lines that require it have semi colons and its all correct. Forgive me if the answer is clear but as I said I only just started learning. Anyway, on with the code: Code: <!doctype html> <html lang="en"> <head> <title>Hi, I'm a button.</title> <link rel="stylesheet" type="text/css" href="style.css"> <script type="javascript"> function mainDo() { if (document.body && document.body.offsetWidth) { winW = document.body.offsetWidth; winH = document.body.offsetHeight; } if (document.compatMode=='CSS1Compat' && document.documentElement && document.documentElement.offsetWidth ) { winW = document.documentElement.offsetWidth; winH = document.documentElement.offsetHeight; } if (window.innerWidth && window.innerHeight) { winW = window.innerWidth; winH = window.innerHeight; } document.write('Width = ' + winW + 'Height = ' + winH); winW=winW/127; winH=winH/128; winW=Math.round(winW); winWs=winW; winH=Math.round(winH); winHs=winH; document.write('Width = ' + winW + 'Height = ' + winH); while (winH>0) { while (winW>0) { document.write('<img onMouseover="this.src=\'img/hibutton_orange.png\'" onClick="this.src=\'img/hibutton_green.png\'" ondblClick="this.src=\'img/hibutton_blue.png\'" src="img/hibutton_blue.png">'); winW=winW-1; } document.write('\n' + '<br>'); winW=winWs; winH=winH-1; } } </script> </head> <body onload="maindo()"> </body> </html> How to add 2 JavaScript code in 1 page so that, so that 1 jsp code could not affect another code?
Hi, I have downloaded the datepicker code from the site http://www.javascriptkit.com/script/...calendar.shtml It's working fine with Firefox but when run the application on Safari/Chrome and when I load the calendar and try to expand the expansion is uneven... only the center column i.e Wednesday is getting expanded and others are remaining constant.. but in Firefox it's working fine... Can somebody help me in fixing it.. Thanks, Ram Problem with the Date when one date variable rolls back to a previous month. Everything is explained he http://kcmaindomain.com/fix-js.html View Page Source of that page to see the java script code. I would greatly appreciate the help as I am fairly amateur coder and I have no idea how to correct this myself. Hi, I'm having a problem getting one of my image rollovers to work, what confuses me is that the other image works fine, I'm trying to get this to work for an assignment here's the javascript: Code: rollImage = new Array() for(i = 0; i < 12; i++){ rollImage[i] = new Image(85,85); } rollImage[0].src = "images/narav2.jpg"; rollImage[1].src = "images/narav3.jpg"; rollImage[2].src = "images/sasuke-avatar-118.jpg"; rollImage[3].src = "images/sasuke.jpg"; function swapNar(img){ //this works fine document.nar11.src = rollImage[img].src; return true; } function returnNar(img){ //this function works fine as well document.nar11.src = rollImage[img].src; return true; } function swapSas(img){ //this function not working document.sasim.src = rollImage(img).src; return true; } function returnSas(img){ //this function also not working document.sasim.src = rollImage(img).src; return true; } Here's the HTML: Code: <tr> <td height="60"> <img src="images/narav2.jpg" name="nar11" width="85" height="85" border="0" id="nar11"/> </td> <td> <a href="naruto.html" onMouseover = "swapNar(1)" onMouseout = "returnNar(0)"> Naruto </a> </td> </tr> <!-- When I mouse over the above link the image rolls over as expected, the bottom link doesn't work as expected and I can't see what I'm doing wrong --> <tr> <td height="60"> <img src="images/sasuke-avatar-118.jpg" name="sasim" width="85" height="85" border="0" id="sasim"/> </td> <td> <a href="sasuke.html" onMouseout= "swapSas(3)" onMouseover= "returnSas(2)"> Sasuke </a> </td> </tr> I can't see what the problem is with the returnSas and swapSas functions, I'm still a noob at this and would really appreciate some assistance, thanks in advance Hi, I have a code which i'm trying to make work. I need it so when I select the button it copies the code to the clipboard, then go directly to the site (eg: google.com), then I need the code to be pasted in to the browser bar and hit enter. I've been working on this for hours. I know i'm doing something wrong if someone could give me a simple code with these features then I could add in the stuff. This is the javascript that copies the code: Code: <script language="JavaScript"> var clip = null; function init() { clip = new ZeroClipboard.Client(); clip.setHandCursor( true ); clip.setText("*********CODE TO COPY IS HERE**********"); clip.glue('d_clip_button'); clip.addEventListener('complete', my_complete); setInterval(checkDone, 1000); } This is what I have to send them to the site. Code: <input type="button" value="Click Here" onClick="javascript:window.open('http://google.com');" > I don't know how to have it all in one so it copies the code then opens the site and pastes into the browser and enters. Regards, Andrew Hello, I get Result of expression 'document.ConverTable' [undefined] is not an object. with the code below, and would like some help finding out what the problem is. Thanks! Code: ... <head> <script type="text/javascript"> function calc(val,factor,putin) { if (val == "") { val = "0" } evalstr = "document.ConverTable."+putin+ ".value = " evalstr = evalstr + val + "*" + factor eval(evalstr) } </script> </head> <body> ... Kg: <input size="10" onkeyup="calc(this.value,2.2046,'clbs')"> Pounds: <input name="clbs" size="10"> ... </body> Hello All, So, I have a website with a floating cart and it loads fine and works almost flawlessly lol. However, when a person has a bunch of items in their cart, and they want to minimize it for the rest of their browsing experience, every time a new page loads, or a refresh happens, the floating cart un-minimizes and expands out fully again displaying all the items. This can become very annoying during the shopping experience when you have a bunch of items loading and just taking up space in the browser. Therefore, I am wondering if their is some html or script that would save the minimizing in the floating cart, and carry it over to the next page, and the rest of the browsing on site? Thank you for any suggestions/help. I am new to HTML and script writing, but I am eager to learn. Hopefully in the future, I won't be paying for little changes like this every time I need one. Solved
Hello everybody I need your help in this problem At first, this is the code used HTML Code PHP Code: <input type="text" onfocus="fadeIn(this)" /><div class="box" style="opacity: 0.0"></div><br /> <input type="text" onfocus="fadeIn(this)" /><div class="box" style="opacity: 0.0"></div> JavaScript Code PHP Code: function fadeIn(elem){ element = elem.nextSibling; elemOpacity = element.style.opacity; element.innerHTML = elemOpacity; if (elemOpacity < 1.0) element.style.opacity = parseFloat(elemOpacity) + 0.1; timeIn = setTimeout(fadeIn, 100); } I have used the opacity property to make fading element like fadeIn() function in jquery , and i have used onfocus event to execute the code . Problem exists in setTimeout function, this function Does not work But the code works without this function What is the cause of the problem , Please help me I have this script added to a facebook icon (#id) on my front page: (function() { var e = document.createElement('script'); e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; e.async = true; document.getElementById('fb-root').appendChild(e); })(); window.fbAsyncInit = function() { var fbClicked = false; FB.init({appId: 'Myappid', status: true, cookie: true, xfbml: true}); FB.Event.subscribe('auth.login', function(response) { if(response.session && fbClicked){ window.location = 'http://www.mysite.com/facebookauth/?ref=/'; } }); } function thFBShortCut() { FB.login(function(response) { fbClicked = true; if (response.session && response.perms && fbClicked) { window.location = 'http://www.mysite.com/facebookauth/?ref=/'; } }, {perms:'email,publish_stream'}); } function thFBLogin() { fbClicked = true; $('.popbox').fadeOut(); FB.getLoginStatus(function(response) { if(response.session && response.status == 'connected' && fbClicked) { window.location = 'http://www.mysite.com/facebookauth/?ref=/'; } }); } I want when whenever user press on facebook icon, the script should trigger facebook connect app. I added `<div id="fb-root"></div>` right after `<body <?php body_class(); ?>>`, but when I load my site I keep getting these error messages: document.getElementById("fb-root") is null and FB is not defined [Break On This Error] FB.login(function(response) { My html: <a id="facebookicon" onclick="thFBShortCut()">Login</a> I'm teaching myself how to build websites; up until now I have made websites using tables within tables and it's all fairly straight forward, now I realise that divs and css allow you to do soooo much more! I have put these files in a temp folder on my website so not to over write the current site. Basically I have followed this online tutorial (http://www.cryer.co.uk/resources/jav...show_links.htm) but when I test the slideshow, it doesn't work. the link is: www.telecaretechnology.com/telecare2/index.html Since I have started writing this, my css file seems to have had a wobbly - I assume my problem is where I'm trying to use server-side include?? Is that the best way to add these files? the javascript I have used to make the slideshow run is he http://www.telecaretechnology.com/te...2/slideshow.js I would really appreciate any advice! Kind Regards, Jamie Code: <html> <body> <script type="text/javascript"> var Items = new Array Items [0] = ["a", "b"]; Items [1] = ["c", "d"]; var i = 0; if(Items [i++][0] == "c"){ document.write("hello"); } </script> </script> <body> </body> </html> so im trying to search an array with this function its not working i tried using firebug but it showed no errors. I think its the i++ part i want to increment i each time it tries it. WAIT SORRY I SOLVED IT I solved it you can put in Pistol or shotgun for name Code: <html> <body> <script type="text/javascript"> var Items = new Array Items [0] = ["Pistol", "50", "2000"]; Items [1] = ["shotgun", "5000","1000"]; var i = 0; function chek(){ if(Items [i][0] == document.getElementById("name").value){ document.getElementById("a").value = Items [i] [1]; document.getElementById("acc").value = Items [i] [2]; i=0; } else { i++ } } </script> </script> <body> Dammage<input type="text" id="a" /> <br/> ACC<input type="text" id="acc" /> <br/> Name<input type="text" id="name" /> <br/> <input type="button" onclick="chek();" value="Chek" /> </body> </html> Is there anyway to make it more streamline so you dont have to click to increment? |