Jump to content

Search the Community

Showing results for tags 'Functions'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Found 18 results

  1. Hello - first time posting. I've searched the forums to see if anyone else had the same question, with no luck. I'm going through the lessons in the tutorial but I can't figure out what's going on in part of the JS Type Conversion lesson. I'll link to the full lesson here, but below is the part I'm having trouble with: (mainly the function) I have no idea what's happening in the function... could someone be kind enough to break it down in detail for me? I understand how arrays work. But the function here has me stumped. Thanks so much
  2. Please i dont know why the my little code do not run the header function - header('Location: http://www.example.com/'); Please i need ans. thanks <?php session_start(); //start the session for the page include("db.php"); //include database file //Check if page was entered by a submit button $user_name=$_POST['user_name']; //Get username !!FROM FORM!! $password=($_POST['password']); //Get name !!FROMFORM!! if (!empty($user_name) && !empty($password)) { $ck=$flash->prepare("SELECT * FROM `data` WHERE `user`=:user_name AND `password`=:password "); //get rows where the username or email address is allready registered $ck->bindParam(':user_name',$user_name); $ck->bindParam(':password',$password); $ck->execute(); //if email address allready excists if($ck->rowCount() > 0) { header('Location: http://www.example.com/'); }} ?>
  3. Hello, this is my first post on the forums after learning HTML and JavaScript for the past 2 weeks. I have a suggestion to make for the JavaScript Functions tutorial, specifically learning how to call a function. The tutorial is very good overall and I am enjoying learning about HTML & JavaScript. As this is my first exposure to coding, my suggestion may be out of place or unusual that I did not know this particular information. However, the JavaScript tutorial never to my knowledge taught me how to call a function the way Exercise 1 at the bottom of the Function tutorial (https://www.w3schools.com/js/js_functions.asp) asked me to do. The answer to call the function as Exercise 1 asks you to do is to insert the code "myFunction();" after the curly bracket however all throughout the JavaScript and particularly the Function tutorial, the user had been taught to call functions by inserting the code "document.getElementById("demo").innerHTML = myFunction();" after the curly bracket. The "return" statement was not used in Exercise 1 as I had felt I was most comfortable using. I would suggest strongly that some line or section be inserted in the JavaScript Function tutorial to teach the method of using "myFunction();" to call a function, as I did not understand that functionality and thought the Exercise was impossible to figure out without looking at the answer. Maaaybe the Exercise is designed to teach you to call a function using "myFunction();" but if that is true, in my opinion it is a poor way to teach that tool. Thank you for your time and in general a great website.
  4. Hi, I've made an html page that invokes a function automatically ( using the parentheses b/4 & after ) to make a table from an XML file. It worked great with a little help from you guys. I then made another one to read a different XML file and that worked great. I want to put both tables on the same page so I made a couple of 'divs' and positioned each in a column formation. That part seems to work well, but I am calling the 2 functions to make the tables consecutively and it doesn't work as I wanted. When I open this file in a browser, as it is here, I get only the second table in the second column correctly; and if I comment out the second table, I get only the first table in the first column correctly. I've included the code below; I hope someone can tell me how to do this. Also just a sample of the 2 XMLs I'm trying to display. Do I need a wrapper function with the others invoked from it, or something like that. Thanks <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Service Club Collections</title> <style> .wholePage { position: relative; width: 1350px; height: 2000px; border: 2px solid red; margin:auto;} .scColl { position:absolute; top:0; left:0; width:1050px; height:2000px; border:2px solid red;} .scTot { position: absolute; top: 0; right: 0; width: 250px; height: 2000px; border: 2px solid red;} #collections { position:absolute; top:0; left:0;} #totals { position:absolute; top:0; right:0;} table, th, td { border: 1px solid red; border-collapse: collapse;} th, td { padding: 7px 10px;} th { font-size:14px; color: firebrick;} td { font-size:12px; color: darkolivegreen; text-align: center;} </style> </head> <body> <a href="ringerinfo.html" type="button">Return</a> <div class="wholePage"> <div class="scColl"> <table id="collections"></table> </div> <div class="scTot"> <table id="totals"></table> </div> </div> <script> (function loadXMLCollDoc() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xmlhttp.open("GET", "datafiles/servClubColl.xml", true); xmlhttp.send(); })(); function myFunction(xmlcoll) { var i; var xmlDoc = xmlcoll.responseXML; var table ="<tr><th>Service Club</th><th>Ring Date</th><th>Location</th><th>Start Time</th><th>End Time</th><th>Total Bills</th><th>Total Coins</th><th>Total Checks</th><th>Total Kettle</th></tr>"; var x = xmlDoc.getElementsByTagName("scCollections"); for (i = 0; i <x.length; i++) { table += "<tr><td>" + x[i].getElementsByTagName("RingerName")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("RingDate")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("Location")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("SchedStart")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("SchedEnd")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("Bills")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("Coins")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("Checks")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("AmountCollected")[0].childNodes[0].nodeValue + "</td></tr>"; } document.getElementById("collections").innerHTML = table; } (function loadXMLTotDoc() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xmlhttp.open("GET", "datafiles/scTotals.xml", true); xmlhttp.send(); })(); function myFunction(xmltot) { var i; var xmlDoc = xmltot.responseXML; var table = "<tr><th>Service Club</th><th>Seasonal Total</th></tr>"; var x = xmlDoc.getElementsByTagName("Totals"); for (i = 0; i < x.length; i++) { table += "<tr><td>" + x[i].getElementsByTagName("ServClub")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("TotalAmount")[0].childNodes[0].nodeValue + "</td></tr>"; } document.getElementById("totals").innerHTML = table; } </script> </body> </html> Here is just a sample of the XML data files *********************************** <?xml version='1.0' encoding='utf-8'?> <dataroot> <scCollections> <RingerName>1st National bank scotia</RingerName> <RingDate>Dec 12 - Mon</RingDate> <Location>Price Chopper Niskayuna Left Door</Location> <SchedStart>9:00 am</SchedStart> <SchedEnd>9:00 pm</SchedEnd> <Bills>$ 243</Bills> <Coins>$ 27</Coins> <Checks>$ 00</Checks> <AmountCollected>$ 270</AmountCollected> </scCollections> <scCollections> <RingerName>Advisory Board</RingerName> <RingDate>Dec 9 - Fri</RingDate> <Location>Co-Op Nott St Niskayuna</Location> <SchedStart>9:00 am</SchedStart> <SchedEnd>1:00 pm</SchedEnd> <Bills>$ 131</Bills> <Coins>$ 15</Coins> <Checks>$ 00</Checks> <AmountCollected>$ 146</AmountCollected> </scCollections> <scCollections> <RingerName>Beukendall Eastern Star</RingerName> <RingDate>Dec 7 - Wed</RingDate> <Location>Price Chopper Glenville Main Dr</Location> <SchedStart>9:00 am</SchedStart> <SchedEnd>7:00 pm</SchedEnd> <Bills>$ 283</Bills> <Coins>$ 64</Coins> <Checks>$ 100</Checks> <AmountCollected>$ 447</AmountCollected> </scCollections> <scCollections> <RingerName>Beukendall Eastern Star</RingerName> <RingDate>Dec 8 - Thu</RingDate> <Location>Price Chopper Glenville Main Dr</Location> <SchedStart>9:00 am</SchedStart> <SchedEnd>7:00 pm</SchedEnd> <Bills>$ 415</Bills> <Coins>$ 38</Coins> <Checks>$ 00</Checks> <AmountCollected>$ 453</AmountCollected> </scCollections> </dataroot> AND ********************************* <?xml version='1.0' encoding='utf-8'?> <dataroot> <Totals> <ServClub>1st National bank scotia</ServClub> <TotalAmount>$ 270</TotalAmount> </Totals> <Totals> <ServClub>Advisory Board</ServClub> <TotalAmount>$ 146</TotalAmount> </Totals> <Totals> <ServClub>Beukendall Eastern Star</ServClub> <TotalAmount>$ 900</TotalAmount> </Totals> <Totals> <ServClub>Corps Band</ServClub> <TotalAmount>$ 190</TotalAmount> </Totals> <Totals> <ServClub>General Electric Volunteers</ServClub> <TotalAmount>$ 2505</TotalAmount> </Totals> </dataroot>
  5. Hi there, I've recently started to try and learn JavaScript on my own in my spare time, as it's an area of work I'd like to get into (not exactly loving my current occupation). I'm trying to learn it from a book I got and finding it very difficult! Much harder than html and css (which I've been learning for a few months as well). I'm trying to answer this question below with a 'for loop' (which is partially running), but I'm really lost as to how to answer it using a function?? Could anyone give me some advice, as it's really doing my head in! It'd be greatly appreciated indeed.... Question: " Write a function that takes a character and returns false if it is not a vowel and true if it is. This function should be used in a program to count the number of non-vowels (not just consonants) and the number of vowels in a string that the user is asked to input. E.g. JavaScript Rocks! Number of vowels: 4 Number of non-vowels: 13 " Here is my attempt so far..... <html> <body><title>Function</title></head> <body> <h1>Function</h1> <script> var sent = (prompt("Please write a short sentence of your choosing")); var vowels = 0; var nonevowels = 0; for (i=0;i<sent.length; i++) { if(sent == "a" || sent == "e" || sent == "i" || sent == "o" || sent == "u") { vowels++; } if(sent == "A" || sent == "E" || sent == "I" || sent == "O" || sent == "U") { vowels++; } else { nonevowels++; } } document.write("Numberowels = " + vowels + "\n"); document.write("Numberone vowels = " + nonevowels); </script> </body> </html>
  6. Hello all, I am coming to learn PHP with a C/C++ background and noticed something which I think is incorrect: $myfile = fopen(); retuens a handle to the file. In the explanation for fread() however it is used and the explanation is that it is the name of the file as the 1st argument. This in my opinion is an incorrect explanation, it is actually the HANDLE. The majority of the PHP syntax however is mostly clear to me. Thanks to those who put the effort, to help us new comers... Cheers Alex
  7. I Have Just Read About The performance.now() Standard,But I Felt Uncomfortable About It. Is There Any Other Way To Solve This?.
  8. I have a function that calls another function inside a "for" loop. The second function uses setInterval() to display and update a countdown clock on the web page. The user sets the time on the countdown clock in minutes, and also sets the number of times the loop will operate (how many countdown clocks). I want the code in the first function to wait until the clock reaches zero before continuing. function firstFunction(){ for(I=1; I<count; I++){ some code... secondFunction(); more code... } My one idea was to create a global variable/flag with a "while" loop with nothing inside the brackets just after calling the second function. In the second function, I would set the flat to "Y" when the timer reaches zero. But, the web page just locks up. while (flag=="N"){ }; Help would be appreciated.
  9. Please forgive me, I'm new at this and old, so the going is slow. 1. If you place multiple functions in .js file, can a functions overwrite or negate other functions? If so, is there special designation that need to be placed in .js file. I'm having trouble with functions not working on the webpage like buttons not working correctly after adding a another function. (I'm not on a live webpage - just learning) 2. Are js files exclusively for functions? Can other things be placed in a .js file besides code that start with function because I've tried other things like example below and could not get them to work in the .js file. example: document.getElementById("bark").innerHTML ="The temperature is " + toCelsius(32) + " Centigrade";​ I had to post that directly in to the body to work. This example is from the tutorial. Any help would be appreciated thanks
  10. I have an application that needs about a dozen separate unrelated and independent javascript functions to run as designed. At present, they are all in a single header (about 17,700 lines of code). All of them, except one, have less than 100 lines of code. The one exception has over 16,000 lines of code. Is there any limit to the number of javascript functions that can appear in a header? Is there a limit to the function size? Do they have to be placed in any specific order? If yes, I'm assuming that I will have to carve them out into separate included js files. If this is the case, the number and order of separate included js files will depend on the answer to these questions.
  11. Hello. I have a problem that's making me feel like an idiot. I have this function. The exact code is maybe not that important because, if I copy/paste the exact code into the program, it is working (but still appending it just in case). However, when I put it in front of the program, I get "TypeError: rad is not a function". There are other functions so I tried putting him in the same SCRIPT tags, tried to separate them, neither is working. <script>function rad(x,y){ var temp=0; if ((y==0) || ((Math.abs(x)/(Math.abs(y)+0.01))>=2)) temp=Math.abs(x); else temp=Math.abs(y)+div(Math.abs(x),2)+Math.abs(x)%2; if ((Math.abs(x/(y+.01))<2) && (y<0)) temp=temp-Math.abs(x)%2; return temp;}</script> Also, "div" is a defined function and that one is working.
  12. I'm designing a feature-rich website with object-oriented PHP and I have a performance question. My background is in C, C++ and C# (.NET) programming. Now all those are compiled whereas PHP is interpreted. The following require_once statements are at the top of each page: <?phprequire_once "_php/library/Session.php"; // Session class (session related functionality)require_once "_php/library/Databases.php"; // Databases class (database related functionality)require_once "_php/library/DatesTimes.php"; // DatesTimes class (date and time related functionality)require_once "_php/library/User.php"; // User class (user related functionality)require_once "_php/library/Page.php"; // Page class (page related functionality)require_once "_php/library/common.php"; // general functions?> // (X)HTML 5 code Now some of those files are large and have a lot of methods/functions that are rarely used but it makes sense to keep them there because of the design principles of OOP. However, where OOP shines the best is in languages such as C# where only the necessary parts of the application is loaded into memory (on the as-needed basis). My question is, will the PHP engine have to waste a lot of CPU parsing through the classes and their methods every time a page is requested even though they're not being used or is there only a performance cost when the methods are being envoked (this parsing is not necessary in C# because the code has already been compiled)? I'm just wondering if I should break down the OOP architecture into smaller units that don't make as much sense logically but do make sense performance-wise.
  13. hello w3s again... i have trouble again with a self project, and this time (like allways) i have no clue why it does this... 1. i have some files like so given in picture: ATTACHED now inside the bittorrent.php file, i have my whole site defined in functions like so: <?php/*=========================*/$mysql_host = "localhost";$mysql_user = "root";$mysql_pass = "daniel1";$mysql_db = "ss_2012";$db_details = mysql_connect($mysql_host, $mysql_user, $mysql_pass);mysql_select_db($mysql_db, $db_details)or die(mysql_error());/*=========================*/function stdhead($title = "",$css_file = ""){$stdhead_start .="<!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=iso-8859-1' /><link rel='stylesheet' type='text/css' href='styles/".$css_file.".css'/><link rel='shortcut icon' href='fav_icon.ico' /><title>".$title."</title></head><body>"; $stdhead_start .="<table class='banner_table' align='center' cellpadding='0'><tr><td><a href='index.php'><img src='styles/images/banners/banner.png' width='1000' height='140' alt='SS_2012' /></a></td></tr></table>"; $stdhead_start .="<table class='status_table' align='center'><tr><td class='status_left'>LEFT</td><td class='status_right'>RIGHT</td></tr></table>"; $stdhead_start .="<table class='menu_table' border='0' align='center'><tr><td class='navigation'><a href='index.php'>HOME</a></td><td class='navigation'><a href='browse.php'>BROWSE</a></td><td class='navigation'><a href='upload.php'>UPLOAD</a></td><td class='navigation'><a href='request.php'>REQUESTS</a></td><td class='navigation'><a href='chat.php'>CHAT</a></td><td class='navigation'><a href='forums.php'>FORUM</a></td><td class='navigation'><a href='guides.php'>GUIDES</a></td><td class='navigation'><a href='bonus.php'>BONUS</a></td><td class='navigation'><a href='rules.php'>RULES</a></td><td class='navigation'><a href='faq.php'>FAQ</a></td><td class='navigation'><a href='links.php'>LINKS</a></td><td class='navigation'><a href='support.php'>SUPPORT</a></td></tr></table>"; $stdhead_start .="<table class='main_table' align='center'><tr><td>";return $stdhead_start;}//stdhead ends... function stdfooter(){$stdfoot_start ="</td></tr></table> <table class='foot_table' align='center'> <tr> <td>Speed-Scene © 2012 -> Revision 01</td> </tr> </table> </body> </html>"; return $stdfoot_start;}//stdfooter ends... /*====================FUNCTIONS PLACE!...====================================*/ function tr($x,$y,$noesc=0) {if ($noesc) $a = $y;else { $a = htmlspecialchars($y); $a = str_replace("\n", "<br />\n", $a);}print("<tr><td class=\"heading\" valign=\"top\" align=\"right\">$x</td><td valign=\"top\" align=left>$a</td></tr>\n");} function genrelist() {$ret = array();$res = mysql_query("SELECT id, name FROM categories ORDER BY name");while ($row = mysql_fetch_array($res)) $ret[] = $row;return $ret;} function StatusBar(){echo "<table class='status_table' align='center'><tr><td class='status_left'>LEFT</td><td class='status_right'>RIGHT</td></tr></table>";}?> and when i replace the status bar place with the StatusBar() Function inside the head function, then i get this result here: http://speed-scene.c...wrong/login.php and when i have the normal text building writed inside the place, then i get the normal design as i wish it to be like this: http://speed-scene.c..._good/login.php now, what i am in a need of, is that if someone can explain me why the design is going to be screwed up with all stuff, the fonts size,the status over the banner, even when i have said to it that it should be under it... then its placing itself up there -.-'... and im calling the designs like so as a example on my login page: <?phprequire_once("include/bittorrent.php");echo stdhead("Login","1");?> This is the Login Page!... <?phpecho stdfooter();?> so now i have my final question here... what the heck am i doing wrong?... someone?... ideas?... EDIT: and no, im not trying to make a torrent tracker... just called the file bittorrent.php for that name because i was trying to follow a tutorial .. EDIT #2: Did i post the right place at all?... mean, should i post in css section instead? ...
  14. Hello W3S... what im trying to do here is to call a function that have some div's in it...and here is my code im using for this: <center><div id="content_body"><center><!--/**********************/--><div class="content_left"><?phpecho full_width_auto_begin_box("Latest News");include ("mods_content/index/news.php");echo full_width_auto_end_box();?></div><!--/**********************/--><div class="content_right"><?phpecho full_width_auto_begin_box("Stats");include ("mods_content/index/stats.php");echo full_width_auto_end_box();?></div><!--/**********************/--></center></div><div class="clear"></div></center> and as you see, then i also added a div class called clear at the end... but it still is confucing somehow... so here is my functions code below: /*Inner (Box auto_100%) Mod Function*/function full_width_auto_begin_box($caption = ""){$begin = "<div class='100_auto_box_background'><div class='100_auto_box_title'><b>".$caption."</b></div><div class='100_auto_box_content'>";return $begin;}function full_width_auto_end_box(){$end = "</div><div class='100_auto_box_footer'><a href=''>To Top</a></div></div>";return $end;}/*Inner (Box auto_100%) Mod Function*/ and below here is my .CSS...: /*CLASSES*/.clear {clear:both; /*SKAL HAVE EN START/###### DIV MED CLASS CLEAR FOR AT FOOTEREN IKKE IRITERRE FLOATSNE...*/}/*CLASSES*//*BOX auto_100% CSS*/.100_auto_box_background {width:100%;background-color: #808080;text-align:left;}.100_auto_box_title {width:auto;background-color: #616161;background-image:url(images/backgrounds/tables_titles/black_1.png);background-size:contain;text-align:left;font-size:20px;}.100_auto_box_content {padding:10px;width:auto;height:auto;background-color: #808080;text-align:left;}.100_auto_box_footer {width:auto;background-color: #616161;background-image:url(images/backgrounds/tables_titles/black_1.png);background-size:contain;text-align:center;}/*FOR THE LINK DECORATION IN THE BOX FOOTER...*/.100_auto_box_footer a:link { /*unvisited Links*/color:#990000;text-decoration:underline;}.100_auto_box_footer a:visited { /*Visited Links*/color:#990000;text-decoration:underline;}.100_auto_box_footer a:hover { /*mouse over link*/color:#990000;text-decoration:underline;}.100_auto_box_footer a:active { /*selected link*/color:#000000;}/*FOR THE LINK DECORATION IN THE BOX FOOTER...*//*FOR THE LINK DECORATION IN THE BOX CONTENT...*/.100_auto_box_content a:link { /*unvisited Links*/color:#900;/*background-color:#333333;*/border: 1px solid #990000;}.100_auto_box_content a:visited { /*Visited Links*/color:#900;}.100_auto_box_content a:hover { /*mouse over link*/color:#900;background-color:#333333;}.100_auto_box_content a:active { /*selected link*/color:#900;}/*FOR THE LINK DECORATION IN THE BOX CONTENT...*//*BOX auto_100% CSS*/ hoping someone can help me :/... Note that this is when im trying to make 2 things between each other... but when im putting it right under each item like so below: <center><div id="content_body"><center><!--/**********************/--><?phpecho begin_box("Latest News");include ("mods_content/index/news.php");echo end_box();echo "<br />";echo begin_box("Stats");include ("mods_content/index/stats.php");echo end_box();?><!--/**********************/--></center></div></center> and that is without a clear/both...ideas?...
  15. EDIT: i found out myself... just look away from this topic ..
  16. Hi, I need external manual functions file, can i download it from Internet, if it's possible please guide me the site names. Thanks in advance.
  17. Okay, I understand what it does, but I'm having troubles understanding the process of the set/getCookie functions given as examples in the w3schools tutorial.I'm a jQuery junkie trying to ramp up to serious scripting (eventually with Ajax and PHP as its becoming apparent). While the school lessons have been invaluable I notice they don't always have a comprehensive list of objects, methods, or actions that can be done. For instance in the Cookie examples, how where does 'exdays' get defined, what do escape() and unescape() do, etc. I understand parts but others seem completely unexplained. Are there any more comprehensive explanations of the cookie?Also, another example, they talk about the setTimeout and clearTimeout, but I never saw setInterval anywhere... that seems like an important thing to leave out of the school so I'm assuming there's 'gotta be a site out there where a full list of events and objects is being updated more regularly.Thanks!
  18. I created a script on a php page. The script is activated when user clicks the submit button on a form. I want to write functions on the same php page. How do I do this? MyData.php<?function getData(){$fname = _POST['fname']; $lname = _POST['lname']; //statements that tells it to write the information to file} function showData(){$price = _POST['price']; $qty = _POST['qty']; $total = $price * $qty; echo $total;}?> MyOutputPage.php<html><head><title>Sample Page</title></head><body>//I want to call the showData() function on the MyData.php page.//How do I do this? <form action=" " method="post"><input type="submit" value="Submit"/></form></body></html> Once I do this, how do I call individual functions on the page. Is there a way to add it to my page with the html like you do when linking to an external javascript script? Thank You
  • Create New...