JavaScript - Capturing Page Events Using Javascript
Hello
I need help regarding capturing page events(mouse click ,navigation) etc on web pages and write them into a text file (using javascript). One way is using javascript events and writing them into text file. Is there be a better way of doing this ?? Similar TutorialsI was testing a required entry form, and i'm stuck. Code: <html> <head> <script type="text/javascript"> function validate_required(field,alerttxt) { with (field) { if (value==null||value=="") { alert(alerttxt);return false; } else { return true; } } } function validate_form(thisform) { with (thisform) { if (validate_required(email,"Username must be filled out!")==false) {username.focus();return false;} } } </script> </head> <body> <form action="submit.htm" onsubmit="return validate_form(this)" method="post"> Username: <input type="text" name="username" size="20"> <input type="submit" value="Submit"> </form> </body> </html> i have this so far. i want to add a password part. i know i would take Code: Password: <input type="text" name="password" size="20"> and put it underneath the username part in the codes., but i don't know to do the rest, with the error message poping up. I am using a freebie script that changes css elements using onClick when you hit a button. I have 12 choices I want to add, and don't want 12 buttons, but rather a dropdown list. 2 button examples (and js code) is: <input onclick="changecss('li','background','url(images/list_02.jpg) no-repeat 10.2em .12em')" value="Change to BG 2" type="button" /> <input onclick="changecss('li','background','url(images/list_03.jpg) no-repeat 10.2em .12em')" value="Change to BG 3" type="button" /> How do I convert this to a SELECT list?? Thank you! Hi all, The question is hopefully relatively simple. if I have an object say Code: [ var SampleObject = function(id){ SampleObject.id = id; SampleObject.age= 22; } Is there a way to create an event that triggers every time the age member value changes? Thanks Ollie. in the attached photos you have a wheel of colors and a corresponding cascading menu. I'd like to just be able to onmouseover one of the 8 colored polygons within the wheel, have it replace the wheel with one of 8 new images depending on which polygon the mouse is over, and at the same time, light up the corresponding image on the cascading company menu group. is this possible with javascript? links to a tutorial? I've had some experience with replacing one image with another onmouseover, but not with breaking up one image into 8 parts, each with a separate image replacement. I could see how you could perform this with only 4 different colored polygons, but not 8. I've done extensive searching, but each example or explanation i come across is too different from my own, so it's ultimately no use. The problem is that I barely know anything when it comes to Javascript, but yet I'm trying to use it. I have a form on a page. This form contains 6 <select> elements, each with its own <option>Other</option> element. If something isn't listed, the user can choose "Other" and then type into a textbox which appears. I have the following code, which works great if only applied to one <select> element. Code: <select name="How did you hear about us?" id="How did you hear about us?" onchange="makeBox1()"> <option value="0" selected="selected">-- Select --</option> <option value="1">Search Engine</option> <option value="2">Referral</option> <option value="3">Trade Publication</option> <option value="4">Vendor Web Site</option> <option value="5">Your Company Website</option> <option value="6">Direct Mail</option> <option value="7">Other</option> </select> <div id = "inputBox1"></div> <script type = "text/javascript"> function makeBox1() { var a = "<input type = 'text' name = 'box1' id = 'box1' class='form popup'>" if (document.getElementById("How did you hear about us?").value==7) { document.getElementById("inputBox1").innerHTML = a; } else { document.getElementById("inputBox1").innerHTML = ""; } } </script> I've read that you have to combine onchange events, but i have no idea how to do this (i've done plenty of trial and error, trying to make every item unique, but to no avail. How would i add more scripts like the above? Hello, I have a question about the cut and paste javascript events calendar at http://www.javascriptkit.com/script/...calendar.shtml Is there any way to add links to the event description that appears in the box below the calendar? Thanks for your help. Hi I am using httpXmlRequest object to call a xml web service. In order to successfully perform a task there are couple steps need to happen. 1 you have to request for a session (cookie) 2 with the cookie, we need to authenticate with the server 3 then perform other actions snippet of my code looks something like this. Basically here i am trying to get the cookie, login and then logout once logged in. function connect() { document.myForm.elements['myTextArea'].value += "connecting to teh server.\n"; try { xhttp.open("GET",urlStr + commonInfoParam, true); xhttp.send(); xmlDoc = xhttp.responseXML; xmlDoc.onreadystatechange = function () { if(xmlDoc.readyState == 4) { var resultsTag = null; resultsTag = xmlDoc.getElementsByTagName("results"); if(resultsTag != null) { for(i=0;i<resultsTag.length;i++) { var commonTag = resultsTag[i].getElementsByTagName("common"); for(j=0;j<commonTag.length; j++) { cookie = commonTag[j].getElementsByTagName("cookie")[0].childNodes[0].nodeValue; break; } } } if(cookie != null) { document.myForm.elements['myTextArea'].value += "cookie found: " + cookie + "\n"; login(); } } }; } catch(e) { document.myForm.elements['myTextArea'].value += "Exception occurred at connect: " + e.message + "\n"; } } function login() { var loginRequestURL = "http://testconnect.com/api/xml?action=login&login=" + username+ "&password=" + password + "&session=" + cookie; try { xhttp.open("GET", loginRequestURL, true); xhttp.send(); xmlDoc = xhttp.responseXML; xmlDoc.onreadystatechange = function () { alert('in loginResponseHandler'); if(xmlDoc.readyState == 4) { try { loginStatus = xmlDoc.documentElement.childNodes[0].attributes.getNamedItem("code").nodeValue; if(loginStatus == 'ok') { alert("login is good: " + loginStatus); logout(); } else { } } catch(e) {} } }; } catch(e) { } } function logout() { alert("in logout"); try { xhttp.open("GET", logoutRequestURL + cookie, true); xhttp.send(); xmlDoc = xhttp.responseXML; xmlDoc.onreadystatechange = function () { alert("in logoutResponseHandler"); if(xmlDoc.readyState == 4) { try { status = xmlDoc.documentElement.childNodes[0].attributes.getNamedItem("code").nodeValue; if(status == 'ok') { alert(status); } } catch(e) {} } }; } catch(e) {} } so when I run my code in the browser, all my alert stages give me proper message as expected. But at the final alert, it hangs. I just could not figvure out what am i doing wrong. can any one pin point this out for me please? Thanks in advance. KM Can we have two onFocus javascriptscript events for single HTML Tag? Thank you..
without outside extensions, how does one debug javascript events on a webpage that primarily relies on unobtrusive JS events? for instance, i have a website i log into that has a "submit" button. the button itself only has this code: Code: <input type="image" class="png" tabindex="5" value="Go" src="login.png"> obviously, the only way that it can submit the form is to use javascript. and it's obviously unobtrusive in this case. consider the fact that it isn't my webpage, and i don't want to try to put random breakpoints everywhere blindly. any help!? HTML TARGET: Code: <div id="login_link" style="margin-top:-142px;margin-left:245px;height:142px;"> <img id="login_link" src="menu_button.png" /><a href="#"><img src="menu_button.png" /></a></div> </div> I'm trying to get menu_button.png to change to menu_button2.png on mouseover... I'd also like it to play a sound on click like "click.wav" I can't rename the div because it controls the slider Heres my current project table: http://bit.ly/dbwH23 I tried to put it in a span and have the span referance to the next tag but it didn't seem to work at least not in firefox. I'm going to keep lookin around but i'm not used to these types of code structure. I was thinking of Embeding a flash file inside the div instead but that might be overkill. Anyone know of a solution that might work? I am using a third party shopping cart service written in php. I don't have access to the php code so I decided to use javascript to write a cookie. What I'm trying to do is have the cookie capture the referring URL and then keep it for a day and have it follow where ever the visitor goes in the shopping cart. Then when they check out, the referring URL will populate a form field and be returned as part of the form results. This way I can track where my visitors come from. My code is below and I'm adding it to the file designated as the head section. (The files I have access to must use some form of include but I can't use php in them - just html and javascript. I've tried.) I have an alert in the code that suggests something to do as well as set the cookie. The alert comes up and the cookie is set but when you go to another page, the alert comes up again and another cookie is set. I just need to have it set once so when they fill out the order form, I'll know where they came from. This is my code and thanks for the help. Code: <SCRIPT LANGUAGE="JavaScript"> cookie_name = "dataCookie"; var referred; function getName() { if(document.cookie) { index = document.cookie.indexOf(cookie_name); if (index != -1) { namestart = (document.cookie.indexOf("=", index) + 1); nameend = document.cookie.indexOf(";", index); if (nameend == -1) {nameend = document.cookie.length;} referred = document.cookie.substring(namestart, nameend); return referred; } } } referred=getName(); if (referred == "dataCookie") {referred = "No-Referral"} function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "=") if (c_start!=-1) { c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start) if (c_end==-1) c_end=document.cookie.length return unescape(document.cookie.substring(c_start,c_end)) } } return "" } function setCookie(c_name,value,expiredays) { var exdate=new Date() exdate.setDate(exdate.getDate()+expiredays) document.cookie=c_name+ "=" + escape(value) + ((expiredays==null) ? "" : "; expires="+exdate.toGMTString()) } function checkCookie() { { var cookieEnabled=(navigator.cookieenabled)? true : false //if not IE4+ nor NS6+ if (typeof navigator.cookieenabled=="undefined" &&!cookieEnabled) { document.cookie="testcookie" cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false } if (cookieEnabled) { var todaysdate = new Date() var day = todaysdate.getDay() switch (day) { case 1: day = "Monday" break case 2: day = "Tuesday" break case 3: day = "Wednesday" break case 4: day = "Thursday" break case 5: day = "Friday" break case 6: day = "Saturday" break case 0: day = "Sunday" break } var thedate = getCookie('thedate') if (thedate != null && thedate != "") { if (day == thedate) {} else {alert('Be sure to subscribe to our newsletter.')} } else { thedate = day if (thedate!=null && thedate!="") { { cookie_name = "dataCookie"; var referred; if(document.cookie != document.cookie) {index = document.cookie.indexOf(cookie_name);} else { index = -1;} if (index == -1) { referred=document.referrer; document.cookie=cookie_name+"="+referred; } } {setCookie('thedate', thedate, 365)} alert('Be sure to subscribe to our newsletter.') } } } else {alert('Please Enable Cookies. This site uses Cookies during your visit.')} } } function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') {window.onload = func;} else {window.onload = function() {if (oldonload) {oldonload();} func(); } } } addLoadEvent(function() { checkCookie(); }); //--> </script> In the body I am reading it with a form field of Code: <SCRIPT LANGUAGE="javascript"> document.write("<FORM>") document.write("Originally Referred by:") document.write("<INPUT id='cookiealert' TYPE=text style='width:300px' VALUE=" +referred+ ">"); document.write("</FORM>") </SCRIPT> Is it possible to capture function calls? for example: alert('hello world'); is there a way to capture this function call. Why do i want to do this: 1. i need a way to test if a function exist before it is called, so i dont get undefined errors etc. 2. try/catch only works on sections of code, i need a global solutions.(can i capture functions calls on remotely loaded scripts, like google analytics etc ) Hello experts, My first question folks. I have recently joined a web based video conference which allow people to join as a guest (no need to create account). This conference's interface and function is written in javascript as an applet. To cut the long story short, is it possible to capture this applet and see the conference (without having to join the conference)? What happen at the moment is people wont be able to see the conference without join in and therefore take one slot out of 7 seats if you like. When all slots are taken people can not see the event. I was wondering if there is a way to capture this event using other javascript. I have all the scripts required to make this conference running, i know the logic of how javascript works but i dont know what is what in detail. Can anyone suggest anything? Thanks. My client has a training site that is associated with 4 different domains. If a user navigates away from one of the domains to another site (for instance www.google.com) they want to display a message and ask them if they want to leave the training site. my understanding of the window.location.href is that it will capture what is typed into the address bar until the request is submitted to the server but by then they are leaving the site. below is my code on the onbeforeunload event. conceptually: i want to capture the URL, compare the hostname and if the host name is one of the 4 domains then allow them to proceed, if it is not then as them if they want to leave the site. if they click ok allow them to move forward, if the click cancel then reload the page. I know this is considered bad design and i have expressed this but this how they want the site to behave. thanks ________________________________________________________________ [CODE] <script type="text/javascript"> function SiteCheck() { var strCurrentURL = window.location.href; var strNewHostName = strCurrentURL.split("/"); // for(i = 0; i < strNewHostName.length; i++) { alert(i + ' ' + strNewHostName[i]); } //strNewHostName[4] = "sddmtraining.org"; //test values //strNewHostName[4] == 'sddmtrain.org'; //test values //strNewHostName[4] == 'www.sddmtrain.web.org'; test values if (strNewHostName[4] == 'sddmtraining.org' || strNewHostName[4] == 'sddmtrain.org' || strNewHostName[4] == 'www.sddmtrain.web.org') ; else { var r = confirm("Are you sure you want leave the Training Site - Click Ok to Leave / Click Cancel to stay"); if (r==true) ; else { window.location.reload(window.location.href ); } } } </script> [\CODE] Codes for Dropdown menu based on radio buttons selection needed!? I need urgent help with this: I need codes for a dropdown menu that is altered by radio buttons. I want to insert the value selected from the dropdown menu into a table. Hi, I am Aditya. I am explaining below the exact scenario where I need the help: I am developing a web application in which I need to integrate a javascript/html editor on some of the web pages and then provide 'Edit' buttons on those web pages so that users can edit the content on that partciular html/jsp page (like editing in wiki pages) and then, when they add some content and click on submit button, the new content should appear on the web page with all the formatting (i.e. bold, italics, color and so on) which was applied by user when he was entering the text. Now, I need help for the below issues: 1. Please suggest me a good javascript/html editor (freely downloadable) which I can use to integrate with my web pages. 2. Once the user has entered some content using the above javascript editor, how to make that content reach the server and update the corresponding web page. I am new to web development, so may be that these questions are too simple. But, I need some help from you. Waiting for your reply, Thanks, Aditya My problem is the following. I have an editable <div>: <div class='edit' id='divContent' name='divContent' ContentEditable>some text</div> If I press 'enter' two lines are skipped. I know that if I press 'shift+enter' only one line will be skipped. If I check the unformatted code of the contenteditable div, 'enter' gives me <p> and 'shift+enter' gives me <br>, which makes sense because <p> is formatted differently than <br>. So I want to change 'enter' into 'shift+enter' I have already found something to capture and kill 'return' function killReturn() { key = event.keyCode; if (key == 13) return false; } But now for some means to replace the killed 'enter' with 'shift+enter'? Thanks a lot in advance for any advise! This is what I have: http://page-test.co.uk/js-test.html ..and it works exactly how I want it to, but I need it to work by doing these two things: (a) If you see in the change_button function, I have hard coded the 'name_can_vary' name element. I need to do it so this isn't hard coded (so it can work on any page/form). (b) I don't want to change any of the HTML, and I only want to change the code used in the change_button function (otherwise I will need to change many pages). Thanks in advance. i have a link that references: <a href="My_Video.asx">video</a>. when you click, video will open in the "windows media player" and the parent window goes blank. how can i prevent the parent window from going blank? thank you for help julio |