JavaScript - Update Html Table's Text Without Refresh
Hello All,
I'm working on a project which requires a small portion from a large table of information to be displayed on a webpage (sort of like a magnifying glass). The display will be a table of fixed size (m by n cells). Some of the cells will be merged. When the table updates, different sets of cells may be merged. It needs to be coded in HTML5, which I assume includes the use of JavaScript and CSS (The specs of this is rather unclear at the moment, so I'm going to cover all bases). Anyhow, looking through the HTML5 and JavaScript tutorials, I found two ways to solve this problem. One way would be to have a script to parse out the relevant information, and have it output into a table (dynamically generating the HTML required). The second way would be to have the script draw the table on its own in a canvas. User events (such as arrow keys on the keyboard) will change the position of the focus (move the magnifying glass in a cardinal direction). I hit a small snag with the first solution - Is it possible to update the table on the page (including changing the structure of it) without having to refresh? If you could point me to a relevant tutorial or example on the web, I'd greatly appreciate it. Similar TutorialsHere is my calander script PHP Code: <script src="http://www.runningprofiles.com/jquery.js" type="text/javascript"></script> <link href="http://www.runningprofiles.com/members/diary/facebox/facebox.css" media="screen" rel="stylesheet" type="text/css"> <script src="http://www.runningprofiles.com/members/diary/facebox/facebox.js" type="text/javascript"></script> <script> jQuery(document).ready(function($) { $('a[rel*=facebox]').facebox() }) </script> <?php // there is NO NEED to edit ANY of this code $ev_dat = array(); for ($i=0;$i<32;$i++) { $ev_dat[$i]=0; } $now = date("Y-m-d", time()); list($ty, $tm, $td) = explode('-',$now); // ty=thisyear, etc. used for highlighting 'today' include("cal_parms.php"); // assorted configuration variables include($dat_names); // retrieved from cal_parms.php as a 'language' file if (!isset($_GET['m'])) { $m = date("m",mktime()); } else { $m = $_GET['m']; } if (!isset($_GET['y'])) { $y = date("Y",mktime()); } else { $y = $_GET['y']; } /*== get what weekday the first is on ==*/ $tmpd = getdate(mktime(0,0,0,$m,1,$y)); $month = $tmpd["month"]; $firstwday= $tmpd["wday"]; if ($firstDayIsMonday == 1) { if ($firstwday == 0) { $firstwday = 6; } else { $firstwday--; } } $lastday = mk_getLastDayofMonth($m,$y); /*== get the last day of the month ==*/ function mk_getLastDayofMonth($mon,$year) { for ($tday=28; $tday <= 31; $tday++) { $tdate = getdate(mktime(0,0,0,$mon,$tday,$year)); if ($tdate["mon"] != $mon) { break; } } $tday--; return $tday; } // compute range of dates for this month to match dates in database in the format yyyy-mm-dd if (strlen($m)<2) { $q="0"; $q.=$m; } else { $q = $m; } $dats_beg = $y. "-". $q. "-01"; $dats_en = $y. "-". $q. "-". $lastday; // open db conn and select all records where date is between $dats_beg and $dats_en include("cal_db_conn.php"); mysql_connect($db_host, $db_login, $db_pass) or die ("Can't connect!"); mysql_select_db($db_name) or die ("Can't open database!"); $query = "SELECT * FROM $db_table WHERE (ev_dat>='$dats_beg') AND (ev_dat<='$dats_en') "; $result = mysql_db_query($db_name, $query); // any matches? if ($result) { // handle the matches and pass relevant info to arrays while ($myrow = mysql_fetch_array($result)) { $found = $myrow['ev_dat']; $pieces = explode("-", $found); $dd = intval($pieces[2]); $ev_dat[$dd] = $myrow['id']; } } ?> <table cellpadding="1" cellspacing="1" border="0" bgcolor="#<? echo $bg_edge; ?>"> <tr><td colspan="7" bgcolor="#<? echo $bg_top; ?>"> <table cellpadding="1" cellspacing="1" border="0" width="100%"> <tr bgcolor="#<? echo $bg_top; ?>"><th width="20" style="<?php echo $hcell; ?>"><a href="<? echo $username; ?>&m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"><img src='http://www.runningprofiles.com/calendar/images/prev.gif' height='18' width='18' alt='' border='0' /></a></th> <th style="<?php echo $hcell; ?>"> <?php echo "<a href='../members/diary/show-month.php?mon=". $m. "&yr=". $y. "'rel=\"facebox\">"; echo "<span style='text-decoration:none'>". $mo[intval($m)]. " ". $y. "</span></a>"; ?> </th> <th width="20" style="<? echo $hcell; ?>"><a href="<? echo $username; ?>&m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y ?>"><img src='http://www.runningprofiles.com/calendar/images/next.gif' height='18' width='18' border='0' alt='' /></a></th> </tr> </table> </td></tr> <tr bgcolor="#<? echo $bg_top; ?>"> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[1]; ?></th> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[2]; ?></th> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[3]; ?></th> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[4]; ?></th> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[5]; ?></th> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[6]; ?></th> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[7]; ?></th> </tr> <? $d = 1; $wday = $firstwday; $firstweek = true; /*== loop through all the days of the month ==*/ while ( $d <= $lastday) { /*== set up blank days for first week ==*/ if ($firstweek) { if ($wday!=0) { echo "<tr bgcolor='#". $bg_tabl. "'>\n"; for ($i=1; $i<=$firstwday; $i++) { echo "<td style='". $tcell. "' bgcolor='#". $bg_fill. "'> </td>\n"; } } /*== Sunday start week with <tr> ==*/ else { echo "<tr bgcolor='#". $bg_tabl. "'>\n"; } $firstweek = false; } /*== check for event ==*/ echo "<td style='". $tcell. "' "; // is this day 'today' AND there's no event today if (($ty==$y) && ($tm==$m) && ($td == $d) && (!$ev_dat[$d])) { echo "bgcolor='#". $bg_now. "'>". $d; } elseif ($ev_dat[$d]) { // get what's happening that day and use as 'mouseOver' for the link $query = "SELECT * FROM $db_table WHERE id=$ev_dat[$d] "; $result = mysql_query($query); $ev = mysql_fetch_array($result); $titl = $ev['ev_title']; echo "bgcolor='#". $bg_act. "'>"; $url = "../members/diary/show.php?event=". $ev_dat[$d]. "&sho=". $win_sho; echo "<a href=' $url' rel=\"facebox\" title=\"". $titl. "\">". $d. "</a>"; } else { echo "bgcolor='#". $bg_days. "'>". $d; } echo "</td>\n"; /*== Saturday end week with </tr> ==*/ if ($wday==6) { echo "</tr>\n"; } $wday++; $wday = $wday % 7; if (($wday==0) AND ($d!=$lastday)){ echo "<tr bgcolor='#". $bg_tabl. "'>\n"; } $d++; } // and close off the table if (($wday!=7) AND ($wday!=0)) { for ($i=$wday; $i<=6; $i++) { echo "<td style='". $tcell. "' bgcolor='#". $bg_fill. "'> </td>\n"; } echo "</tr>"; } echo "\n</table>"; include("win_open.php"); ?> what would be the best way to make it so that if you wish to chnage the month it changed the month on page rather than refresh the whole page its on? Hello Friends In my jsp,Struts project i am using the javascript calendar control for selecting the date and by using function calcage() i am calculating the age of the user but problem occurs when the page refreshes OR when user updated the other values such as name ,contact no. Then the value of the age is set as 0 in the textfield as 0 So can you please tell me why this problem occurs And please give me solution Thanks hi i have a table with some document.write statements inside that write inside the cells. i need to refresh the table from a function so the statements will execute again. but i only want the table to refresh not the whole page document.location.reload() this does the page but can i put the tables id in the brackets or something. thanks Hello, I'm Chris, welcome everyone. I'm in a need of help. I'm writing application that displays messages from users. This messages are kept in external XML file and every time user post a new message this XML document is appended. What I want to do is to display all messages at the bottom of screen. Messages have to slide horizontally in one line. To do that I used this code: Code: horizontalScroll.js: var scrllTmr; window.onload = function(){ document.getElementById('scroll').style.overflow = 'hidden'; document.getElementById('scrollme').style.float = 'left'; document.getElementById('scrollme').style.position = 'relative'; cw = parseInt(document.getElementById('scroll').offsetWidth/2); w = parseInt(document.getElementById('scrollme').offsetWidth/2); lft = cw + w; document.getElementById('scrollme').style.left = lft + "px"; scrollStep(cw,w,lft); } function scrollStep(cw,w,lft){ if(lft == w * -1) lft = cw + w; document.getElementById('scrollme').style.left = lft + "px"; if(scrllTmr) clearTimeout(scrllTmr); scrllTmr = setTimeout('scrollStep(cw,w,' + (lft - 1) + ')',10); } index.html: <div id="scroll"><div id="scrollme"> <h1 style="white-space: nowrap;">Lets scroll this right here 1 | Lets scroll this right here 2 | Lets scroll this right here 3 | Lets scroll this right here 4 | Lets scroll this right here 5 | Lets scroll this right here 6 | Lets scroll this right here 7 | Lets scroll this right here 8 | Lets scroll this right here 9 | Lets scroll this right here 10 | Lets scroll this right here 11 | Lets scroll this right here 12 | Lets scroll this right here 13 | Lets scroll this right here 14 | Lets scroll this right here 15 | Lets scroll this right here 16 | Lets scroll this right here 17 | Lets scroll this right here 18 | Lets scroll this right here 19 | Lets scroll this right here 20 </h1></div></div> The problem with that code is that at 1/3 length of text it starts from beginning and this is wrong. The text have to scroll to the very end and then start to scroll from beginning again. Another thing, that I'm unable to deal with is refreshing/reloading the content from XML file. What I need to do is to check if XML was changed/appended and if it was then I have to add this added message to text that scrolls horizontally and view it at the end of horizontal text. I'm pretty sure I have to use Ajax here. Also, if text from XML file will be added to horizontal text page cannot refresh and start scrolling from beginning, but instead of that if have to append horizontal text and continue to scroll showing appended message at the end. Any advices, please? Thanks, Chris hello, can anyone help me with a javascript-php-ajax problem? I have created a table with checkboxes and whenever an ajax function is called to refresh, the checkboxes that were highlighted and checked get reset, here is my javascript for the check function: $(document).ready(function() { $("#checkall").live('click',function(event){ $('input:checkbox:not(#checkall)').attr('checked',this.checked); //To Highlight if ($(this).attr("checked") == true) { //$(this).parents('table:eq(0)').find('tr:not(#chkrow)').css("background-color","#FF3700"); $("#policy").find('tr:not(#chkrow)').css("background-color","#FC9A01"); } else { //$(this).parents('table:eq(0)').find('tr:not(#chkrow)').css("background-color","#fff"); $("#policy").find('tr:not(#chkrow)').css("background-color","#FFF"); $("#policy").find('tr.alt:not(#chkrow)').css("background-color","#EAF2D3"); } }); $('input:checkbox:not(#checkall)').live('click',function(event) { if($("#checkall").attr('checked') == true && this.checked == false) { $("#checkall").attr('checked',false); $(this).closest('tr').css("background-color","#ffffff"); } if(this.checked == true) { $(this).closest('tr').css("background-color","#FC9A01"); CheckSelectAll(); } if(this.checked == false) { $(this).closest('tr').css("background-color","#ffffff"); $(this).closest('tr.alt').css("background-color","#EAF2D3"); } }); function CheckSelectAll() { var flag = true; $('input:checkbox:not(#checkall)').each(function() { if(this.checked == false) flag = false; }); $("#checkall").attr('checked',flag); } }); Hello! I have been designing a schedule website which will be displayed on several computers throughout the building, I would like to be able to edit the JS during the day but I do not want to be going all through the building refreshing every computer to make sure it has the latest JS version. I also do not want use the meta HTML tag to refresh because that is too noticeable with the images reloading. Basically I would like to only refresh the JS file. I found this link, but it has a button which defeats the purpose. Any way of doing this without the button? FYI, I have the javascript setTimeout("driver()",1000); already so that the clock stays up to date. Not sure if that will make things easier or more complicated... EDIT: not sure why the ICODE tags are not working EDIT 2: Forgot the website! http://www.philnicholas.com/2009/05/...ing-your-page/ Hi all, I need some help to update my table.It consists about selecting one team from each two drop-down list and enter the score to the two textbox. Textbox 1 relate to the team selected from the first drop-down list and textbox2 relate to the team selected from the second drop-down list.If the score entered in textbox1 is greater than textox2 means that team selected from the first drop-down win and need to update the point of the related team in the table. win = 3 point draw = 1 point lost = 0 point Here what I have down so far...any idea or referencing how I can tackle this task? Code: <form id="foot"> <label for="first">Please select the first team:</label> <select id="first"> <option value="team 1">team 1</option> <option value="team 2">team 2</option> <option value="team 3">team 3</option> </select> <label for="second">Please select the second team:</label> <select id="second"> <option value="team 1">team 1</option> <option value="team 2">team 2</option> <option value="team 3">team 3</option> </select> <input type="submit" value="Update"/><br/> <label for="username">Enter score for the match (First team and Second team)</label> <input type="text" id="txtbox1" size="2"/> <input type="text" id="txtbox2" size="2"/> </form><br/> <table border="1" width="50%" id="score"> <thead> <tr> <th>Team</th> <th>Point</th> </tr> <tbody> <tr> <td>Team 1</td> <td>30</td> </tr> <tr> <td>Team 2</td> <td>20</td> </tr> <tr> <td>Team 3</td> <td>10</td> </tr> </tbody> </thead> </table> function updateTable(){ var form = document.getElementById("foot"); var firstdrop = document.getElementById("first"); var seconddrop = document.getElementById("second"); var box1 = ParseInt(document.getElementById("txtbox1").value); var box2 = ParseInt(document.getElementById("txtbox2").value); var table = document.getElementById("score"); arrwin = ["3"]; arrdraw = ["1"]; arrlost = ["0"]; } </script> i want to update the table -play -win -draw -lost -goals in the following code when i enter the score. (e.g if i select manchester united from drop down1 and chelsea from dropdown 2- i get to update their score. let's say i update their score 1-0. in this case manchester won. i want the record to updated to manchester united as :win 1 - draw 0 - lost 0 goals 1 and chelsea as :win 0 - draw 0 lost 1 goals -1. what shall i do? how do i continue? <!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> <link rel="stylesheet" href="../css/foot.css" type="text/css" media="screen"/> </head> <body> <div class="container"> <header> <h1>Online Automated Football League Result</h1> </header> </div> <div class="ball"> <label for="first">Please select the first team:</label> <select id="first"> <option value="team_1">Manchester United</option> <option value="team_2">Liverpool</option> <option value="team_3">Chelsea</option> <option value="team_4">Arsenal</option> <option value="team_5">Manchester City</option> <option value="team_6">Real Madrid</option> <option value="team_7">Bayern Munich</option> <option value="team_8">Barcelona</option> </select> <label for="second">Please select the second team:</label> <select id="second"> <option value="team_1">Manchester United</option> <option value="team_2">Liverpool</option> <option value="team_3">Chelsea</option> <option value="team_4">Arsenal</option> <option value="team_5">Manchester City</option> <option value="team_6">Real Madrid</option> <option value="team_7">Bayern Munich</option> <option value="team_8">Barcelona</option> </select> <label for="username">Enter score for the match (First team and Second team)</label> <input type="text" id="txtbox1" size="2"/> <input type="text" id="txtbox2" size="2"/> <input type="button" value="Update" onclick="updateTable();"/><br/> <div id="err" style="color:Red;"></div> <br/> <table border="1" width="50%" id="score"> <thead> <tr> <th>Team</th> <th>Point</th> <th>Play</th> <th>Win</th> <th>Draw</th> <th>Lost</th> <th>Goal.S</th> <th>Goal.C</th> <th>Goal.D</th> </tr> </thead> <tbody> <tr> <td>Manchester United</td> <td id="team_1">0</td> <td id="team_1">0</td> <td id="team_1">0</td> <td id="team_1">0</td> <td id="team_1">0</td> <td id="team_1">0</td> <td id="team_1">0</td> <td id="team_1">0</td> </tr> <tr> <td>Liverpool</td> <td id="team_2">0</td> <td id="team_2">0</td> <td id="team_2">0</td> <td id="team_2">0</td> <td id="team_2">0</td> <td id="team_2">0</td> <td id="team_2">0</td> <td id="team_2">0</td> </tr> <tr> <td>Chelsea</td> <td id="team_3">0</td> <td id="team_3">0</td> <td id="team_3">0</td> <td id="team_3">0</td> <td id="team_3">0</td> <td id="team_3">0</td> <td id="team_3">0</td> <td id="team_3">0</td> </tr> <tr> <td>Arsenal</td> <td id="team_4">0</td> <td id="team_4">0</td> <td id="team_4">0</td> <td id="team_4">0</td> <td id="team_4">0</td> <td id="team_4">0</td> <td id="team_4">0</td> <td id="team_4">0</td> </tr> <tr> <td>Manchester City</td> <td id="team_5">0</td> <td id="team_5">0</td> <td id="team_5">0</td> <td id="team_5">0</td> <td id="team_5">0</td> <td id="team_5">0</td> <td id="team_5">0</td> <td id="team_5">0</td> </tr> <tr> <td>Real Madrid</td> <td id="team_6">0</td> <td id="team_6">0</td> <td id="team_6">0</td> <td id="team_6">0</td> <td id="team_6">0</td> <td id="team_6">0</td> <td id="team_6">0</td> <td id="team_6">0</td> </tr> <tr> <td>Bayern Munich</td> <td id="team_7">0</td> <td id="team_7">0</td> <td id="team_7">0</td> <td id="team_7">0</td> <td id="team_7">0</td> <td id="team_7">0</td> <td id="team_7">0</td> <td id="team_7">0</td> </tr> <tr> <td>Barcelona</td> <td id="team_8">0</td> <td id="team_8">0</td> <td id="team_8">0</td> <td id="team_8">0</td> <td id="team_8">0</td> <td id="team_8">0</td> <td id="team_8">0</td> <td id="team_8">0</td> </tr> </tbody> </table> </div> <script type="text/javascript"> function updateTable(){ document.getElementById('err').innerHTML = ''; var firstdrop = document.getElementById("first").value; //get team from 1st drop down var seconddrop = document.getElementById("second").value; //get team from 2nd drop down var temp1 = document.getElementById("txtbox1").value; //get score for 1st team var box1 = Number(temp1);//store score of 1st team var temp2 = document.getElementById("txtbox2").value; //get score for 2nd team var box2 = Number(temp2);//store score of 2nd team var tablebox1 = Number(document.getElementById(firstdrop).innerHTML);//store name of 1st team var tablebox2 = Number(document.getElementById(seconddrop).innerHTML);//store name of 2nd team if(temp1 == '' || temp2 == ''){ document.getElementById('err').innerHTML = 'Please enter both scores.'; alert("Please enter both scores."); return; } if(firstdrop != seconddrop){ if(box1 > box2){ document.getElementById(firstdrop).innerHTML = tablebox1 + 3; }else if(box1 < box2){ document.getElementById(seconddrop).innerHTML = tablebox2 + 3; }else{ document.getElementById(firstdrop).innerHTML = tablebox1 + 1; document.getElementById(seconddrop).innerHTML = tablebox2 + 1; } }else{ document.getElementById('err').innerHTML = 'Please select two different teams.'; alert("Please select two different teams."); } } </script> </body> </html> Hi. I am new here. I wanted help for a JavaScript code. You might think I'm lazy for not writing it myself, but the truth is I am not a JavaScript coder. I just have a really simple website and I am trying to do something for which I know JS is required but I don't know how to do it. I've also searched around but couldn't find the appropriate code. What I want to do is to make an html page load a different background image every time it refreshes. I will have a list of background images and I want to be able to add in this list, without having to change anything else in the codes after I do this (I think this is made by making an array of images and by putting .length somewhere in the codes, but I don't know exactly how I should do this). I already know how to do an external file (.js) and link to it from my .html page. Now I want the code to put in the .js file, and the code to put in the <body> of my .html file. Please help me Thanks Hello im trying to update a text area value with edited code with javascript, i dont know how to and im asking if you guys know
Hi all, I'm a JavaScript newbie and I am trying to create a situation where a user clicks a button, a popup is launched in which they have a textarea to enter some text. Once they hit submit, the popup should disapear and a certain text element on the previous page should be updated to show what they entered. Its like this, but obviously it wouldn't be on the same page: http://www.tizag.com/javascriptT/jav...-innerHTML.php - updating text based on user input. I have the popup part working just fine: index.php Code: <script type="text/javascript"> <!-- function editText() { sList = window.open("editText.html", "list", "width=300,height=300"); } // --> </script> which is triggered by an onclick="editText()" however I can seem to figure out how to update the box with the text they enter in the popup part. I'm sure it is something do with innnerHTML. editText.html Code: <script type="text/javascript"> function changeText2(){ var userInput = document.getElementById('userInput').value; document.getElementById('boldStuff2').innerHTML = userInput; } </script> <p>Welcome to the site <b id='boldStuff2'>dude</b> </p> <input type='text' id='userInput' value='Enter Text Here' /> <input type='button' onclick='changeText2()' value='Change Text'/> Can anybody help me out here? Many thanks Hi, I can't get this to work, but I'm trying to update the text into an iframe on the same page with a button, for a game I'm making, the battle messages when you attack. Please any help greatly appreciated. here is the html file with the button and onClick Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <style type="text/css"> body { background-color: black; color: gold; } </style> </head> <body> <html> <body> <script type="text/javascript"> var my_var = "Hello World!" function text2add(){ return '<font color=gold><strong>'+my_var+'</strong></font>'; } </script> <form> <form><input type="button" value="change" onClick="text2add();"/></form> Main page! Frame below. <br><br> <iframe src="iframe.html" ></iframe> </body> </html> </body> </html> and here is the iframe page code] Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <script type="text/javascript"> document.write(parent.text2add()); </script> This is my iframe </body> </html> I work at a bar in Louisiana and have been put in charge of the website. Every day (Sun-Sat) we update the main page with who is bartending that night, along with a few other edits. I don't come into the office until 2pm, Mon-Fri. I would really prefer if the website could be updated 'automatically' at like, 4am or something, every day. Instead of me struggling to figure out how I'll update it on weekends. I have to use FrontPage, so I'm limited in the types of codes I can use. But Javascript seems to work well. What I'm thinking is have an 'updates' folder with pages labeled either by weekday (sunday.html monday.html tuesday.html, etc) or by date (072410.html, 072510.html, etc). Then the main page having some code that pulls from those files. (I'd prefer the weekday setup if I have the option) Since the bar doesn't close until 2am most days, I'd rather not have it change over at exactly midnight, but I'm willing to work with that if it means I know it's being updated every day regularly. I'm creating a page that calculates a number depending on what value is inputted into a text field. I need to create some javascript that updates this new calculated value and outputs it next to the input field. Anytime the user changes the number, it recalculates the value. My calculation is currently being produced by PHP, however if I need to, I can create javascript as well to recalculate these numbers. My formulas for all 4 calculations are as follows: First: Inputted Value * 10 Second: Inputted Value * 20 Third: Inputted Value / 2 Fourth: Inputted Value * 2 Here is my code I'm working with: PHP Code: <?php session_start(); $username = $_SESSION['username']; include_once('inc/connect.php'); $credquery = mysql_query("SELECT * FROM userstats WHERE username='$username'"); $row = mysql_fetch_assoc($credquery); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $sitetobanner = $_POST['sitetobanner']; $sitetotext = $_POST['sitetotext']; $bannertotext = $_POST['bannertotext']; $texttobanner = $_POST['texttobanner']; if (isset($sitetobanner)){ $bannerimp = round($_POST['bannerimp']); if ($bannerimp > 1){ $s = "s"; } if ($bannerimp <= $credits){ $newcredits = $credits - $bannerimp; $newbannercredits = $bannerimp * 10; $totalbannercredits = $bannercredits + $newbannercredits; $updatebanner = mysql_query("UPDATE userstats SET credits='$newcredits', bannercredits='$totalbannercredits' WHERE username='$username'"); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $convertedbanner = "You converted ".$bannerimp." credit".$s." into ".$newbannercredits." banner impressions"; } else{ if ($credits>1){ $mycredits = $credits - 1;} $errorbanner = number_format($mycredits, 0, '.', ''); } } if (isset($sitetotext)){ $textimp = round($_POST['textimp']); if ($textimp > 1){ $s = "s"; } if ($textimp <= $credits){ $newcredits = $credits - $textimp; $newtextcredits = $textimp * 20; $totaltextcredits = $textcredits + $newtextcredits; $updatebanner = mysql_query("UPDATE userstats SET credits='$newcredits', textcredits='$totaltextcredits' WHERE username='$username'"); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $convertedtext = "You converted ".$textimp." credit".$s." into ".$newtextcredits." text ad impressions"; } else{ if ($credits>1){ $mycredits = $credits - 1;} $errortext = number_format($mycredits, 0, '.', ''); } } if (isset($texttobanner)){ $texttobannerimp = round($_POST['texttobannerimp']); if ($texttobannerimp > 1){ $s = "s"; } if ($texttobannerimp <= $textcredits){ if ($texttobannerimp>=2&&$texttobannerimp>""){ $newcredits = $textcredits - $texttobannerimp; $newbannercredits = $texttobannerimp / 2; $totalbannercredits = $bannercredits + $newbannercredits; $updatebanner = mysql_query("UPDATE userstats SET textcredits='$newcredits', bannercredits='$totalbannercredits' WHERE username='$username'"); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $convertedtextimp = "You converted ".$texttobannerimp." text ad impression".$s." into ".$newbannercredits." banner impressions"; } else{ $convertedtextimp = "You Hag"; } } else{ if ($textcredits>1){ $mycredits = $textcredits - 1;} $errortextimp = number_format($mycredits, 0, '.', ''); } } if (isset($bannertotext)){ $bannertotextimp = round($_POST['bannertotextimp']); if ($bannertotextimp > 1){ $s = "s"; } if ($bannertotextimp <= $bannercredits){ $newcredits = $bannercredits - $bannertotextimp; $newtextcredits = $bannertotextimp * 2; $totaltextcredits = $textcredits + $newtextcredits; $updatebanner = mysql_query("UPDATE userstats SET bannercredits='$newcredits', textcredits='$totaltextcredits' WHERE username='$username'"); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $convertedbannerimp = "You converted ".$bannertotextimp." banner impression".$s." into ".$newtextcredits." text impressions"; } else{ if ($bannercredits>1){ $mycredits = $bannercredits - 1;} $errorbannerimp = number_format($mycredits, 0, '.', ''); } } ?> <html> <head> <title>Convert Credits</title> <script type="text/javascript" language="javascript"> function inputLimiter(e,allow) { var AllowableCharacters = ''; if (allow == 'NumbersOnly'){AllowableCharacters='0123456789.';} var k; k=document.all?parseInt(e.keyCode): parseInt(e.which); if (k!=13 && k!=8 && k!=0){ if ((e.ctrlKey==false) && (e.altKey==false)) { return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1); } else { return true; } } else { return true; } } </script> </head> <body> <h1>Convert Credits</h1><br /> Credits: <?php echo $credits; ?><br /> Banner Impressions: <?php echo $bannercredits; ?><br /> Text Ad Impressions: <?php echo $textcredits; ?><br /> <form action="convert.php" method="POST"> <h3>Credits To Banner Impressions</h3> Convert <input type="text" name="bannerimp" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" value="<?php echo $errorbanner; ?>" onChange=""> credits into BLANK Banner Impressions! <input type="submit" name="sitetobanner" value="Convert"><br /> <?php echo $convertedbanner; ?> </form> <form action="convert.php" method="POST"> <h3>Credits To Text Ad Impressions</h3> Convert <input type="text" name="textimp" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" value="<?php echo $errortext; ?>"> credits into BLANK Text Ad Impressions! <input type="submit" name="sitetotext" value="Convert"><br /> <?php echo $convertedtext; ?> </form> <form action="convert.php" method="POST"> <h3>Text Ad To Banner Impressions</h3> Convert <input type="text" name="texttobannerimp" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" value="<?php echo $errortextimp; ?>"> Text Ad Impressions into BLANK Banner Impressions! <input type="submit" name="texttobanner" value="Convert"><br /> <?php echo $convertedtextimp; ?> </form> <form action="convert.php" method="POST"> <h3>Banner To Text Ad Impressions</h3> Convert <input type="text" name="bannertotextimp" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" value="<?php echo $errorbannerimp; ?>"> Banner Impressions into BLANK Text Ad Impressions! <input type="submit" name="bannertotext" value="Convert"><br /> <?php echo $convertedbannerimp; ?> </form> </body> </html> Hi, I have the below code: Code: <script type="text/javascript"> function loadQuickMessageCheck(File,ID){ var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; eucalyptus = setInterval(function(){loadQuickMessageCheck(File,ID)},20000); } } xmlhttp.open("POST",File,true); xmlhttp.send(); } </script> But I am overloading the server and crashing it. I've googled the issue and have found people with similar problems who talk about the need to cancel the last refresh request before they send the next refresh. I even found this nice piece of code which worked for someone else. Quote: try{window.clearTimeout(tRefresh)} catch(err) {} tRefresh = setInterval(setContext, varInterval*60*1000); } I am not sure if this is the solution that I am looking for but if it is all my attempts at applying this code has been a bit of a disaster. Hi, I am trying to implement something like a javascript that can click and focus the Status Update Box on Facebook. Till now, I have nothing in hand that can perform the task so I thought about a javascript that can do it. I am not even a newbie to javascript but I know that it can perform various complicated tasks on client side. Can anyone here tell me how do I click the Status Update box and set it to focused by a javascript so that when I start typing the Status box receive the text ? Thanks hi, all... haven't found exactly the solution here, and trying to cobble something together but it's just not working. php is doing the heavy lifting in terms of generating the code, but the upshoot is i have a script: Code: <script type="text/javascript"> var values[1] = "This layout includes a 'title' and 'body' content block."; var values[2] = "This layout features everything included in the Standard Page layout as well as a 'comments' block."; function replaceText( var_id) { document.getElementByID(pageLayout_replace).innerHTML = values[var_id]; } </script> and a select box: Code: <fieldset> <legend>Page Layouts</legend> <label for="pageLayout" class="half left">Choose a page layout<br /> <select name="pageLayout" id="pageLayout" size="5" onChange="replaceText(this.options[this.selectedIndex]);"> <option value="1">Standard Page</option> <option value="2">Standard Page w/Comments</option> </select> </label> <label class="half right"> Page Layout Description:<br /> <span id="pageLayout_replace">Click on a page layout title to the left to get a description here.</span> </label> </fieldset> however, the error console in firefox says Code: Error: missing ; before statement Line: 14, Column: 8 Source Code: var values[1] = "This layout includes a 'title' and 'body' content block."; and then when i try to select one of the items, Code: Error: replaceText is not defined Line: 1 any insight? thanks in advance! Hello, everyone... I have this problem that is really bugging me. I am trying to implement this script found in Javascriptkit: http://www.javascriptkit.com/script/...ltooltip.shtml It has a very unique feature of grabbing arbitrary HTML tags and attaching tooltips to them. Priceless to my site. But the problem is, the script only works with jQuery up to 1.2.6... after that version, it stops working entirely. Quite an issue, as you can imagine. It also has some issues with browsers other than Firefox that I hope updating the code might fix. I don't have any lead on this... could anybody look into the code and tell me what's wrong? Thank you, hi the title pretty much says it but il go into a little more deph, im looking for a piece of script that i can insert into my masterpage which will fetch the year from the server and display it on the footer. just to save our company updating the dates each year. cheers, ant. |