JavaScript - Need Help With Security Questions
Hi, I am currently having a problem with my code. It is pointing at a logical error somewhere as neither the error console in FireFox nor Firebug can detect any errors. The problem is getting the alert box to pop up when the user types in invalid letters or numbers for their respective functions. I guess it could be the Unicode coding for Internet Explorer or Mozilla, or maybe the validation is not getting called from the option list....Anyway here's my code so far:
<script type="text/javascript"> /* <![CDATA[ */ function validateAlphabetic(keyPressEvent) { if (navigator.appName == "Microsoft Internet Explorer") var enteredKey = keyPressEvent.keyCode; else if (navigator.appName == "Netscape") var enteredKey = keyPressEvent.charCode; var enteredChar = String.fromCharCode(enteredKey); var retValue = true; try { if (!/\D/.test(enteredChar) && !/\W/.test(enteredChar)) throw "You did not enter an alphabetic value."; } catch(inputError) { window.alert("You can only enter letters into this field."); retValue = false; } finally { return retValue; } } function validateNumeric(keyPressEvent) { if (navigator.appName == "Microsoft Internet Explorer") var enteredKey = keyPressEvent.keyCode; else if (navigator.appName == "Netscape") var enteredKey = keyPressEvent.charCode; var enteredChar = String.fromCharCode(enteredKey); var retValue = true; try { if (!/\d/.test(enteredChar) && !/\W/.test(enteredChar)) throw "You did not enter a numeric value."; } catch(inputError) { window.alert("You can only enter numbers into this field."); retValue = false; } finally { return retValue; } } /* ]]> */ </script> </head> <body> <h1>Challenge Questions</h1> <form action="" enctype="application/x-www-form-urlencoded"> <select> <option value="maiden" onkeypress="return validateAlphabetic(event)">What is your mother's maiden name</option> <option value="pet" onkeypress="return validateAlphabetic(event)">What is the name of your favorite pet?</option> <option value="city" onkeypress="return validateAlphabetic(event)">What city were your born in?</option> <option value="security" onkeypress="return validateNumeric(event)">What is your social security number?</option> <option value="siblings" onkeypress="return validateNumeric(event)">How many siblings do you have?</option> </select><br /> <input type="text" size="25" /> </form> </body> Reply With Quote Similar TutorialsOk, just wanted to throw this out there to see if it is worth regexing a text field for user input. Since JS is client side and the script I am using is not accessing the server for anything, do I need to regex the input text field of my script? Is there any way a cracker can use this for evil? I'm working on an html form that will be launched from within another application, but every time it launches the form none of the JS coding works because of the stupid IE security. If I launch the form from outside the application I just have to select "allow blocked content" from that stupid information bar that says "to help protect your security IE has restricted the webpage from running scripts...." I added the application site to our trusted sites and basically turned off security for that zone but it still doesn't work. Obviously there is a way to run JS without allowing the content, but I don't do enough coding to know how that is done. Can someone help me out please? I need the JS to run automatically without that information bar appearing at all. My shoutbox is constantly getting hacked the JavaScript code is below. I suspect they are exploiting the same origin policy. The hackers are using administrator's usernames and spamming lots of offensive messages into the database. Any help would be much appreciated, thank you. Code: /***************************/ //@Author: Adrian "yEnS" Mato Gondelle & Ivan Guardado Castro //@website: www.yensdesign.com //@email: yensamg@gmail.com //@license: Feel free to use it, but keep this credits please! /***************************/ $(document).ready(function(){ //global vars var inputUser = $("#nick"); var inputMessage = $("#message"); var loading = $("#loading"); var messageList = $(".content > ul"); //functions function updateShoutbox(){ //just for the fade effect messageList.hide(); loading.fadeIn(); //send the post to shoutbox.php $.ajax({ type: "POST", url: "shoutbox.php", data: "action=update", complete: function(data){ loading.fadeOut(); messageList.html(data.responseText); messageList.fadeIn(2000); } }); } //check if all fields are filled function checkForm(){ if(inputUser.attr("value") && inputMessage.attr("value")) return true; else return false; } //Load for the first time the shoutbox data updateShoutbox(); //on submit event $("#form").submit(function(){ if(checkForm()){ var nick = inputUser.attr("value"); var message = inputMessage.attr("value"); //we deactivate submit button while sending $("#send").attr({ disabled:true, value:"Sending..." }); $("#send").blur(); //send the post to shoutbox.php $.ajax({ type: "POST", url: "shoutbox.php", data: "action=insert&nick=" + nick + "&message=" + message, complete: function(data){ messageList.html(data.responseText); updateShoutbox(); //reactivate the send button $("#send").attr({ disabled:false, value:"Shout it!" }); } }); } else alert("Please fill all fields!"); //we prevent the refresh of the page after submitting the form return false; }); }); I have written a little bit of javascript which displays a popup div. The essence of the idea is simple, and works like this: In the javascript: Code: function popup(markup) { var div = document.createElement("div"); div.innerHTML = markup; document.body.appendChild(div); } And in the PHP: PHP Code: $markup = "<h3>Help</h3><p>You clicked on help, so here it is.</p>"; echo '<a href="javascript:popup('.htmlentities($markup, ENT_QUOTES).');">help</a>'; Of course, there's a whole load more code (e.g. I have a mechanism for displaying the pop-up near the mouse and for allowing the user to close the pop-up, etc, etc, etc), but that is irrelevant to my question. Note also that $markup can contain anything I want - e.g. it could contain a form. Note also that the server populates $markup with predictable content - it is NOT populated by the user. Are there any security risks inherent in the code as I have posted it? (i.e. barring the fact that $markup could be used for code injection, but I have accounted for that and mitigated against it). a simple NO YOU CAN'T or a BUY A TEXTBOOK & READ IT will probably answer my query.. what i want to do is to analyse a load of share bulletin boards, from a webpage on my home pc. i'd hoped to do it by putting the bb page in an iframe and parsing the iframe's innerHTML. but this is barred by javascript. i'm a bit cheesed off having found that out only after doing the hard work of writing the parsing-code.. (i had pasted a sample bulletin board source code into the iframe, so it was all local..) but i read something about JSON.. which might outflank the security. i'd like to know: can i get an example of how this might be done? how much of a learning curve is JSON. can i fix it up on this machine? thanks for any help.. I have a webpage in which my users complete a form in order to get through to page 2. I cannot use PHP to check as it must be on-the-fly checking. My idea was like the following: PHP Code: <script type="text/javascript"> function check(x) { if (x == 1) { document.write('<IMG SRC="img/'+x+'.jpg">'); } if (x == 2) { document.write('<IMG SRC="img/'+x+'.jpg">'); } if (x == 3) { document.write('<IMG SRC="img/'+x+'.jpg">'); } if (x == 4) { document.write('<IMG SRC="img/'+x+'.jpg">'); } } </script> And for the images to actually be PHP files that check further details of the user and insert details to DB. Then when the user clicks the next button it will check to see if all 4 users have loaded under that users details. However, I would much prefer it if I could use more PHP as I'm a Javascript n00b. Preferably I would like to use PHP to create unique keys for the images so that once I have obfuscated the javascript code the user will not figure out how to cheat the system even if they manage to reverse engineer the code. Is it possible to use PHP within javascript? E.g. PHP Code: <?php $pic = "picture.jpg"; ?> <script> function something(){ document.write('<IMG SRC="img/$pic">'); } </script> Or is this not at all possible? Edit: I know how much simpler that first script could have been, was just trying to simplify from my double as messy full script which will probably confuse you even more!!! FireFox is throwing a DOM security error. And i don't really know why. i've used toDataURL() before, and it's never done this. Hopefully i can get this little app fixed, so that i can use it on my TabletPC for taking notes in class. The line of code that is throwing this error is: Code: var Note = document.getElementById("SketchPage").toDataURL(); here's the full error from the Error Console: Error: uncaught exception: [Exception... "Security error" code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" location: "file:///C:/SketchBook-Dev/SketchBook.js Line: 236"] here is the JS file: Code: var PenSize = "3"; var PenShape = "Circle"; var PenColor = "Black"; var LoadFile = ""; var UIstatus = "visible"; var CurrentNote = 0; var BGcolor = "#C7C1A3"; var DataPath = "\Data\\"; var ImageExtension = ".img"; var FileList = []; var SystemPath; var UIstatus = "visible"; var Server = "localhost"; var NxtNote = new Image(); document.onkeyup = ToggleUI; function Init() { // Get the System Path GetSystemPath("SketchBook.html"); // Load All Filenames of the DataPath directory into an array GetFileList(SystemPath + DataPath, FileList); //Load the first Note onto the canvas // if there are no notes in the directory, don't try to load anything if(FileList.length > 0) { var Source = LoadFromDisk(FileList[CurrentNote]); NxtNote.src = Source; // Load the image data onto the canvas var canvas = document.getElementById('SketchPage').getContext('2d'); canvas.drawImage(NxtNote , 0, 0); } } function HideOptions() { document.getElementById("Options").style.visibility = "hidden"; } function ToggleUI(e) { var KeyID = (window.event) ? event.keyCode : e.keyCode; var KeyValue = 18; // Use a key to hide the toolbars so that most of the screen is used for the UI if(KeyID == KeyValue) { if(UIstatus == "visible") { UIstatus = "hidden"; document.getElementById("UI").style.visibility = "hidden"; return; } if(UIstatus == "hidden") { UIstatus = "visible"; document.getElementById("UI").style.visibility = "visible"; } } } function ShowOptions() { document.getElementById("Options").style.visibility = "visible"; } function UpdatePenSize() { PenSize = document.getElementById('GetPenSize').value; } function UpdatePenShape() { PenShape = document.getElementById('GetPenShape').value; } function UpdatePenColor() { PenColor = document.getElementById('GetPenColor').value; } function Draw(element, event) { document.addEventListener("mousemove", PenHandler, true); document.addEventListener("mouseup", upHandler, true); event.stopPropagation(); event.preventDefault(); function PenHandler(event) { var x = event.clientX; var y = event.clientY; // mouse event goes here var canvas = document.getElementById("SketchPage"); var ctx = canvas.getContext("2d"); if (PenShape ="Circle") { // This draws a circle ctx.fillStyle = PenColor; ctx.beginPath(); ctx.arc(x, y, PenSize, 0, Math.PI*2, true); ctx.closePath(); ctx.fill(); } event.stopPropagation(); } function upHandler(event) { document.removeEventListener("mouseup", upHandler, true); document.removeEventListener("mousemove", PenHandler, true); event.stopPropagation(); } } function SaveNote() { // Get the current file name var FileName = SystemPath + DataPath + CurrentNote + ImageExtension; // Convert the Canvas Data into a Base64 encoded PNG image var Note = document.getElementById("SketchPage").toDataURL(); // Write the PNG file to the disk SaveToDisk(FileName, Note); } function NextNote(Direction) { if(Direction == "up") { // Display the previoius note CurrentNote--; // Make sure you don't incrimnet to a non-existant note if(CurrentNote <= 0) { CurrentNote = FileList.length; } var Source = LoadFromDisk(FileList[CurrentNote]); NxtNote.src = Source; // Load the image data onto the canvas // Clear the Pre-existing Canvas Data First ClearSketch(); var canvas = document.getElementById('SketchPage').getContext('2d'); canvas.drawImage(NxtNote, 0, 0); return; } if(Direction == "down") { //Display the Next note CurrentNote++; // Make sure you don't incrimnet to a non-existant note if(CurrentNote > FileList.length) { CurrentNote = 0; } var Source = LoadFromDisk(FileList[CurrentNote]); NxtNote.src = Source; // Load the image data onto the canvas // Clear the Pre-existing Canvas Data First ClearSketch(); var canvas = document.getElementById('SketchPage').getContext('2d'); canvas.drawImage(NxtNote, 0, 0); return; } } function DeleteNote() { // Delete The current note DeleteFile(SystemPath + DataPath + FileList[CurrentNote]); // Reload the Directory List // Clear the FileList Array FileList = []; GetFileList(SystemPath + DataPath, FileList); // Load The Previous Note // Display the previoius note CurrentNote--; // Make sure you don't incrimnet to a non-existant note if(CurrentNote <= 0) { CurrentNote = FileList.length; } var Source = LoadFromDisk(FileList[CurrentNote]); NxtNote.src = Source; // Load the image data onto the canvas var canvas = document.getElementById("SketchPage"); var context = canvas.getContext("2d"); canvas.drawImage(NxtNote, 0, 0); return; } function AddNote() { // Add a note to the notebook and at the end of the File List // **** Later this function should be modified to be an INSERT function rather than just an add // Just incase the user needs to go back an edit and add more things to their notebook CurrentNote++; // Add the new Note File name to the end of the FileList Array FileList.push(CurrentNote + ImageExtension); // Clear the Canvas ClearSketch(); // Write a blank image file to the Data directory so that we have the actual file there var FileName = SystemPath + DataPath + CurrentNote + ImageExtension; var Note = document.getElementById("SketchPage").toDataURL(); } function ClearSketch() { // Clear the contents of the Canvas //Draw a rectangle that covers the canvas var canvas = document.getElementById("SketchPage"); var ctx = canvas.getContext("2d"); ctx.fillStyle = BGcolor; ctx.fillRect (0, 0, canvas.width, canvas.height); } function Crypt(method) { // This function will Encrypt or Decrypt All the NoteData if(method == "encrypt") { return; } if(method == "decrypt") { return; } } function Archive(method) { // This function will Restore or Backup all NoteData to a network resource if(method == "restore") { return; } if(method == "backup") { return; } } // ******************** These are the XPCOM Functions ************************ function GetSystemPath(ApplicationName) { // This function should Detect the system directory of the app // and return that string as the SystemPath variable // You must supply the filename of the HTML file that it is being called from // I suppose later i could add the code to detect the HTML's actual file name // It's on the ToDo List... var GetSysPath = self.location; GetSysPath = GetSysPath + ""; Get = GetSysPath.replace("file:///" , ""); Get = Get.replace(/\//g , "\\"); Get = Get.replace(ApplicationName, ""); SystemPath = Get; return SystemPath; } function DeleteFile(FileName) { // Delete a local file netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var aFile = Components.classes["@mozilla.org/file/local;1"].createInstance(); if (aFile instanceof Components.interfaces.nsILocalFile) { aFile.initWithPath(FileName); aFile.remove(false); } } function GetFileList(Directory, FileList) { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var _nsILocalFile = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); // initialize path to work with _nsILocalFile.initWithPath(Directory); // get file interface implemenation // this means that an XPCOM Class can implement multiple interface var lv_oFile = _nsILocalFile.QueryInterface(Components.interfaces.nsIFile); var lv_oEntries = lv_oFile.directoryEntries; while(lv_oEntries.hasMoreElements()) { var lv_cFile = lv_oEntries.getNext() .QueryInterface(Components.interfaces.nsIFile).path; FileList.push(lv_cFile); } } function SaveToDisk(filepath, content) { try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch (e) { alert("Permission to save file was denied."); } var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath( filepath ); if ( file.exists() == false ) { file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 ); } var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"] .createInstance( Components.interfaces.nsIFileOutputStream ); outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 ); var output = content; var result = outputStream.write( output, output.length ); outputStream.close(); } function LoadFromDisk(filePath) { if(window.Components) try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(filePath); if (!file.exists()) return(null); var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream); inputStream.init(file, 0x01, 00004, null); var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream); sInputStream.init(inputStream); return(sInputStream.read(sInputStream.available())); } catch(e) { //alert("Exception while attempting to load\n\n" + e); return(false); } return(null); } and the HTML UI code: Code: <html><head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <title>Sketch Book v1.0</title> <script src="SketchBook.js" type="text/javascript"></script> <script src="JSxpcom.js" language="text/javascript"></script> </head> <body onLoad="Init();"> <div id="SketchPageView"> <canvas id="SketchPage" width="480" height="640" style="background: #C7C1A3; position: absolute; top: 0px; left: 0px;" onmousedown="Draw(this, event);"></canvas> </div> <div id="Options" style="position: absolute; visibility: hidden; top: 100px; left: 50px;"> <table cellwidth="100" border="0" cellpadding="0" cellspacing="0" height="50"> <tbody><tr><td><img src="./Image/TL-black.PNG" height="19" width="19"></td><td bgcolor="#bce0f8"><center><b>Options</b></center><img src="./Image/delete.png" style="position:absolute; top: 2px; left: 150px; height: 18; width: 18;" onClick="HideOptions();"></td><td><img src="./Image/TR-black.PNG" height="19" width="19"></td></tr> <tr><td bgcolor="#bce0f8"></td> <td bgcolor="#bce0f8"> <div style="border: 1px solid black;"> <table> <tbody><tr> <td><center>Pen Size</center></td><td><center>Color</center></td> </tr> <tr> <td> <select id="GetPenSize" onchange="UpdatePenSize();"> <option value="1">1 px</option> <option value="2">2 px</option> <option value="3">3 px</option> <option value="4">4 px</option> <option value="5">5 px</option> </select> </td> <td> <select id="GetPenColor" onchange="UpdatePenColor();"> <option value="Black">Black</option> <option value="White">White</option> <option value="Red">Red</option> <option value="Blue">Blue</option> <option value="Green">Green</option> <option value="Brown">Brown</option> </select> </td> </tr> <tr> <td><input value="Restore" onclick="RestoreData();" type="button"></td><td><input value="Backup" onclick="BackupData();" type="button"></td> </tr> <tr> <td><input value="Encrypt" onclick="EncryptData();" type="button"></td><td><input value="DeCrypt" onclick="DecryptData();" type="button"></td> </tr> </tbody></table> </div> </td> <td bgcolor="#bce0f8"></td></tr> <tr><td><img src="./Image/BL-black.PNG" height="19" width="19"></td> <td bgcolor="#bce0f8"></td><td align="right"><img src="./Image/BR-black.PNG" height="19" width="19"></td></tr> </tbody></table> </div> <table id="UI" style="position: absolute; top: 0px; left: 412px; visibility: visible;" border="0" cellpadding="0" cellspacing="0" width="40"> <tbody><tr><td><img src="./Image/TL-black.PNG" height="19" width="19"></td><td bgcolor="#bce0f8"></td><td><img src="./Image/TR-black.PNG" height="19" width="19"></td></tr> <tr><td bgcolor="#bce0f8"></td> <td bgcolor="#bce0f8" height="600"> <img src="./Image/up.png" style="width: 30px; height: 30px;" alt="up" onclick="NextNote('up');"><br><br><br><br> <img src="./Image/plus.png" style="width: 30px; height: 30px;" alt="add" onclick="AddNote();"><br><br><br><br> <img src="./Image/save.png" style="width: 30px; height: 30px;" alt="save" onclick="SaveNote();"><br><br><br><br> <img src="./Image/clear.png" style="width: 30px; height: 30px;" alt="clear" onclick="ClearSketch();"><br><br><br><br> <img src="./Image/delete.png" style="width: 30px; height: 30px;" alt="delete" onclick="DeleteNote();"><br><br><br><br> <img src="./Image/gear.png" style="width: 30px; height: 30px;" alt="options" onclick="ShowOptions();"><br><br> <img src="./Image/down.png" style="width: 30px; height: 30px;" alt="down" onclick="NextNote('down');"> </td> <td bgcolor="#bce0f8"></td> </tr> <tr><td><img src="./Image/BL-black.PNG" height="19" width="19"></td> <td bgcolor="#bce0f8"></td> <td align="right"><img src="./Image/BR-black.PNG" height="19" width="19"></td></tr> </tbody></table> </body></html> 1. I am in the midst of making a website and doing a few things but am thinking of adding a log in section for members can i put a password directly on a video file? or do i have to do it to the page? 2. Also looking for a good provider to upload my site to, what does everything suggest for this? Thanks JavaScript functions must be called: A. from the server B. implicitly C. explicitly D. A and C, but not B. E. None of the above. JavaScript commands written outside of a function will be executed: A. by the server. B. implicitly. C. explicitly. D. never, they are ignored. E. None of the above. The best loop for iterating through an array is A. Enhanced For loop B. While C. Do Until D. Do While. E. None of the Above. JavaScript Arrays are always passed to functions? A. By Reference. B. By Value. C. Globally. D. As a string. E. None of the Above. The best way to execute JavaScript code when you first bring up a page is: A. onload event B. JavaScript code outside of any function. C. onstart event. D. All of the above. E. None of the Above. Write a JavaScript function to handle a callback: Assume the following input fields: <input type="text" id="lastName" name="lastName" /> <input type="text" id="firstName" name="firstName" /> <input type="text" id="phone" name="phone" /> <input type="text" id="email" name="email" /> A callback function will receive a pipe delimited string from the server as such: Last-name|first-name|phone#|email Example: Doe|Jane|415-555-1212|jane.doe@gmail.com The callback function is: function customer_Callback ( content ) { // use the split method to convert content to an array. // use document.getElementById() to get each of the above input fields. // populate from the array. } ----------------------------------------- I am having serious trouble with these problems, I beseech you! There will be a special prize to whoever answers correctly all these questions first. Thanks! Hi again, I have 2 new questions for you all! 1.) *RESOLVED* 2.) So in this form: Code: <form name="form" action="email.php" method="post"> <div id="dynamicInput"> <br> <input type="checkbox" name="1" /><input type="text" name="i[]"> </div> <input type="button" value="Add another text input" onClick="addInput('dynamicInput');"> <br> <input name="email" type="text"> <br /> A12098 <input name="verify" type="text"> <input name="submit" type="submit"> </form> I have a button that will add a form element to the form. In this case, it adds a checkbox and a text box. The name on the checkbox goes up from 1-30 (thats the max amount of fields that can be added) and the text box has a name of i[]. Is it possible for the user to click on the checkbox and the corresponding text box (the one next to the checkbox) will be disabled so editing is stopped? Then they could un-click it and it would be editable again. Thanks in advance! I am newbie in javascript. While being studying it I have not understood some concepts well. JS is prototype-based language, as in Java it has one main prototype Object, also there are some other widely used object, like Array, RegEx, String ...... . So I can access and inherit from this objects/prototypes. So the questions is where do this object (declarations) are stored ? They are also allocated in memory ? Or when JS sees that there is declaration of some object is present i script it reads from file or whatever ? When I am using Function with key word new, what happens. As far as function is also object, it has field prototype and when calling this function with new it returns object of prototype type ? Am I right ? So if I haven't specified prototype it will returns object of Object type ? How does javascript knows about real type of variable. For example when I use regexp, it has method exec. I can call it on every variable. But I guest if variable doesn't have this field it returns undefined ? So the question is how does JS determine what real type of variable is ? Where this information is stored ? Closure in JS. I don't understand this concept well. I think of it like reference count in Java (used or been used by Garbage Collector). If we have a least one reference to variable it will still exist and it doesn't matter where it was declared. So making getter method inside another func makes it exists in memory. If I am wrong please give good explanation of this. Does JS runs in its own virtual machine like Java ? Or browser plays this role. I guess if it has GC, since one process cannot access address space of another process it should be something like virtual machine which controls memory allocation. I would be very grateful for help. Thx in advance. Reply With Quote 01-21-2015, 10:44 AM #2 Dormilich View Profile View Forum Posts Senior Coder Join Date Jan 2010 Location Behind the Wall Posts 3,532 Thanks 13 Thanked 372 Times in 368 Posts Questions About Javascript - JavaScript | Dream.In.Code I'm researching a possible web project. The project will allow users to create and run JS online, similar to JSFiddle, Construct 2 and GameSalad. At this stage I'm just looking to gather general information. So my first question is, just how big of a project would that be? what web technologies would be needed? Would Node.Js be needed? or would PHP be ok for the backend? Thanks for any advice. Ok, so I have a couple of questions about JavaScript that I would like answered by the programming gurus on this forum, please. Firstly, I have an idea for an online text-based role-playing game (games like GangsterParadise, etc.), and I am wondering, is it possible (or advisable?) to create the site using nothing but HTML, CSS and JavaScript? Can it be done, and if so, are there any downsides to doing this? I have heard using strictly JavaScript as a programming language on its own, on a site where members will have their own password-protected accounts, should not be done, as there are serious security flaws - is this true, and if so, why? Secondly, most JS programmers on the forum have probably digested and been through hundreds and hundreds of books on the subject since beginning to learn JavaScript - in your opinion, what are the best books to get hold of, for a relative beginner to JavaScript? What book makes the language easy to understand, and doesn't have you scratching your head to make sense of what it is saying? Thanks a lot in advance for the help, it's much appreciated. I am not understanding something here with this: http://www.w3schools.com/jquery/jquery_ajax.asp Code: <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("div").load('test1.txt'); }); }); </script> </head> <body> <div><h2>Let AJAX change this text</h2></div> <button>Change Content</button> </body> </html> When you click on the button, AJAX changes the text : Code: Let AJAX change this text to: Code: AJAX is not a programming language. It is just a technique for creating better and more interactive web applications. My question is, where is this text above located since it's not in the code? Also, if I wish to change the text mentioned, how can I do so please? 1. I want to make form with 2 select filds that one of them will be disabled if in the first the use choose a specific option i wrote it in this way (but its not work) how I fix it? Code: <script type="text/javascript"> function itay() { if (document.some1.one.value="x") document.some1.two.disabled=true if (document.some1.one.value="y") document.some1.two.disabled=false } </script> </head> <body bgcolor="#FFFFFF"> <form name="some1"> <table> <tr> <td> <select id="one" onclick="itay()"> <option value="x">x</option> <option value="y">y</option> </select> </td> <td> <select id="two"> <option value="a">a</option> <option value="b">b</option> </select> </td> </tr> </table> </form> 2. I want that after u fill the form and press submit u will see a txtarea with all the options u selected (for confirm that you chose the right things) and then press submit agien and get all the things u saw in the txtarea to a Email. (Hope u understand ) so how I do it? Hey everyone, I have a survey that I have been developing (with the help of people from this forum among others) that is nearing completion but still has a couple things to be worked out using JavaScript. For reference, here is a link to the survey: http://wri.eas.cornell.edu/weed_survey_site/index2.html Here is one issue that I'm having and I would appreciate any help: 1. on line 111, the label, id and value for each input needs to increase by one (i.e <label for='ValidCheckbox_01'><input type = 'checkbox' name = 'ValidCheckbox2' id= 'ValidCheckbox_01' value= '1'>" + i + "</label>, <label for='ValidCheckbox_02'><input type = 'checkbox' name = 'ValidCheckbox2' id= 'ValidCheckbox_02' value= '2'>" + i + "</label>, etc.) for each additional label. Lately I've been doing some modding for a game called Minecraft which requires some programming in Java. I've been doing a lot of research but because I can't think of a simplified version of my questions it's hard to get any results from Google. So I'm hoping someone could answer these for me. If you can't, I would even appreciate being pointed in the right direction or led to some reading material that would answer these questions for me. 1) How can I add the value of a variable onto the name of another variable. For instance, I have this line of code Code: EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(Item.ingotIron)); and this variable that will always be a number Code: private int numberA; I would like to add the value of numberA onto entityitem. So if numberA was 1 entityitem would become entityitem1. 2) What is the best variable type to store values such as Item.coal, which is an object within the game? Would a String type suffice? 3) Using the same code above: Code: EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(Item.ingotIron)); How could I use a variable's value where Item.ingotIron is? I tried some different things but the compiler threw "ItemStack doesn't exist" or some error along those lines at me. For instance if variableA's value is Item.coal, how could I use that variables value where Item.ingotIron is. Code: EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(variableA)); I appreciate your time and help on this issue and anything you can provide will be greatly appreciated. Hi All I have a xml string located in a hidden textbox that i need to parse how do i get it into a xml object I thought nievly i could xmlDoc = document.getElementById("XML").value alert(xmlDoc.getElementsByTagName("SupplMets")[0]); document.write("<table border='1'>"); but obviously i need to do some more work to get it into an xml object ...any ideas the end goal here is to get the data in the xml into a table here is what the xml string looks like <SupplMets TumorSupplementalId="272341"><SupplMet TumorSupplMetsId="109130" SiteOfMetastasis="C020" DateOfMetastasis="20010101" MetastasisIdType="" MetastasisEliminated="" MetastasisSD="02-003710" /></SupplMets> Hey everyone. I am very new at JavaScript and I need some help. I want to have a section on my home page where a person can choose a bike by clicking on a couple of arrows on the right and left ends of the bike. I want something similar to this type of program. http://qlpros.com/ I don't want a border around the bike. I have been looking for a couple hours now and I haven't found anything. Any help would be much appreciated!! My other question is how to transfer javascript to an external style sheet in dreamweaver. Thanks!! I know that global variables are properties of the window object... so does that mean that local variables are properties of the function they belong to? And does that mean that functions are methods of the window object and that nested functions are methods of the function they belong to?
|