JavaScript - The Delete Buttons In This Code Do Not Work
Hello,
I have a script that lets you add tasks to a task list and then you can click a button to sort them, but I cannot get the "Delete Selected Task" and "Delete All Tasks" buttons to work correctly. I will be eternally indebted to whoever can help me fix these two buttons. The code I am working on is posted below. Thank you for your time. [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" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>To Do List</title> <script type="text/javascript"> /* <![CDATA[ */ function addTask() { if (document.forms[0].newtask.value == "") window.alert("You must enter a value in the New Task field."); else { if (document.forms[0].tasks.options.value == "tasks") document.forms[0].tasks.options[0] = null; var newTask = new Option(); newTask.value = document.forms[0].newtask.value; newTask.text = document.forms[0].newtask.value; var numTasks = document.forms[0].tasks.options.length; document.forms[0].tasks.options[numTasks] = newTask; document.forms[0].newtask.value = ""; } } function deleteTask() { var selectedTask = 0; var taskSelected = false; while (selectedTask < document.forms[0].tasks.length) { if (document.forms[0].tasks.options[selectedTask].selected == true) { taskSelected = true; break; } ++selectedTask; } if (taskSelected == true) document.forms[0].tasks.options[selectedTasks] = null; else window.alert("You must select a task in the list."); } function ascendingSort() { var newTasks = new Array(); for (var i =0; i < document.forms[0].tasks.length; ++i) { newTasks[i] = document.forms[0].tasks.options[i].value; } newTasks.sort(); for (var j =0; j < document.forms[0].tasks.length; ++j) { document.forms[0].tasks.options[j].value = newTasks[j]; document.forms[0].tasks.options[j].text = newTasks[j]; } } /* ]]> */ </script> </head> <body> <h1>To Do List</h1> <form action=""> <p>New Task <input type="text" size="68" name="newtask" /></p> <p><input type="button" value="Add Task" onclick="addTask()" style="width: 150px" /> <input type="button" value="Delete Selected Task" onclick="deleteTask()" style="width: 150px" /> <input type="button" value="Delete All Tasks" onclick="document.forms[0].task.options.length = 0;" style="width: 150px" /><br /> <input type="button" value="Ascending Sort" onclick="ascendingSort()" style="width: 150px" /> </p> <p><select name="tasks" size="10" style="width: 500px"> <option value="tasks">Tasks</option></select></p> </form> </body> </html> [CODE] Similar TutorialsI have buttons that check all the check boxes and uncheck all the checkboxes. They seem to not be working. Here is the code. Javascript Code: <script type="text/javascript"> function checkall(delchk) { for (i = 0; i < delchk.length; i++) delchk[i].checked = true; } </script> <script type="text/javascript"> function uncheckall(delchk) { for (i = 0; i < delchk.length; i++) delchk[i].checked = false; } </script> PHP PHP Code: <?php error_reporting(E_ALL); require("inc/config.php"); if (isset($_POST['del'])) { for ($count = 0;$count<count($_POST[delchk]);$count++) { $delete = $_POST[delchk][$count]; $query = "DELETE FROM persons WHERE id = '$delete'"; $result = mysql_query($query); if (!$result) { die("Error deleting persons! Query: $query<br />Error: ".mysql_error()); } } } $result = mysql_query("SELECT * FROM persons"); // Check how many rows it found if(mysql_num_rows($result) > 0){ echo "<table id=\"mytable\"> <thead> <tr> <th align=\"center\" scope=\"col\">Delete?</th> <th align=\"center\" scope=\"col\">First Name</th> <th align=\"center\" scope=\"col\">Last Name</th> <th align=\"center\" scope=\"col\">Profile</th> <th align=\"center\" scope=\"col\">Date</th> <th align=\"center\" scope=\"col\">IP Address</th> </tr> </thead> <tbody>"; echo "<form name = 'myform' action='' method='post'>"; while($row = mysql_fetch_array($result)) { echo "<tr align=\"center\">"; echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$row['id'].'" /></td>'; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td><a target=frame2 href='" ."profile.php?user1=". $row['FirstName'] ."'>Check Profile</a></td>"; echo "<td>" . $row['AddedDate'] . "</td>"; echo "<td>" . $row['Ip'] . "</td>"; echo "</tr>"; } echo "</tbody>"; echo "</table>"; echo "<hr>"; echo "<input type='submit' name = 'del' value='Delete Selected'></form>"; echo "<input type='button' onclick='checkall(document.myform[\"delchk[]\"]);' value='Select All'>"; echo "<input type='button' onclick='uncheckall(document.myform[\"delchk[]\"]);' value='UnSelect All'>"; } else{ // No rows were found ... echo 'No registered members.'; } mysql_close(); ?> I got this code to WORK with Buttons... But, i can NOT get it to work with URLs/LINKs... dose anyone have any suggestions? The URL alternative LINKs are placed below the buttons... but like i have said, they don't work. Help Pleeeeese. Thanks. ****HEAD <script language="javascript" type="text/javascript"> function getCheckedValue() { document.getElementById("presentationsNavBars").style.display = 'block'; document.getElementById("proposalsNavBars").style.display = 'none'; document.getElementById("postingsNavBars").style.display = 'none'; document.getElementById("myaccountNavBars").style.display = 'none'; } function getCheckedValue2() { document.getElementById("presentationsNavBars").style.display = 'none'; document.getElementById("proposalsNavBars").style.display = 'block'; document.getElementById("postingsNavBars").style.display = 'none'; document.getElementById("myaccountNavBars").style.display = 'none'; } function getCheckedValue3() { document.getElementById("presentationsNavBars").style.display = 'none'; document.getElementById("proposalsNavBars").style.display = 'none'; document.getElementById("postingsNavBars").style.display = 'block'; document.getElementById("myaccountNavBars").style.display = 'none'; } function getCheckedValue4() { document.getElementById("presentationsNavBars").style.display = 'none'; document.getElementById("proposalsNavBars").style.display = 'none'; document.getElementById("postingsNavBars").style.display = 'none'; document.getElementById("myaccountNavBars").style.display = 'block'; } </script> ****** BODY <div class="student_text"> <asp:RadioButton ID="RadioButton1" GroupName="reg" Text="presentations" runat="server" OnClick="return getCheckedValue();" /> <br /> <%--OR how do i get it to work when using a URL as shown below for example--%> <a href="navPageTest2.aspx" runat="server" onclick="getClickedValue();">Presentations_link_ex</a><br /> </div> <br /><br /> <div class="student_text"> <asp:RadioButton ID="RadioButton2" GroupName="reg" Text="proposals" runat="server" onclick="return getCheckedValue2();" /> <br /> <%--OR how do i get it to work when using a URL as shown below for example--%> <a href="navPageTest2.aspx" onclick="getClickedValue2();">Proposals_link_ex</a><br /> </div> <br /><br /> <div class="student_text"> <asp:RadioButton ID="RadioButton3" GroupName="reg" Text="postings" runat="server" onclick="return getCheckedValue3();" /> <br /> <%--OR how do i get it to work when using a URL as shown below for example--%> <a href="navPageTest2.aspx" onclick="getClickedValue3();">Postings_link_ex</a><br /> </div> <br /><br /> <div class="student_text"> <asp:RadioButton ID="RadioButton4" GroupName="reg" Text="myaccount" runat="server" onclick="return getCheckedValue4();" /> <br /> <%--OR how do i get it to work when using a URL as shown below for example--%> <a href="navPageTest2.aspx" onclick="getClickedValue4();">Myaccount_link_ex</a><br /> </div> <br /><br /> ****************************** start display ***************************** <br /><br /> <div id="presentationsNavBars" style="display: none;"> SOME HTML HERE ..........presentations nav bar............ </div> <div id="proposalsNavBars" style="display: none;" > SOME HTML HERE 44444444 proposals nav bar 44444444444 </div> <div id="postingsNavBars" style="display: none;" > SOME HTML HERE 2222222 postings nav bar 2222222222222 </div> <div id="myaccountNavBars" style="display: block;" > SOME HTML HERE 33333333 myaccount nav bar 33333333 </div> <br /><br /> ****************************** end ***************************** so here is my "Project" for this class http://sw.cs.wwu.edu/~strickk/Project2/project2.html and here are the directions where im stuck at, just right click view source to see the code. I believe what i am doing wrong is where i enter my variables and i dont know how to get an alert message to pop up using an if statement as well as getting the values for the distances to show up correctly directions: 8. Now we will write some JavaScript to validate the input. We don’t want the user to be able to enter the same origin and destination city when they book a ticket. So we will use an if statement to check that. If they have entered the same origin and destination city then we will tell them that by using an alert statement and make them select again. All of your code to validate the input code goes in between the single quotes of the onClick event in the Calculate Fare button. Follow these steps: a) Assign the value of the origin city to a variable called origin Note that the value that gets assigned to origin is actually 0, 60, 90, 120 or 150 (and NOT Bellingham, Everett, Seattle etc.) since the value we gave to the each element of the list was its distance from Bellingham. This will make our lives easier later when we compute the fare. b) Assign the value of the destination city to a variable called destination in a similar fashion. c) Write an if statement that will test whether origin is equal to destination and if it is then do two things. i. Issue an alert message that says Please input different origin and destination cities ii. Stop the execution of the JavaScript code in the onClick event. Use return; as the second statement inside the if statement. Remember to use curly braces to denote that two statements are contained within the if statement. Your if statement will have the following structure to it. if (<put the test you want to do here>) { alert(<put the message here>); return; Code: <script type="text/javascript" language="javascript"> function toggle() { var ele = document.getElementById("toggle"); var text = document.getElementById("display"); if(ele.style.display == "block") { ele.style.display = "none"; text.innerHTML = "Show"; } else { ele.style.display = "block"; text.innerHTML = "Hide"; } } </script> Code: <a href="javascript:toggle();" id="display" style="color:#000000">Show</a> <div id="toggle" style="display:none">CONTENT</div> The above toggle code works perfectly. How can I edit the code to use buttons instead of text? In other words: How can I replace two different texts that say "Show" and "Hide" with two different buttons that say "Show" and "Hide"? Thanks. Hi guys, I am working on my first validation form and although the Submit button works fine and puts me to the landing page, I don't get the alert, when nothing is checked. Please look at my code and help if you can. I really don't need anything fancy, just working Code: <!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" /> <meta name="keywords" content="social media survey, social media, media survey, survey, danish media, danish media survey" /> <meta name="description" content="This survey is a school project, not an actual research. It has been designed to figure out the connection between the gender of the Danish users and their knowledge and usage of social media." /> <script language="JavaScript" type="text/javascript"></script> <script> function isRadioButtonSelected(radioGrpName, errorMsg){ var radios = document.getElementsByName(radioGrpName); var i; for (i=0; i<radios.length; i=i+1 ){ if (radios[i].checked){ return true; } } alert(errorMsg); return false; } function validate(){ if(isRadioButtonSelected('gender', 'please select your gender')){ return true; } return false; } </script> <title>The Social Media survey</title> <style type="text/css"> <!-- body { font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif; background: #8DC63F; margin: 0; padding: 0; color: #000; } } a img { border: none; } .container { width: 960px; margin: 0 auto; } .header { background: #FFF; margin-top: 30px; background-color:transparent; background-image:url(header.jpg); background-attachment: fixed; background-position:left center; background-repeat:no-repeat; } .content { padding-left: 50px; padding-right: 50px; padding-top: 30px; padding-bottom: 30px; background-color:#E7EFB9; font-family:Verdana, Geneva, sans-serif; font-size: 13px; } .footer { background: #FFF; } .fltrt { float: right; margin-left: 8px; } .fltlft { float: left; margin-right: 8px; } .clearfloat { clear:both; height:0; font-size: 1px; line-height: 0px; } </style> </head> <body> <div class="container"> <div class="header"><img src="header1.jpg" alt="The Social Media survey" width="960" height="175" /></div> <div class="content"> <form id="page1" action="http://projects.knord.dk/interaction/saveforminfo.aspx" onsubmit="return validate(); method="post"> <input type="hidden" name="surveyid" value="igakotra" /> <input type="hidden" name="landingpage" value="http://www.google.com" /> <input type="hidden" name="usecookie" value="true" /> <h3>1. Choose your gender</h3> <input type="radio" name="gender" value="male" id="male"/><label for "male">Male</label> <input type="radio" name="gender" value="female" id="female"/><label for "female">Female</label><br /><br /> <input type="submit" name="submit" value="Submit"/> </form> </div> <div class="footer"><a href="page1.html"><img src="1page.jpg" width="960" height="99" alt="1/6 pages" /></div> </div> </body> </html> I really need it asap... thanks guys, you're awesome Hi, I have some basic code that allows me to press a button that inserts a new row in to my table, which also includes a text box. I also have a button that "should" allow me to remove the last text box. However, for some reason it doesn't work and I can't figure out why. The commented area works fine when active and accurately tells me the amount of rows that have been inserted. It is simply the delete part that doesn't work. Here is my code; PHP Code: var currentTxtBx = 0; function addRow(tableID) { if (currentTxtBx<10){ if (currentTxtBx<10){ var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "text"; element1.name = 'check'+(currentTxtBx+1); currentTxtBx++; cell1.appendChild(element1); } } else { alert('cannot add more than 10 boxes'); } } function deleteRow(tableID) { var allTxtBxs = document.getElementById('dataTable').getElementsByTagName('input'); if(allTxtBxs.length == 0){ alert('there are no text boxes to remove'); } else { //alert('you have ' +allTxtBxs.length+ ' textboxes'); document.getElementById('dataTable').removeChild(allTxtBxs[allTxtBxs.length-1]); currentTxtBx = allTxtBxs.length; } } If anyone could provide any advise or a solution to help me overcome this problem I would really appreciate it. Thanks. I have been looking around for a while on google and have come accross a few things but still am unable to find the exact codes. I am trying to have a page setup so that when the user clicks a button it will add preset text to a form box and keep the chronological order of buttons that are clicked. This is going to be used for my ambulance service to assist dispatch so basically i am looking for preset buttons that the dispatcher can click disp. and have the dispatch and time added to a list in the form box that can later be copied and emailed to our cell phones. Thanks for any help. 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 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> 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 /> 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.") } } 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 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. So when I enter in numbers for the calculator the numerical grade shows, but not the letter grade. I dont know if I called the function wrong or if my if statement is wrong. I have no idea. Can someone help me please? Code: <!DOCTYPE html> <html lang="en"> <head> <title>Lab</title> <meta charset="utf-8"> <script> function calculateGrade () { var test1 = document.getElementById("t1") var test2 = document.getElementById("t2") var finalexam = document.getElementById("t3") var labs = document.getElementById("t4") var projects = document.getElementById("t5") var quizzes = document.getElementById("t6") var grade= document.getElementById("fng") grade.value=parseFloat(0.15*test1.value)+parseFloat(0.15*test2.value)+parseFloat(0.20*finalexam.value)+parseFloat(0.30*labs.value)+ parseFloat(0.05*projects.value)+parseFloat(0.15*quizzes.value) } function getLetterGrade() { if (totalGrade >= 90) letterGrade = "A"; else if (totalGrade < 90 && totalGrade >= 80) letterGrade = "B"; else if (totalGrade < 80 && totalGrade >= 70) letterGrade = "C"; else if (totalGrade < 70 && totalGrade >= 60) letterGrade = "D"; else if (totalGrade < 60 && totalGrade >= 50) letterGrade = "F"; } </script> </head> <body> <form id="form1" name="form1"> <table> <tr> <th colspan="2"> Score </th> </tr> <tr> <td> Test 1 </td> <td><input type="text" name="t1" id="t1" value= ""></td> </tr> <tr> <td> Test 2 </td> <td><input type="text" name="t2" id="t2" value= ""></td> </tr> <tr> <td> Final Exam </td> <td><input type="text" name="t3" id="t3" value=""></td> </tr> <tr> <td> Labs </td> <td><input type="text" name="t4" id="t4" value=""></td> </tr> <tr> <td> Projects </td> <td><input type="text" name="t5" id="t5" value=""></td> </tr> <tr> <td> Quizzes </td> <td><input type="text" name="t6" id="t6" value=""></td> </tr> <tr> <th colspan="2"> <input type="button" name="b1" id="b1" value="Calculate Grade" onclick="calculateGrade(); getLetterGrade()"> </th> </tr> <tr> <td> Final numerical grade </td> <td><input type="text" name="fng" id="fng" style="border: none"></td> </tr> <tr> <td> Final letter grade </td> <td><input type="text" name="letterGrade" id="letterGrade" style="border: none"></td> </tr> </table> </form> </body> </html> 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. Hi,my current pop under code works ever 24hrs,but I would like to change it to work every hour,and/or to work every time a member clears his cookies.If I am not explaining this correctly please let me know and I will try to correct this. Code: function setCookie(name, value, time) { var expires = new Date(); expires.setTime( expires.getTime() + time ); document.cookie = name + '=' + value + '; expires=' + expires.toGMTString(); } Any help with this would be greatly appreciated!! Mike Edit:If you need me to post the whole code I have no prob with this.I only posted this part because I thought the issue would be in var expires = new Date();. Just want to know what should I change it to? Here is the whole code. Code: <script type="text/javascript"> var puShown = false; function doOpen(url) { if ( puShown == true ) { return true; } win = window.open(url, 'wmPu', 'toolbar,status,resizable,scrollbars,menubar,location,height=700,width=1100'); if ( win ) { win.blur(); puShown = true; } return win; } function setCookie(name, value, time) { var expires = new Date(); expires.setTime( expires.getTime() + time ); document.cookie = name + '=' + value + '; expires=' + expires.toGMTString(); } function getCookie(name) { var cookies = document.cookie.toString().split('; '); var cookie, c_name, c_value; for (var n=0; n<cookies.length; n++) { cookie = cookies[n].split('='); c_name = cookie[0]; c_value = cookie[1]; if ( c_name == name ) { return c_value; } } return null; } function initPu() { if ( document.attachEvent ) { document.attachEvent( 'onclick', checkTarget ); } else if ( document.addEventListener ) { document.addEventListener( 'click', checkTarget, false ); } } function checkTarget(e) { if ( !getCookie('popundr') ) { var e = e || window.event; var win = doOpen('My Site Name Here/'); setCookie('popundr', 1, 24*60*60*1000); } } initPu(); </script> I do know that most of you hate pop ups and pop unders,but this is not to annoy my users.I am just using this to promote another site that I own..Thanks again. Code: function dimensions(){ $('.resource-container').css("width",($(window).width() - 306) + 'px'); $('.resource-title').css("width",($(window).width() - 366) + 'px'); $('.resource-container').css("height",($(window).height() - 250) + 'px'); $('.resource-content ul').css("height",($(window).height() - 292) + 'px'); $('.resource-iframe').css("width",($(window).width() - 306) + 'px'); $('.resource-iframe').css("height",($(window).height() - 275) + 'px'); } function resourcego(id){ $.ajax({ url: "http://glynit.co.cc/resource.php?id=" + id + "&item=list&part=name", cache: false, success: function(data){ name = data; $.ajax({ url: "http://glynit.co.cc/resource.php?id=" + id + "&item=list&part=list", cache: false, success: function(data){ list = data; $('.resource-toolbar').html('<div id="resource-title" class="resource-title">' + name + '</div>'); $('.resource-content').html('<div class="resource-list"><ul>' + list + '</ul></div>'); dimensions(); } }); } }); } function viewresource(id,ref){ $.ajax({ url: "http://glynit.co.cc/resource.php?id=" + id + "&content=name", cache: false, success: function(data){ name = data; $('.resource-toolbar').html('<div id="resource-back" class="resource-back" onclick="resourcego(' + ref + ');">Back</div><div id="resource-title" class="resource-title">' + name + '</div><div id="resource-print" class="resource-print">Print</div>'); $('.resource-content').html('<iframe id="resource-iframe" class="resource-iframe" src="http://glynit.co.cc/resource.php?id=' + id + '&content=content"></iframe>'); dimensions(); } }); } $(window).load(function() {dimensions();}); $(window).resize(function() {dimensions();}); The webiste is http://www.glynit.co.cc/ and the login is guest:guest And the page is the resources page and it is the links on the left of that page that do not work. |