JavaScript - Need Some Help With Multi Forms Anyone ?
I have a problem with some forms and utilizing the proper code to make them work.
Need some help if anyone out there has some working knowledge could help let me now, anyone ?? Eric I will post the code and the problem if someone would chim in thanks Similar TutorialsI'm using the autofill forms plugin for firefox which can be found he https://addons.mozilla.org/en-US/firefox/addon/4775 I use it to automatically fill various web forms, duh. But I would like certain values to be chosend randomly from a list I create. I contacted the developer and he said the add on probably does not need a new feature because there is a 'dynamic tags' function to fill certain forms with dynamic values (e.g. the current time or date). He has given over the project to another developer and told me I probably would find a solution in a good javascript programming forum. So here I am! Can anyone help me with this? Basically, I just need a javascript code which chooses on item from an array randomly, I guess? I'm not a programmer myself, so any help would be greatly (!) appreciated. Thanks a lot in advance for any further guidance! Note: Here are sample dynamic tags from the plugin: <datetime> new Date().toLocaleString() <useragent> navigator.userAgent <langcode> navigator.language <resolution> screen.width+'x'+screen.height <clipboard> this.getClipboardText() Hi there, I have a couple of scripts which both do exactly what I want, but when I try use them both at the same time only one of them will work, could you tell me if i need to change anything in them to get them both to work at the same time or if im missing something really simple? Thanks Script 1 Code: <script type="text/javascript"> var imgPaths = ['pic1.jpg', 'pic2.jpg', 'pic3.jpg', 'pic4.jpg', 'pic5.jpg']; //preload the images var imgObjs = new Array; for(var i=0; i < imgPaths.length; i=i+1) { imgObjs[i] = new Image(); imgObjs[i].src = imgPaths[i]; } function togglePic(num) { if(currPic == 0 || currPic != num) { document.getElementById("image").src = imgObjs[num].src; currPic = num; } else { document.getElementById("image").src = imgObjs[0].src; currPic = 0; } } //load the default image window.onload=function() { document.getElementById("image").src = imgObjs[0].src; currPic = 0; //flag storing current pic number } </script> Script 2 Code: <script type="text/javascript"> window.onload=function () { setStyles(); }; function setStyles() { ids = new Array ('style1','style2','style3','style4'); for (i=0;i<ids.length;i++) { document.getElementById(ids[i]).className=''; document.getElementById(ids[i]).onclick=function() { return Cngclass(this); } } } function Cngclass(obj){ var currObj; for (i=0;i<ids.length;i++) { currObj = document.getElementById(ids[i]); if (obj.id == currObj.id) { currObj.className=(currObj.className=='')?'selected':''; } else { currObj.className=''; } } return false; } </script> 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> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title></title> </head> <body> <div id="style"> <div id="styleimage"> <img src="" id="image" width="610" height="229" /> </div> <div id="stylenav"> <ul> <li id="style1"><a href="#" onclick="togglePic(1); return false">style 1</a></li> <li id="style2"><a href="#" onclick="togglePic(2); return false">style 2</a></li> <li id="style3"><a href="#" onclick="togglePic(3); return false">style 3</a></li> <li id="style4"><a href="#" onclick="togglePic(4); return false">style 4</a></li> </ul> </div> </div> </body> </html> Hi i am working on a website project.. in which i have like.. for the menu.. i have a horizontal menu.. with three tabs for eg... Home , about us, contact us and.. when i click on the Home tab, i need a horizontal submenu with four or five links.. say for eg : menu1,menu2,menu3,menu4,menu4 and menu5 and when i click on menu1 i need a vertical menu on click of of menu1. so i need two horizontal menu and one vertical menu. i have attached a sample image of my menu. please have a look. Can i do this in javascript.. I need to do this using html , css or jquery.. How do i ... Please help me Hey guys! I've been searching for a multi-answer script for a 'sort of' quiz I'm making (it's not really a quiz, but I figure it's a similar concept). Example of what I want: Please Select which recipe you'd like: [checkbox1] Chocolate Brownies [checkbox2] Chocolate Chip Cookies [checkbox3] Strawberry Cake [checkbox4] Apple Pie |Submit| If they choose only Chocolate Brownies, then it'll take them to a page with just the brownie recipe, but if they choose Chocolate Brownies and Chocolate Chip Cookies it should take them to a second page I'll make with both recipes on it, etc. I know it's a lot of pages based on how many possible selections, but that's as far as my knowledge goes on how to do this. Any help would be SO appreciated! Thanks, Shia EDIT: I'd like the new information to appear in a new window for easy printing. Hello, I would like to add multi-language support on the website. So far i have the following code which enables a drop down menu. I would rather prefer a flags instead of a drop down menu. Please help. Thank you very much. PHP Code: <div id="google_translate_element" class="right"></div> <script> function googleTranslateElementInit() { new google.translate.TranslateElement({ pageLanguage: 'en', includedLanguages: 'en,fr,de,it,es', gaTrack: true, gaId: 'UA-28770952-1', layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL }, 'google_translate_element'); } </script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script> ok before i ask my question, please dont tell me to use php...i have my reasons for not doing so...and also, i would like to avoid cookies and ajax....that being said, lets see if you guys can help me out.... ive got a home page with a section where i have links....now, all those links actually go to the same page called services.html ....my problem is this....depending on what link they clicked, the page will display different information...and i cant for the life of me figure out out how to find out which link they clicked from the home page while in services.html....is there a way in my home page to create a variable that is usable on all pages that the person navigates to within my website? like a kind of global or something?? also, is there already a document object that tells me their history of what links they clicked....what im trying to do is contingent on knowing what link they clicked on the home page....basically, services.html has the same links as the home page; however, when i click each one, the innerHTML is changed to display the correect info...i just want to make it so that the home page tells services.html which link was clicked....or if thats not possible, maybe when i click one of the links on the home page, it takes me to services.html and activates one of services.html's links since it has the same links as the home page, except it has them working. now lets also get a little creative...i dont know much javascript, but i do know you can create a new window and hide it...if i create a new window, will it be accessible from another page? because i can put variables in that window maybe or even use the name of the window as a holder...im thinking outside the box here but please help me out...im new to javascript hiya guys im just trying to get some javascript working that will display on one html page multiple ticking digital clocks representing the accurate time of a host of differents countrys. i currently have managed to get a ticking clock on the page using +++++++++++++++++++++++++ var thetime=new Date(); var nhours=thetime.getHours(); var nmins=thetime.getMinutes(); var nsecn=thetime.getSeconds(); ++++++++++++++++++++++++++++++++ i now need to get other clocks on same page but with the live ticking time from other countrys. i tried for hours searching sites but could not find a solution i understood. i did however add simply add ++++++++++++++++++++ var nhours=thetime.getHours() +7; +++++++++++++++++++ the plus 7 i added was intended to add 7 hours to the clock then i could use this method for all the clocks and it did work it did change the time but there was a problem hong kong is about 8 hours ahead of the uk when its 8pm here its 2am there and if i use this method and i add 6 hours to the getHours variable it then makes the time 26hours rather than 3am here is my code i hope you can be of some help ++++++++++++++++++++++++++++++++++++++++++++++ <html> <HEAD> <TITLE>JavaScript Clock</TITLE> <SCRIPT language="JavaScript"> <!-- function ukclock() { var thetime=new Date(); //var mins=new Date(); //var secn=new Date(); var nhours=thetime.getHours(); //the line below same as above except the +num can be used to add hours to the clock //var nhours=thetime.getHours() +6; var nmins=thetime.getMinutes(); var nsecn=thetime.getSeconds(); var AorP=" "; if (nhours>=12) AorP="P.M."; else AorP="A.M."; if (nhours>=13) nhours-=12; if (nhours==0) nhours=12; if (nsecn<10) nsecn="0"+nsecn; if (nmins<10) nmins="0"+nmins; document.clockform.clockspot.value=nhours+": "+nmins+": "+nsecn+" "+AorP; setTimeout('ukclock()',1000); } //--> </SCRIPT> </head> <BODY onload="ukclock()"> <FORM name="clockform"> Current Time in UK: <INPUT TYPE="text" name="clockspot" size="15"> <br /> </FORM> </body> ++++++++++++++++++++++++++++++++++++++++++++++ Hey everyone, I need some help with a function. I'm using ajax to grab a response from a PHP page, on success, the ajax sets a variable. After the line that calls the ajax function is the line the returns the variable (a global variable). Problem is, because the variable is returned right after the ajax function is fired, it doesn't give the ajax enough time to set the variable. The work around I've thought about would be using the ajax function as a variable, and returning that variable in the initial return line. Could anyone either help me with a better solution, or tell me what I'm doing wrong? Here's some code for reference: The function that will return the response I'm trying to collect: Code: function lt_ajaxGet(hash) { var params = "hash=" + escape(encodeURI(hash)); makePOSTRequest('hash.php?get', params); return ajax_response; } The ajax code: Code: if(http_request.status == 200){ ajax_response = http_request.responseText; } hi i am writing a code which needs multi event that's not my problem but it is about mouse event my html is like this Code: <form> d:<input type='text' name='dlink' id='dlink' onkeypress='a()'><br /> m:<input type='text' name='mlink' id='mlink'> </form> i want to perform any changes on dlink to mlink for example i'm using onkeypress so if a user used mouse [right click and then paste] it not works any event like onmouseover or onfocus or ... do not solve my problem i found out that IE has onpaste but other browser not so help me what should i do? Is there any way to have a multiline text string in javascript? For example strname="line one of string line two of string"; I get an error that the string is not terminated. The reason I want to do this is from the following code: Code: <textarea name="comments" id="comments" cols="90" rows="8" ></textarea> <?php if (isset($_REQUEST["registered"])) { $end_of_line=chr(10); $carriage_return=chr(13); $step1=str_replace($carriage_return,"",$comments); $step2=str_replace($end_of_line,"<br>",$step1); echo "<script type='text/javascript'>\n"; echo "intermediate='",$step2,"';\n"; echo "comment_value=",'intermediate.replace(/<br>/g,"\n")',";\n"; echo "document.getElementById('comments').value=comment_value;</script>\n"; }?> I an getting the value to set a textarea to from the server. It may have newline characters. If there is a way to have a multiline string, then I could skip all the steps and just echo one javascriopt command. Can this be done? CraigRS I was wondering, could you have more than one username and password for the Username and Password II script? and if so, could you tell me how?
Hello, I need your help. I'd like to structure and build an array like the below.: Code: var provinces = [ ['Ontario','ON'], ['Quebec','QC'], ['British Columbia','BC'], ['Saskatchewan','SK'] ]; then, id like to compare the value (x) against my array ie. Code: var x = 'Ontario' if (x matches the first value in the array 'provinces') { then let x = ON } How do you write something like this in javascript? Much thanks and appreciation for all your help, Cheers, Jay Hello Im after a very specific layout for my dropdown menu. Basically 3 menu boxes listed vertically in a table and then an iframe underneath. When a user selects an option in box 1 , i would like a specific list of options to be displayed in box 2 . The options shown in box 2 must be dependent on box 1 i.e. as the box 1 selection changes , so do the box 2 options. Same thing applies with box 3 - when the user changes box 2 , i would like a specific list of options displayed in box 3. Then when a selection is made in box 3 , i want a certain page to load in an iframe below the 3 boxes. If you could also populate each box with some sample data so i can replace it to fit my site as needed by myself :-) So in a nutshell:- User Clicks Box 1 --> Specific Options Appear In Box 2 User Clicks Box 2 --> Specific Options Appear In Box 3 User Makes A Choice In Box 3 --> Specific Page Loads In Iframe Below (Already Got This Bit Figured Out) Help much appreciated on this. I eagerly await a response :-) Hi, I have a question about an oop/class style form of javascript programming. I have stripped the code down to the basic minimum. The problem is I have created two instances of the same class and have entered data into those classes. But as you will see the two separate instances of the class appear to share the same data. How do I get my class structure working so separate instances will retain their separate data? Here is the code: Index.html Code: <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <script type="text/javascript" src="test.js"></script> <script type="text/javascript"> debugger; // Do this because a page resart seems to keep old data function SetGlobals() { var ui; var el; // Arr00 ui = document.getElementById("Arr00"); el = arr0.arrayGet(0); ui.innerHTML = el.m_String; // Arr01 ui = document.getElementById("Arr01"); el = arr0.arrayGet(1); ui.innerHTML = el.m_String; // Arr10 ui = document.getElementById("Arr10"); el = arr1.arrayGet(0); ui.innerHTML = el.m_String; // Arr11 ui = document.getElementById("Arr11"); el = arr1.arrayGet(1); ui.innerHTML = el.m_String; } function MyOnLoad() { SetGlobals(); } </script> </head> <body onload="MyOnLoad()" style="width:100%; height: 100%; padding: 0 0 0 0; margin: 0 0 0 0; overflow: hidden; background:#000000"> <div id="divScreen" style="display: block; width:100%; height="100%"> <div id="divMenu" style='float: left; background:#00FF00; border-color: #000000; border-width: 1px;'> <table> <tr> <td> Array 0/String 0: <label id="Arr00"></label> </td> </tr> <tr> <td> Array 0/String 1: <label id="Arr01"></label> </td> </tr> <tr> <td> Array 1/String 0: <label id="Arr10"></label> </td> </tr> <tr> <td> Array 1/String 1: <label id="Arr11"></label> </td> </tr> </table> </div> <div id="divMain" style='height: 100%; background:#0000FF; margin-left: 250px; border-color: #000000; border-width: 1px;'> </div> </div> </body> </html> Test.js Code: var BaseARR = function() { _arr = []; // new Array(); // Public functions that can access private members this.Add = function(arg) { var i, addAt; if(arg==null || (addAt = FindEnterPos(arg))<0) return false; // since adding and not deleting anything, nothing of value will be returned _arr.splice(addAt, 0, arg); return true; }; // This finds the entry position for in FindEnterPos = function(arg) { return (_arr.length + 1); }; this.arrayGet = function(i) { return ((_arr != null && i >= 0 && i < _arr.length) ? _arr[i] : null); }; }; var stringId = function(id, str) { // public has a this. , privates have just var this.m_Id = id; // int this.m_String = str; // string }; // This so allow statics var stringIdARR = function() { BaseARR.call(this); }; Anyone have a script that has multi timers that will loop; Sort of like the ones used in reverse auctions. First timer 1:24:59:59 (days/h/m/s) Second timer 1:00:00 (h/m/s) Third timer 1:59 (m/s) Forth timer 59 (s) I have one now that I found here and makes no sense to me; PHP Code: <!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" xml:lang="en" lang="en"> <head> <title></title> <font size="-4"><font face="bold"> <script language="JavaScript" type="text/javascript"> /*<![CDATA[*/ function zxctElsByClass(zxccls,zxcp,zxctag) { var zxcexa=zxccls.indexOf('=='); zxccls=zxccls.replace(' ==','').replace(/ss/g,' '); var zxcclss=zxccls.split(' '); zxcp=zxcp||document; zxcp=typeof(zxcp)=='object'?zxcp:document.getElementById(zxcp); zxctag=zxctag||'*'; var zxcels=zxcp.getElementsByTagName(zxctag),zxcary=[]; for (var zxc0=0;zxc0<zxcels.length;zxc0++){ for (var zxc0a=0;zxc0a<zxcclss.length;zxc0a++){ var zxcreg=new RegExp('\\b'+(zxcexa<0?zxcclss[zxc0a]:zxccls)+'\\b'); if ((zxcclss[zxc0a])&&zxcreg.test(zxcels[zxc0].className)){ zxcary.push(zxcels[zxc0]); break; } } } return zxcary; } function Upgrading(hrs,mins,secs){ hrs=zxctElsByClass(hrs); mins=zxctElsByClass(mins); secs=zxctElsByClass(secs); for (var zxc0=0;zxc0<hrs.length;zxc0++){ hrs[zxc0].oop=new UpgradingOOP(hrs[zxc0],mins[zxc0],secs[zxc0]) } } function UpgradingOOP(hrs,mins,secs){ this.time=[hrs,mins,secs]; this.cng(); } UpgradingOOP.prototype.cng=function(){ var hours=this.time[0].firstChild.data; var mins=this.time[1].firstChild.data; var secs=this.time[2].firstChild.data; secs=secs-1; if (secs<0){ mins=mins-1; secs=59; } if (mins<0){ hours=hours-1; mins=59; secs=59; } if (hours<0) { hours=0; mins=0; secs=0; this.time[0].firstChild.data=hours; this.time[1].firstChild.data=mins; this.time[2].firstChild.data=secs; window.location = document.URL; } if (mins>=0) { mins=mins-1; mins=mins+1; if (secs<10) secs="0"+secs; if (mins<10) mins="0"+mins; this.time[0].firstChild.data=hours; this.time[1].firstChild.data=mins; this.time[2].firstChild.data=secs; this.to=setTimeout(function(zxcoop){return function(){zxcoop.cng();}}(this),1000); } } /*]]>*/ </script></head> <table align=\"left\" width=\"50\" height=\"50\" border=\"0\" bgcolor=\"ltblue\"> <tr> <td><label class='uHours' >1</label>: <label class='uMins'>1</label>: <label class='uSecs'>1</label></td> <td><label class='uHours' >1</label>: <label class='uMins'>1</label>: <label class='uSecs'>1</label></td> <td><label class='uHours'>1</label>: <label class='uMins'>1</label>: <label class='uSecs'>1</label></td> </tr> </table> <br /> <table align=\"left\" width=\"50\" height=\"50\" border=\"0\" bgcolor=\"ltblue\"> <tr> <td><label class='uHours' >1</label>: <label class='uMins'>1</label>: <label class='uSecs'>1</label></td> <td><label class='uHours' >1</label>: <label class='uMins'>1</label>: <label class='uSecs'>1</label></td> <td><label class='uHours'>1</label>: <label class='uMins'>1</label>: <label class='uSecs'>1</label></td> </tr> </table> <script type="text/javascript">Upgrading('uHours','uMins','uSecs');</script> </font></font> </body> </html> I have two known methods of creating a javascript array: 1) Double brackets such as: Code: var animation_JD = [[]]; 2) Create and array then create an array inside each array element manually which is the most common method as far as I know. The problem is that the second method requires the array be be defined in size and I require a 2D array, 3D array and 4D array. Using the second method uses far to much memory to be plausible, unless there is a way to make arrays smaller by defining parts of them as integers only? Otherwise for the 1st method I described I don't know how to loop through all elements of the array such as: Code: for(group in animation_JD){ } So does anyone have another way of creating arrays, defining an array as integers only(ideally not every part of the array) to save memory, or a way to loop through arrays created in the first method? Thanks! Hey very quick question how could I do this? Basicly I have this html code. Code: <div id="editor"> <div id="tools"></div> </div> Now my javascript mods the editor by using the 'editor' id how can I use the variable for the 'editor' to look inside itself for the id 'tools', a bit like this and I know this doesn't work as I tried it but how could I do this. Code: var editor = document.getElementById('editor'), tools = editor.getElementById('tools'); // Basicly it will have the editor as the root so // if tools is also somewhere else on the page it // wont pick it up, id's will never be 2 the same // but just in-case there is lol. Short version: I'm having trouble with "moving subarrays" in a multidimensional associative array. Long version: (Yes, I know that there's technically no such thing as a js associative array and that I'm actually using a generic object.) This is one of those annoying questions for which significant code can't be shown. I'm fetching a JSON object from PHP and parsing it as multi-dimensional associative array that comes out with this "structure": Code: obj[regions][variables][years] = value; My presentation logic works fine for that. Year data is presented for each variable, and variables are grouped by region. For reference, if needed, the display is tabular and similar to this: Code: Regions | Variables | 2003 | 2004 | 2005 ========================================= | measure1 | abcd | efgh | ijkl ================================= county1 | measure2 | mnop | qrst | uvwx ================================= | measure3 | yzab | cdef | ghij ========================================= | measure1 | abcd | efgh | ijkl ================================= county2 | measure2 | mnop | qrst | uvwx ================================= | measure3 | yzab | cdef | ghij ========================================= | measure1 | abcd | efgh | ijkl ================================= county3 | measure2 | mnop | qrst | uvwx ================================= | measure3 | yzab | cdef | ghij ========================================= | measure1 | abcd | efgh | ijkl ================================= county4 | measure2 | mnop | qrst | uvwx ================================= | measure3 | yzab | cdef | ghij ========================================= My problem comes from trying to allow the option to reorganize the grouping - that is, turning it into regions grouped by variable. The display logic can handle it, but I can't get the array handling code right. The desired secondary structure is Code: obj[variable][region][year] = value; Some things I've tried: Code: /* obj is in the format of obj[region][variable][year] = value */ data_arr = new Array(); for (var region in obj) { for (var variable in obj[region]) { for (var year in obj[region][variable]) { /* fail one */ data_arr[variable][region][year] = obj[region][variable][year]; /* data_arr[variable] is undefined */ /* fail two */ y = obj[region][variable][year]; y_arr = new Array(); y_arr[year] = y; r_arr = new Array(); r_arr[region] = y_arr; data_arr[variable] = r_arr; /* only the values from the last iteration are displayed */ /* fail three */ y = obj[region][variable][year]; y_arr = new Array(); y_arr[year].push(y); r_arr = new Array(); r_arr[region].push(y_arr); data_arr[variable].push(r_arr); /* y_arr[year] is undefined */ } } } And then other permutations of those three. I could run through it easy if not needing the textual index, but that's actually part of my display data, so it has to stay. Can anyone help me with what I'm overlooking? |