JavaScript - What Type Of Javascript Is This?
In this code, what does the beginning "setCal ()" do, and what is it?
Its not a function, or a variable, I'm confused... Code: <script> /*Copyright 1996 - Tomer and Yehuda Shiran Feel free to "steal" this code provided that you leave this notice as is. Additional examples from the book can be found at http://www.geocities.com/SiliconValley/9000/ For more information contact Tomer or Yehuda Shiran <yshiran@iil.intel.com>*/ setCal() function getTime() { // initialize time-related variables with current time settings var now = new Date() var hour = now.getHours() var minute = now.getMinutes() now = null var ampm = "" // validate hour values and set value of ampm if (hour >= 12) { hour -= 12 ampm = "PM" } else ampm = "AM" hour = (hour == 0) ? 12 : hour // add zero digit to a one digit minute if (minute < 10) minute = "0" + minute // do not parse this number! // return time string return hour + ":" + minute + " " + ampm } function leapYear(year) { if (year % 4 == 0) // basic rule return true // is leap year /* else */ // else not needed when statement is "return" return false // is not leap year } function getDays(month, year) { // create array to hold number of days in each month var ar = new Array(12) ar[0] = 31 // January ar[1] = (leapYear(year)) ? 29 : 28 // February ar[2] = 31 // March ar[3] = 30 // April ar[4] = 31 // May ar[5] = 30 // June ar[6] = 31 // July ar[7] = 31 // August ar[8] = 30 // September ar[9] = 31 // October ar[10] = 30 // November ar[11] = 31 // December // return number of days in the specified month (parameter) return ar[month] } function getMonthName(month) { // create array to hold name of each month var ar = new Array(12) ar[0] = "January" ar[1] = "February" ar[2] = "March" ar[3] = "April" ar[4] = "May" ar[5] = "June" ar[6] = "July" ar[7] = "August" ar[8] = "September" ar[9] = "October" ar[10] = "November" ar[11] = "December" // return name of specified month (parameter) return ar[month] } function setCal() { // standard time attributes var now = new Date() var year = now.getYear() if (year < 1000) year+=1900 var month = now.getMonth() var monthName = getMonthName(month) var date = now.getDate() now = null // create instance of first day of month, and extract the day on which it occurs var firstDayInstance = new Date(year, month, 1) var firstDay = firstDayInstance.getDay() firstDayInstance = null // number of days in current month var days = getDays(month, year) // call function to draw calendar drawCal(firstDay + 1, days, date, monthName, year) } function drawCal(firstDay, lastDate, date, monthName, year) { // constant table settings var headerHeight = 50 // height of the table's header cell var border = 2 // 3D height of table's border var cellspacing = 4 // width of table's border var headerColor = "midnightblue" // color of table's header var headerSize = "+3" // size of tables header font var colWidth = 60 // width of columns in table var dayCellHeight = 25 // height of cells containing days of the week var dayColor = "darkblue" // color of font representing week days var cellHeight = 40 // height of cells representing dates in the calendar var todayColor = "red" // color specifying today's date in the calendar var timeColor = "purple" // color of font representing current time // create basic table structure var text = "" // initialize accumulative variable to empty string text += '<CENTER>' text += '<TABLE BORDER=' + border + ' CELLSPACING=' + cellspacing + '>' // table settings text += '<TH COLSPAN=7 HEIGHT=' + headerHeight + '>' // create table header cell text += '<FONT COLOR="' + headerColor + '" SIZE=' + headerSize + '>' // set font for table header text += monthName + ' ' + year text += '</FONT>' // close table header's font settings text += '</TH>' // close header cell // variables to hold constant settings var openCol = '<TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>' openCol += '<FONT COLOR="' + dayColor + '">' var closeCol = '</FONT></TD>' // create array of abbreviated day names var weekDay = new Array(7) weekDay[0] = "Sun" weekDay[1] = "Mon" weekDay[2] = "Tues" weekDay[3] = "Wed" weekDay[4] = "Thu" weekDay[5] = "Fri" weekDay[6] = "Sat" // create first row of table to set column width and specify week day text += '<TR ALIGN="center" VALIGN="center">' for (var dayNum = 0; dayNum < 7; ++dayNum) { text += openCol + weekDay[dayNum] + closeCol } text += '</TR>' // declaration and initialization of two variables to help with tables var digit = 1 var curCell = 1 for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) { text += '<TR ALIGN="right" VALIGN="top">' for (var col = 1; col <= 7; ++col) { if (digit > lastDate) break if (curCell < firstDay) { text += '<TD></TD>'; curCell++ } else { if (digit == date) { // current cell represent today's date text += '<TD HEIGHT=' + cellHeight + '>' text += '<FONT COLOR="' + todayColor + '">' text += digit text += '</FONT><BR>' text += '<FONT COLOR="' + timeColor + '" SIZE=2>' text += '<CENTER>' + getTime() + '</CENTER>' text += '</FONT>' text += '</TD>' } else text += '<TD HEIGHT=' + cellHeight + '>' + digit + '</TD>' digit++ } } text += '</TR>' } // close all basic table tags text += '</TABLE>' text += '</CENTER>' // print accumulative HTML string document.write(text) } </script> <p align="center"><font face="arial" size="-2">This free script provided by</font><br> <font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript Kit</a></font></p> Similar Tutorialsi have know that JavaScript the data types are either:Primitive (number", "string", "boolean", "undefined",null), or Non-primitive (objects). but why the return values of using typeof can be "function"? i feel this collide with the above. Okay I am looking for some good free scripts of dynamic javascript menu (I dont know how to call them properly). A type of menu where let say on the left you click on item and on the right it updates content to cliced item. Any ideas where could I find some good or how are those called?
Reply With Quote 01-24-2015, 11:31 PM #2 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,310 Thanks 82 Thanked 4,754 Times in 4,716 Posts I think you need to be more specific. Do you mean you want to do this all in one HTML page? So that the displayed content changes depending on what tab or button the user clicks on? That's not quite the same thing as what is normally called a navigation menu, where more often then not you are using the menu to get to ANOTHER html page. hello, I have a form which contains multiple inputs with type 'text' and 'radio' buttons, and i'm trying to validate all these fields using javascript. Know that the id's and names came from database. so i want to validate by type. Please anyone help me as fast as possible thank you can i write the encryption type in javascript?? i am writing like this in my javascript function, but not able to getting it work...... document.form_name.enctype ="multipart/form-data" php has the $_POST GLOBAL that contains an array of all the POST form variables. Does Javascript contain something similar built in?
hi guyz i do have a problem in passing javascript variable to <input type=hidden value=""> here's my code: <?php while ($row = mysql_fetch_array($result)) { ?> <script type="text/javascript"> function viewcodec(){ var randomValueCodec = randomString(5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'); document.getElementById('commentMarkCodeCompCodec-'+<?php echo $row['p_id'];?>).innerHTML = randomValueCodec; document.getElementById('commentMarkCodeComp-'+<?php echo $row['p_id'];?>).innerHTML = randomValueCodec; } </script> <form action="" method="post" name="postsForms"> <div class="commentBox" align="right" id="commentBox-<?php echo $row['p_id'];?>" <?php echo (($comment_num_row) ? '' :'style="display:none"')?>> <input type=text id="commentMarkname-<?php echo $row['p_id'];?>" name="commentmarkname" class="commentMarkname" size="35" maxlength="20"> <textarea class="commentMark" id="commentMark-<?php echo $row['p_id'];?>" name="commentmark" cols="60"></textarea> <input type=text id="commentMarkcode-<?php echo $row['p_id'];?>" name="commentmarkcode" class="commentMarkcode" size="35" maxlength="20"> <br clear="all" /> <span id='commentMarkCodeCompCodec-<?php echo $row['p_id'];?>'><b><script type="text/javascript">viewcodec();</script></b></span> <input type="hidden" id="commentMarkCodeComp-<?php echo $row['p_id'];?>" name="commentMarkCodeComp" value=""> <br clear="all" /> <br clear="all" /> <a id="SubmitComment" style="float:right" class="small button comment"> Comment</a> </div> </form> <?php } ?> Hi, I have an array in JavaScript. How can I GROUPBY Branch, then by Client and then by Referral Type and COUNT DISTINCT LPS # in JavaScript. Please note I need to do this client side using JavaScript. Array Data: Branch Client Referral Type LPS # 402036 402430 Psychological File Review 30 402049 402805 In-Home Assessment 10.87927 402050 402993 Chiropractic Assessment 100 402049 402805 Chiropractic File Review 10.88054 402049 402806 Chiropractic File Review 10.88055 402049 402806 Defense Medical 20 402049 402807 Chiropractic Assessment 10 402049 402807 In-Home Assessment + Form 1 10.88054 402049 402807 Physiotherapy Assessment 10 402049 402808 Attendant Care Assessment 10 402049 402808 Chiropractic Assessment 10.88041 402049 402808 In-Home Assessment 10 402049 402816 Chiropractic Assessment 10.85316 402049 402827 Neurological File Review 10.88047 402049 402827 Social Work File Review 10.88044 402050 402605 Psychological File Review 880434 402050 402661 Physician Assessment 878203 402050 402993 Physician Assessment 1000 402036 402575 Psychological File Review 50 Thanks How do you make an ios5 type notification system with javascript for your webpage?
suggestions welcome !!
I am trying to add a pulldown menu with a button to my website. I have successfully done this with a javascript I found online here to give credit: http://www.blazonry.com/javascript/js_menu.php I tried to modify the form so it will use an image file instead of the default button. To troubleshoot I took the relevant code and put into a seperate html file. This one is using the default code from the site referenced above. This is the page published online: http://www.keylimecomputerservice.com/test/default.html Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <SCRIPT LANGUAGE="JavaScript"><!-- function openURL() { // grab index number of the selected option selInd = document.theForm.aaa.selectedIndex; // get value of the selected option goURL = document.theForm.aaa.options[selInd].value; // redirect browser to the grabbed value (here a URL) top.location.href = goURL; } //--> </SCRIPT> </head> <body> <TABLE SPAN="3" BORDER=1 CELLSPACING=0 CELLPADDING=0 align="center" WIDTH="60%"> <TR> <TD WIDTH="33%"> <center><font color="black">Choose a connection</font></center><br> <form name="theForm"> <tt> <center> <select name="aaa" size="1"> <option selected value="#"> ---------- </option> <option value="/remote/connect1.exe">Connection 1</option> <option value="/remote/connect2.exe">Connection 2</option> <option value="/remote/connect3.exe">Connection 3</option> <option value="/remote/connect4.exe">Connection 4</option> <option value="/remote/connect5.exe">Connection 5</option> <option value="/remote/connect6.exe">Connection 6</option> <option value="/remote/connect7.exe">Connection 7</option> <option value="/remote/connect8.exe">Connection 8</option> </select> </center> </TD> <TD WIDTH="33%"> <input type="button" value=" GO " onClick="openURL()"> </tt> </form> </TD> <TD WIDTH="33%"> </TD> </TR> </TABLE> </body> I then tried to change the form to use an image instead of the default button. Obviously I didn't do it right. THIS ONE DOES NOT WORK. When you choose a menu item and then click the image, it just refreshes the page. Published page: http://www.keylimecomputerservice.co.../modified.html This is the modified code.: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <SCRIPT LANGUAGE="JavaScript"><!-- function openURL() { // grab index number of the selected option selInd = document.theForm.aaa.selectedIndex; // get value of the selected option goURL = document.theForm.aaa.options[selInd].value; // redirect browser to the grabbed value (here a URL) top.location.href = goURL; } //--> </SCRIPT> </head> <body> <TABLE SPAN="3" BORDER=1 CELLSPACING=0 CELLPADDING=0 align="center"> <TR> <TD WIDTH="33%"> <center><font color="black">Choose a connection</font></center><br> <form name="theForm"> <tt> <center> <select name="aaa" size="1"> <option selected value="#"> ---------- </option> <option value="/remote/connect1.exe">Connection 1</option> <option value="/remote/connect2.exe">Connection 2</option> <option value="/remote/connect3.exe">Connection 3</option> <option value="/remote/connect4.exe">Connection 4</option> <option value="/remote/connect5.exe">Connection 5</option> <option value="/remote/connect6.exe">Connection 6</option> <option value="/remote/connect7.exe">Connection 7</option> <option value="/remote/connect8.exe">Connection 8</option> </select> </center> </TD> <TD WIDTH="33%"> <input type="image" src="connectbutton.jpg" onClick="openURL()"> </tt> </form> </TD> <TD WIDTH="33%"> </TD> </TR> </TABLE> </body> Any and all help is appreciated. Runout74 I need to change input type="text" to input type="password" via JavaScript Code: <form id="login" action="#" method="post"> <input id="username-field" type="text" name="username" title="Username" onmousedown="javascript:this.value=''; javascript:this.focus();" value="Username" tabindex="1" /> <input id="password-field" type="text" name="password" title="Password" onmousedown="javascript:this.value=''; javascript:this.type='password'; javascript:this.focus();" value="Password" tabindex="2" /> <input type="submit" name="submit" value="sign in" tabindex="3" /> </form> This works in Firefox and Safari but not IE So then I tried this code Code: <script type="text/javascript"> function passit(ip){ var np=ip.cloneNode(true); np.type='password'; if(np.value!=ip.value) np.value=ip.value; ip.parentNode.replaceChild(np,ip); } </script> <form id="login" action="#" method="post"> <input id="username-field" type="text" name="username" title="Username" onmousedown="javascript:this.value=''; javascript:this.focus();" value="Username" tabindex="1" /> <input id="password-field" type="text" name="password" title="Password" onmousedown="javascript:this.value=''; passit(this.form[0]); javascript:this.focus();" value="Password" tabindex="2" /> <input type="submit" name="submit" value="sign in" tabindex="3" /> </form> This does what I need but turns the username type to password field not the password box Please can somone help! Hi there, I am having a hard time trying to understand this: The script I am using does not work if I write doctype as follows: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> But it does when removing the link: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > However when I remove the link from the doc type, in IE my selected menu is unaligned; Here is the link. Have you got an idea about why it does not work with the full doc type? Thanks a lot for having a look; This was climbing up the tree strructure, where on top and only on very top is one input of type text Now I inserted (inside tree) some inputs of type hidden , which needs to be ignored while below while operates. How to do that ? Getting nowhere with this. Code: function doit(tmpObj) { while (!tmpObj.getElementsByTagName('input')[0]) { tmpObj.style.visibility = 'hidden'; tmpObj = tmpObj.parentNode; } ... Hi, As part of a package deal I received a javascript script for redirecting a webpage. Now I already have simple redirection but wanted to see how this one did the redirection. But it starts off by defining an array with strange sets of characters. Is this hexadecimal or something ? Can I convert it into a more readable and understandable form ? var _0x46d5=["\x67\x65\x74\x54\x69\x6D\x65","\x73\x65\x74\x54\x69\x6D\x65","\x3B\x20\x65\x78\x70\x69\x72\x65\x73\ x3D","\x74\x6F\x47\x4D\x54\x53\x74\x72\x69\x6E\x67","","\x63\x6F\x6F\x6B\x69\x65","\x3D","\x3B\x20\x 70\x61\x74\x68\x3D\x2F","\x3B","\x73\x70\x6C\x69\x74","\x6C\x65\x6E\x67\x74\x68","\x73\x75\x62\x73\x 74\x72\x69\x6E\x67","\x63\x68\x61\x72\x41\x74","\x20","\x69\x6E\x64\x65\x78\x4F\x66","\x26","\x3F"," \x68\x72\x65\x66","\x6C\x6F\x63\x61\x74\x69\x6F\x6E","\x73\x6C\x69\x63\x65","\x70\x75\x73\x68","\x65 \x7A\x6D\x62\x72\x65\x64","\x4E","\x59","\x75\x73\x65\x72\x41\x67\x65\x6E\x74","\x76\x65\x6E\x64\x6F \x72","\x6F\x70\x65\x72\x61","\x74\x65\x73\x74","\x73\x75\x62\x73\x74\x72"]; function createCookie(_0x810ex2,_0x810ex3,_0x810ex4,_0x810ex5){ ... the script continues using the array elements above. Thanks for any insights. . I know very little JavaScript (I can modify a script slightly, but I can't write one), so I am asking for your help. I want to place a textarea on a web page. This textarea would have attributes to make it so that if you pressed "i", it would come out as "c", or if you pressed "]" it would appear as "=", and so on. (If you're wondering, I want to make it work like the Dvorak keyboard layout). I also would like a button to copy the text in the textarea to the clipboard. Thank you in advance for your help! Jordon Does anyone know if it it possible to automatically replace any instance of & with 'and' using javascript when someone types into a text input?
I apologize if I am posting this in the wrong section. I am looking for a code or script for a certain type of game but I can't even figure out what this type of game would be called. The game I am talking about is called "cryptopix" at tanga.com. I would really like to implement something like that on my website that members could create and participate in. If anyone can help point me in the right direction I would be forever grateful. I would assume it's a java script.
What is the most efficient type of chat to make? From what I see online most people use a database and limit the number of results they return, but I noticed that some chats, like google and facebook, for some reason are able to load the full chat and get results almost instantly. How do they do it? I would love to make a replica of a google chat and just redesign the way it looks. If anyone can help me with the javascript/php part of this, that would be great. thanks! I am restarting a thread because as a result of acting on all of the suggestions I have received the nature of the issue has changed. I am trying to create a button and add it to the DOM under IE7. The code works fine under Firefox: Code: var editButton = document.createElement("button"); editButton.name = "editCitation" + rowNum; try { editButton.type = 'button'; } catch(e) { // IE7 throws this exception alert("citTable.js: gotAddCit: unable to set type for <button name='editCitation" + rowNum + "' type=" + editButton.type); } editButton.onclick = editCitation; editButton.appendChild(document.createTextNode('Edit Citation')); td1.appendChild(editButton); I am creating a <button> rather than an <input type=button> because a <button> permits HTML in the button label. Most of my buttons support Alt keyboard shortcuts, so I want to underline the appropriate letter in the label. According to the HTML 4.01 specification, which is as close to a standard as IE7 supports, a <button> can be one of three types: submit, reset, or button, and the default is submit. Since I wish to create a <button type=button> I therefore, at least theoretically, need to be able to set the value of the type attribute. However IE7 throws an exception at that point, although, interestingly, when I interrogate the value of editButton.type in the catch it is set to button. So how do I reliably set the type of a button under IE7? I have a simple function like this: Code: function chars_remaining() { var remaining = 200 - document.getElementById("text_box").value.length; document.getElementById("number").innerHTML = 'Characters Remaining: ' + remaining; } And I call this onkeyup on the textarea. 200 chars max and what happens is when they type a character, it will still stay at 200 until they press another key. So when it will be 199, it should actually be 198. Onkeyup, onkeydown, onkeypress will all do the same thing. How can I make it so that as soon as they press a key it changes right away? Also I insert this into my database with mysql_real_escape_string, which is limited at 200 chars. When they keep typing and get to 0 remaining characters if they had any quotes, backslashes, etc. they will get added and thus some of their text will be cut off. I.e. lets say the text ended with "good luck". If they had 3 quotes in their text it might end up being "good l" instead because 3 backslashes had to be used to escape. So would the best thing to do be to count a quote, backslash, etc. as two characters instead of one. How would I do that in JS? |