JavaScript - Can't Set Js Variable To A Url For Some Reason
This code snippet below was extracted from a rather large javascript. It is not written here to function alone, but it is solely to illustrate my question, Why can't a variable be read from within a function when it has been set as the text of a url address, in this case www.google.com)?
When I click on the browser HREF that calls the OnClick event, the function SwitchFN, I receive the following 2 alerts: "Ones" (variable is output as expected) "undefined" (the second variable is no longer defined within the function, however using the command alert(numtwo) in the variable definition section of my code will work as expected and the alert will be "www.google.com" Why can't the function see the variable when it is a URL? Code: I have set several default variables up in the beginning of my script: var numone = "Ones" var numtwo = "www.google.com" /// more variables set /// more functions function switchfn(nfn,nrm) { document.cookie = "mvrfile=" + numone alert(numone) alert(numtwo) } document.write('<TR><TD BGCOLOR=# ALIGN=LEFT VALIGN=top WIDTH=60 COLSPAN=2><A HREF="#" onClick="switchfn(\'' + myview + '\',\'' + mytxt + '\')">' + mytxt + '</A></TD></TR>') ; Similar TutorialsI am attempting to create a web based quote system that pops up a preview of the fencing type selected on click. but nothing works.. im frustrated with this and need a bit of guidance. hopefully someone will help here is the HTML body of the form Code: <body> <form action="" id="fenceprice" onsubmit="return false;"> <fieldset> <legend>Let's get a quote together for you!</legend> <p>How many feet of fencing do you need? <input type="number" name="length" min="1"></p> <label >Type of fence (Price/foot)</label><br> <input type="radio" name="fence" value="StockadePrivacy" onclick="calculateTotal()" /> Stockade Privacy Fence ($13.99)<br> <input type="radio" name="fence" value="OverlappingPrivacy" onclick="calculateTotal()" /> Overlapping Privacy Fence ($14.99)<br> <input type="radio" name="fence" value="ShaddowboxPrivacy" onclick="calculateTotal()" /> Shaddowbox Privacy Fence ($15.99)<br> <input type="radio" name="fence" value="3BoardHorse" onclick="calculateTotal()" /> 3 Board Horse Fence ($5.99)<br> <input type="radio" name="fence" value="4BoardHorse" onclick="calculateTotal()" /> 4 Board Horse Fence ($6.99)<br> <input type="radio" name="fence" value="4FtChain" onclick="calculateTotal()" /> 4 foot Chain Link Fence ($6.50)<br> <input type="radio" name="fence" value="6FtChain" onclick="calculateTotal()" /> 6 foot Chain Link Fence ($7.99)<br> <input type="radio" name="fence" value="4FtField" onclick="calculateTotal()" /> 4 foot Field Fence ($5.25)<br> <input type="radio" name="fence" value="6FtField" onclick="calculateTotal()" /> 6 foot Field Fence ($7.25)<br> <input type="radio" name="fence" value="4FtNoClimb" onclick="calculateTotal()" /> 4 foot Field Fence with No Climb Wire ($5.73)<br> <input type="radio" name="fence" value="4FtCross" onclick="calculateTotal()" /> 4 foot Cross Fence ($6.75)<br> <input type="radio" name="fence" value="4FtCrossWire" onclick="calculateTotal()" /> 4 foot Cross Fence with No Climb Wire ($7.25)<br> <input type="radio" name="fence" value="BarbedWire" onclick="calculateTotal()" /> 4 Strand Barbed Wire Fence ($5.00)<br> <input type="radio" name="fence" value="4FtVinyl" onclick="calculateTotal()" /> 4 foot Vinyl Fence ($15.99)<br> <input type="radio" name="fence" value="6FtVinyl" onclick="calculateTotal()" /> 6 foot Vinyl Fence ($17.99)<br> <p> <label for='includepaint' class="inlinelabel"> Include Paint($1.25/foot)</label> <input type="checkbox" id="includepaint" name='includepaint' onclick="calculateTotal()" /> </p> <p> <input type= "submit" name="submit" onclick="calculateTotal()" /> </p> <div id="totalPrice"></div> </fieldset> </form> </body> here is my js for the preview images (js.js) Code: var app = preview.module('app' , ['ui.filters']); function MainController($scope) { function Preview(type, imageSrc){ this.type = type; this.imageSrc = imageSrc; }; var fenceType = [ new Fence("StockadePrivacy" , "nicks work/single gate stockade.jpg"), new Fence("OverlappingPrivacy" , "nicks work/board over board privacy fence (3).jpg"), new Fence("ShaddowboxPrivacy" , "nicks work/shadowbox (2).jpg"), new Fence("3BoardHorse" , ""), new Fence("4BoardHorse" , "nicks work/titan (37).jpg"), new Fence("4FtChain" , ""), new Fence("6FtChain" , "nicks work/1003154_498266626917855_1385007596_n.jpg"), new Fence("4FtField" , "nicks work/wire by road.jpg"), new Fence("6FtField" , "nicks work/field wire.jpg"), new Fence("4FtNoClimb" , ""), new Fence("4FtCross" , "nicks work/cross fence black.jpg"), new Fence("4FtCrossWire" , ""), new Fence("BarbedWire" , ""), new Fence("4FtVinyl" , "nicks work/4ft vinyl.jpg"), new Fence("6FtVinyl" , "nicks work/6ft vinyl.jpg") ]; $scope.fenceType = fenceType; $scope.getCurrentFenceImage = getCurrentFenceImage; function getCurrentFence() { return_.find($scope.fenceType, { type: $scope.fenceType}) || {}; } function getCurrentFenceImage() { return getCurrentFence().imageSrc; }; } here is my code for the form calculations (formcalculations) Code: var fence_price = new Array(); fence_prices["StockadePrivacy"]=13.99; fence_prices["OverlappingPrivacy"]=14.99; fence_prices["ShaddowboxPrivacy"]=15.99; fence_prices["3BoardHorse"]=5.99; fence_prices["4BoardHorse"]=6.99; fence_prices["4FtChain"]=6.5; fence_prices["6FtChain"]=7.99; fence_prices["4FtField"]=5.25; fence_prices["6FtField"]=7.25; fence_prices["4FtNoClimb"]=5.73; fence_prices["4FtCross"]=6.75; fence_prices["4FtCrossWire"]=7.25; fence_prices["BarbedWire"]=5; fence_prices["4FtVinyl"]=15.99; fence_prices["6FtVinyl"]=17.99; function getQuantity() { //Assume form with id="theform" var theForm = document.forms["fenceprice"]; //Get a reference to the TextBox var length = theForm.elements["length"]; var howmuch =0; //If the textbox is not blank if(quantity.value!="") { howmuch = parseInt(quantity.value); } return howmuch; } function paintPrice() { var paintPrice=0; //Get a reference to the form id="fenceform" var theForm = document.forms["fenceprice"]; //Get a reference to the checkbox id="includecandles" var includePaint = theForm.elements["includepaint"]; //If they checked the box set candlePrice to 5 if(includePaint.checked==true) { paintPrice=1.25; } //finally we return the candlePrice return paintPrice; } function getFenceSizePrice() { var fenceSizePrice=0; //Get a reference to the form id="fenceform" var theForm = document.forms["fenceform"]; //Get a reference to the fence the user Chooses name=selectedCake": var selectedFence = theForm.elements["selectedfence"]; //Here since there are 4 radio buttons selectedCake.length = 4 //We loop through each radio buttons for(var i = 0; i < selectedFence.length; i++) { //if the radio button is checked if(selectedFence[i].checked) { fenceSizePrice = fence_prices[selectedFence[i].value]; break; } } //We return the fenceSizePrice return fenceSizePrice; } function getTotal() { //Here we get the total price by calling our function //Each function returns a number so by calling them we add the values they return together var fencePrice = getFenceSizePrice() * getQuantity() + paintPrice() * getQuantity(); //display the result var divobj = document.getElementById('totalPrice'); divobj.style.display='block'; divobj.innerHTML = "Total Price For Fencing $"+fencePrice; } function hideTotal() { var divobj = document.getElementById('totalPrice'); divobj.style.display='none'; } Reply With Quote 12-19-2014, 01:01 AM #2 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,311 Thanks 82 Thanked 4,754 Times in 4,716 Posts So have you used your error console? Or your JavaScript debugger? Hit the F12 key to bring up both. I recommend using the Chrome browser for this because I like its integration of the console and debugger, et. al., best. But any modern browser will do. Are you getting errors right off the bat from the error console? Are you getting errors when you try to select a fence, etc.? Tell us *WHAT* is going wrong. Don't make us re-construct your page so we can use our error console. And if you still can't figure it out, can you post the page LIVE someplace? Give us a URL to look at? Hi there, i have this simple script that replaces the scrollbar of an iframe called iFrame1 with 2 up and down arrow images, but it only works in IE, i've tried it in Chrome and Firefox... here is the code Code: <script type="text/javascript" language="javascript"> function bsh_iFrame1(step,time){hs_iFrame1=setInterval("sh_iFrame1("+step+")",time)} function esh_iFrame1(){clearInterval(hs_iFrame1)} function sh_iFrame1(step) { scrollx=iFrame1.document.body.scrollLeft scrolly=iFrame1.document.body.scrollTop scrolly=scrolly+step iFrame1.window.scroll(scrollx,scrolly) } </script> Code: </td><td align="center" valign="middle" width="31"><img src="up.png" alt="up" border=0 vspace="5" hspace="3" onMouseDown="esh_iFrame1();bsh_iFrame1(-3,2)" onMouseUp="esh_iFrame1();bsh_iFrame1(-1,20)" onMouseOver="bsh_iFrame1(-1,20)" onMouseOut="esh_iFrame1()"><br> <img src="down.png" alt="down" border=0 vspace="5" hspace="3" onMouseDown="esh_iFrame1();bsh_iFrame1(3,2)" onMouseUp="esh_iFrame1();bsh_iFrame1(1,20)" onMouseOver="bsh_iFrame1(1,20)" onMouseOut="esh_iFrame1()"> thanks in advance for any answers... Hi, I'm making a Google Map that reads info from a database and pulls Twitter usernames from it to plot points on a map. In the infowindow of these points I have some code that displays the Twitter users latest tweet. There's alot of code for this map so i'll only show you the part i'm working on: Code: function readData() { var request = GXmlHttp.create(); request.open("GET", "phpsqlinfo_result.php", true); request.onreadystatechange = function() { if (request.readyState == 4) { var xmlDoc = GXml.parse(request.responseText); // obtain the array of markers and loop through it i=[0]; markers=[0]; map.getInfoWindow().hide(); gmarkers = []; map.clearOverlays(); side_bar_html = ""; var markers = xmlDoc.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { // obtain the attribues of each marker var lat = parseFloat(markers[i].getAttribute("lat")); var lng = parseFloat(markers[i].getAttribute("lng")); var point = new GLatLng(lat,lng); var label = markers[i].getAttribute("name"); var address = markers[i].getAttribute("address"); var type = markers[i].getAttribute("type"); var html = '<' + 'script src="http://twitter.com/javascripts/blogger.js"><' + '/script><' + 'script type="text/javascript" src="http://twitter.com/statuses/user_timeline/' + label + '.json?callback=twitterCallback2&count=1"><' + '/script><br /><div id="twitter_update_list" style="list-style:none"></div>'; // create the marker var marker = createMarker(point,label,html); map.addOverlay(marker); } // put the assembled side_bar_html contents into the side_bar div document.getElementById("side_bar").innerHTML = side_bar_html; } } request.send(null); } var html is where it's all happening. I'm using the Twitter script from http://limetouch.com/article/valid-x...vascript-code/ and I have it laid out with all them ' + ' to break it up so it doesn't end the actual javascript used to create the map. I'm new to Javascript so I don't know too much. I know that this method is a really backwards way of doing it, but it works for Firefox. I'm able to retrieve the users latest tweet when I click on their map marker. What I want to know is why it doesn't work in any other browser? I've tried IE7+8, Google Chrome, Opera, and Safari and no tweet displays. Sub-question: While a tweet does display in Firefox, the infowindow doesn't resize with the dynamic content. Any way to fix that? hi all. im having problems with this ajax script i wrote: Code: function admin_adduser() { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } user = document.getElementById('user_user').value; user = user.replace(/^\s+|\s+$/g, '');// trim whitespace //check if name is unique unique = 'false'; var params = "?user=" + escape(user); var url="_check_username.php"; url=url+params; ajaxedInner = ""; xmlHttp.open("GET",url,true); xmlHttp.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT"); xmlHttp.onreadystatechange=stateChanged; xmlHttp.send(null); xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4) { if (xmlHttp.status == 200) { unique = xmlHttp.responseText.replace(/^\s+|\s+$/g, ''); //trims all whitespace! //alert(unique); } } } if(unique == 'true') { //alert("working: " + unique); password = document.getElementById('user_password').value; var params = "?user_user=" + escape(user) + "&user_password=" + escape(password); var url="_admin_add_user.php"; url=url+params; ajaxedInner = "users"; xmlHttp.open("GET",url,true); xmlHttp.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT"); xmlHttp.onreadystatechange=stateChanged; xmlHttp.send(null); document.getElementById('user_password').value = ""; document.getElementById('user_user').value = ""; } else { alert('Please select a unique name for the new staff member\nadd a middle initial maybe?'); } } if i alert(unique) it tells me 'true' (string) but still doesnt go into the create part of the script, i just get the alert('Please select a unique name for the new staff member\nadd a middle initial maybe?'); any ideas? i know im probably missing something basic but its really annoying lol btw - the php for the _check_username.php is simple: PHP Code: <?php if(!isset($_SESSION)) {session_start();} if($_SESSION['authorised'] != true) { exit; } include 'config.php'; include 'opendb.php'; $user = $_REQUEST['user']; $query = "SELECT user FROM user WHERE user='$user'"; echo $query; $result = mysql_query($query) or die('false'); $row = mysql_fetch_array($result, MYSQL_ASSOC); if($row) { echo 'false'; } else { echo 'true'; } mysql_free_result($result); ?> I have the following function: Code: function sonKare(sayac, oteki) { var vertical, horizontal = hangiYataySira(sayac, oteki), j, k, l, m, united, tekRakam, actualV = [], actualH = [], numaralar = [1, 2, 3, 4, 5, 6, 7, 8, 9], olmayanlar = []; if(ilkSefer === true) { vertical = hangiDikeySira(rakamlar.length); ilkSefer = false; } else { vertical = hangiDikeySira(rakamlar.length - 1); } for(j = 0; j <= vertical.length - 1; j ++ ) { if(rakamlar[vertical[j]] !== undefined) actualV.push(rakamlar[vertical[j]]); } for(k = 0; k <= horizontal.length - 1; k ++ ) { if(rakamlar[horizontal[k]] !== undefined) actualH.push(rakamlar[horizontal[k]]); } united = actualV.concat(actualH); //---- Olmayan rakamları bulan kısım ------------ outer: for(l = 0; l <= numaralar.length - 1; l++) { for(m = 0; m <= united.length - 1; m++) { if(numaralar[l] === united[m]) continue outer; if(m === united.length - 1 && numaralar[l] !== united[m]) olmayanlar.push(numaralar[l]); } } //---------------------------------------------- if(olmayanlar.length > 1 || olmayanlar.length === 0) { rakamlar = []; document.form1.buton.click(); // THIS LINE DOES NOT WORK SECOND TIME } else { $("_" + oteki + "_" + sayac).value = olmayanlar[0]; rakamlar.push(olmayanlar[0]); sayac++; if(sayac === 10) return; else sonKare(sayac, oteki); //CALLS ITSELF } } This is a recursive function. As stated above there is a line which does not work for the second time. What I mean is, it works perfect for the first time and after function calls itself, it doesn't work. Javascript does execute the line above it but just disregards that document.form1.buton.click(); line. I use Firebug for debugging and I checked it many times, when that expression needs to be executed for the second time, JavaScript just ignores it and immediately goes at the end of the function... I just can't figure out why JS does such a thing? p.s: Don't bother about weird variable names, they are not in English but in Turkish which is my native language I am trying to fix some datetime strings so I can convert form values into date objects so I can compare the dates in my validation process. the date time strings look like - 7/21/2011 8:00am for some reason the am is not being replaced by " am" . here's the function Code: function ampm(str){ str.replace(/am/gi," am") str.replace(/pm/gi," pm") return str } for example the result of ampm("8:00am") is 8:00am and not 8:00 am .. it seems so simple. Hi all. Can someone please help me make this code accurate so it counts the correct number of characters? when u click on the box, it should display 0. when u type in the box, it should count up by 1. when u click on the box, and u delete a character or characters, it subtracts that many code: Code: <form method="POST"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td width="100%"> <textarea onkeyDown="count_it(this)" rows="12" name="charcount" cols="60" wrap="virtual"></textarea> </td> </tr> <tr> <td width="100%"><div align="right"><p> <input type="text" name="displaycount" size="20"></p> </div></td> </tr> </table> </form> <script language="JavaScript"> function count_it(what){ formcontent=what.form.charcount.value what.form.displaycount.value=formcontent.length } </script> I started on the following page (part of an asp.net solution), but the damned thing keeps reloading. Anyone able to spot the problem? Cheers! 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"> <head><title> Untitled Page </title></head> <body> <form name="form1" method="post" action="jstest3.aspx" id="form1"> <div> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEwMjYxNzg2NjFkZMc95XPGgLBVJLhpE9SpA+WIaf+s" /> </div> <div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwKUmIGgCgLs0bLrBgKM54rGBm+z7+T68pYhg8H9O6b/Ex0HpZ0A" /> </div> <div> <input name="TextBox1" type="text" id="TextBox1" /> <input type="submit" name="Button1" value="Button" id="Button1" /> <script language="javascript" type="text/javascript"> if (parent != null) { tb = parent.document.getElementById("TextBox"); tbLocal = document.getElementById('TextBox1'); if (tb != null) tbLocal.value = tb.value; btn = document.getElementById('Button1'); if (btn != null) btn.click(); } </script> </div> </form> </body> </html> Here is the link in question. I have created a small page with the isolated problem on it. http://frontendaudio.com/v/vspfiles/...pt_tester.html the javascript file that is referenced basically only does one thing. It searches for "> >" and then alerts us whether or not it's on the page. --- It pulls the innerHTML of the entire document --- the searches it - and indexes the string. I echoed the string out to a text area so you could see the string "> >" is clearly there after the word microphones in the link tag... </a> > < etc.. Any thoughts on how I can detect this string somehow? Thanks. Here is the code inside the javascript file. Code: var myStringDiscuss = 'microphones</a> >'; myStringDiscuss = myStringDiscuss.replace(/~/g,""); // unmunge function discussDetection(){ var str = document.getElementsByTagName('html')[0].innerHTML; str = str.toLowerCase(); // to make case insensitive var category_string = str.indexOf(myStringDiscuss); if (category_string == -1) { alert("not on this page"); } else { alert("IS on the page"); } } window.onload= discussDetection; Hi, I have a programing problem that have been around for ages. I have search on google using several expressions and words and after hours of digging i'm still unable to do it. I would like to get a value from a HTML page hosted remotely with an inconstant value. Then define this value and name as a javascript variable and apply or show in my page. Thanks for all the help P.S. Is there any way to make a domain lookup in javascript? I mean a user enters a domain and the script converts to an ip and shows to the user. If not thanks, probably it can only be done in the server side... I don't know how I should do ? Quote: <html> <head> <script type="text/javascript"> function add(a,b){ y=a+b return y } var aaa = add(one,two) //one needs to get somehow get the value of yil, in this case 10 var one = function reas(){i=10;if(i<10){yil = 15}; else{yil = 10; yil = one;}; var two = 20; document.write(y) </script> </head> </html> also why doesn't this work? Quote: <html> <head> <script type="text/javascript"> function adder(a,b){ var k=a+b; return k } var hes=adder(5,kol); kol=40; alert(hes); </script> </head> </html> you cannot have variables in callback functions? Hi! I have a javascript in the head of the document which has a variable named "ref2" ... ref2 is already working as I can see its value working in another function. I need to send this variable as the value of a hidden field in the form which is in the body of the document. This is my JavaScript Code: Code: function WriteContactFormStatement1 () { var ContactFormValue = ref2; document.write('<input type="hidden" name="UReferrersName" value="' + ContactFormValue + '" />'); } var WriteContactFormStatement = WriteContactFormStatement1 (); And at the end of my form, before the submit button, I have the following code: Code: <!-- START -- Javascript to print the statement for UReferrersName --> <script language="JavaScript" type="text/JavaScript"> //WriteContactFormStatement(); document.write (WriteContactFormStatement); </script> <!-- End -- Javascript to print the statement for UReferrersName --> When I execute the form, it doesn't work the way it should, plus, gives me a word "undefined" next to the "Submit" button ..... Please help !... - Xeirus. Hello I have a php page in which I declared a js variable... right at the top of the page... <script type="text/javascript"> var tester = 0; </script> Later in the page I test this variable... <script type="text/javascript"> if (tester==1){ do some stuff!! } </script> But I keep getting an error variable _tester undefined Am I missing something obvious... I am new to js... but this seems really straightforward Hello I have a piece of javascrip that refreshes the page: ---------- Code: <script type="text/javascript"> <!-- Begin function reFresh() { location.reload(true) } /* Set the number below to the amount of delay, in milliseconds, you want between page reloads: 1 minute = 60000 milliseconds. 2 minutes = 120000 milliseconds 5 minutes = 300000 milliseconds*/ window.setInterval("reFresh()",20000); // End --> </script> -------- I am new to javascript and wanted to use an html options menu in order to be able to choose the refresh interval: Code: <SELECT NAME="refreshtime"> <OPTION VALUE="60000">1 min</option> <OPTION VALUE="120000">2 min</option> <OPTION VALUE="180000">3 min</option> <OPTION VALUE="240000">4 min</option> </SELECT> I know that I have to pass a variable to the function. I have tried several variations but none have worked. I have mostly received a "done with errors" warning. Any help would be appreciated. Thanks Zam This might be a stupid question, but is there any memory usage difference between var variable1, variable2; and var variable1; var variable2;? I'm learning how to use faster code hence the question.
Hello everybody I have a problem with Java Script damned I want to add the values of several variables in one variable and then use this variable, which contains the values of variables You can see the following example HTML Code PHP Code: <input type="text" name="txt1" /> <br/>age <input type="text" name="txt2" /> <br/><br/> <input type="button" name="submits" value="send"/> Javascript Code PHP Code: field = document.getElementsByName('txt1')[0]; field2 = document.getElementsByName('txt2')[0]; submit = document.getElementsByName('submits')[0]; data = 'data=' + field.value + '&data2=' + field2.value + '&submits=' + submit.value; document.getElementsByName('submits')[0].onclick = function(){ alert(data); } After executing this code I find that the variables are not displayed values As in the following picture I want to know what the cause of this problem ? If I manually write out "2/22/2012 4:00 PM" in TargetDate, I get the correct result for what I want to do (a countdown). But I want the countdown to always be the current day at 4pm. So I tried the code below thats commented, but it is not working. New to javascript, still reading the books, just hoping for some guidance on this. Code: Next Update: <script language="JavaScript"> var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() TargetDate = "2/22/2012 4:00 PM"; //TargetDate = "document.write(month + "/" + day + "/" + year) + 4:00PM"; BackColor = "white"; ForeColor = "red"; CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = "%%H%% H, %%M%% M, %%S%% S"; FinishMessage = "Forecasts posted"; </script> <script language="JavaScript" src="countdown.js"></script> Hi, I want to write some javascript code that uses arrays, I have a list of arrays named array1, array2, array3 etc. I want to perform a function on each of these arrays. I wanted to have a variable for the number after array so this is what I have: <code> var array1 = new Array ("1","2","3","4","5"); var array2 = new Array ("5","6","7","8","9"); for (var i=1; i<=2;i++){ document.writeln(("array"+i)[1]); } </code> the problem is it gives me the letters in the string array instead of the array values. How do I get javascript to treat ("array"+i) as array1? Can anyone tell me of how to take or assign a javascript variable into php.
I have a form created in Dreamweaver that uses the following code to validate the form: Code: function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_validateForm() { //v4.0 var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]); if (val) { nm=val.name; if ((val=val.value)!="") { if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n'; } else if (test!='R') { num = parseFloat(val); if (isNaN(val)) errors+='- '+nm+' must contain a number.\n'; if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); min=test.substring(8,p); max=test.substring(p+1); if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; } } if (errors) alert('The following error(s) occurred:\n'+errors); document.MM_returnValue = (errors == ''); } In the form: Code: onsubmit="MM_validateForm('FirstName','','R','LastName','','R','Address1','','R','HomePhone','','R','email','' ,'RisEmail');return document.MM_returnValue"> I have a second form that I want to submit after the first form is submitted and am using the following: Code: function SubmitForm(){ document.paypal.submit(); } My question: I don't know javascript. Is there a variable I can add to the function MM_validateForm() so that if the first form does not validate, the second form will not be sent? Thanks in advance for any help. |