JavaScript - Syntax For Creating A Variable And Using It Immediately?
Code:
var x = "blahblah".indexOf("blahblah"); if (x !== -1){ // do something with x alert("Present"); } else { alert("Not present"); } Is there some syntax/code structure that allows something like this: Code: if ( (var x = "blahblah".indexOf("blahblah")) !== -1){ // do something with x alert("Present"); } else { alert("Not present"); } Similar TutorialsHii guys, I'm new here. I'm currently an employee at Boston Financial Data Services and I need some help coding a MS Sharepoint page (or separate HTML page,) with HTML, CSS, and Javascript all in one. I've been working with another on trying to get a lightbox to work with my sharepoint page for quite some time and we came across a snag. I want to use this Javascript here in either my Sharepoint content web part or in a separate HTML page (but neither code seem to work with it): Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="imagetoolbar" content="no" /> <title>Manage Portal</title> <script type="text/javascript" src="js/jquery.min.js"></script> <script> !window.jQuery && document.write('<script src="jquery-1.4.3.min.js"><\/script>'); </script> <script type="text/javascript" src="js/jquery.mousewheel-3.0.4.pack.js"></script> <script type="text/javascript" src="js/jquery.fancybox-1.3.4.pack.js"></script> <link rel="stylesheet" type="text/css" href="css/jquery.fancybox-1.3.4.css" media="screen" /> <link rel="stylesheet" href="css/style.css" /> <script type="text/javascript"> $(document).ready(function() { /* * Examples - images */ $("#various3").fancybox({ 'width' : '75%', 'height' : '75%', 'autoScale' : false, 'transitionIn' : 'none', 'transitionOut' : 'none', 'type' : 'iframe' }); }); </script> </head> <a id="various3" href="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/Lists/Messages/NewForm.aspx?RootFolder=%2Fsites%2FDepartmentCommunities%2FInvestorServices%2FISMC2%2FLists%2FMessages&ContentTypeId=0x012002009E73B71E51BD5A4487B5BA4453025B6C&Source=https%3A%2F%2Fbfsiteportal%2Fsites%2FDepartmentCommunities%2FInvestorServices%2FISMC2%2FLists%2FMessages%2FAllItems%2Easpx" target=_blank><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; WIDTH: 238px; BORDER-BOTTOM: 0px solid; HEIGHT: 202px" height=140 alt="Post Message" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/link.png" width=190 border=0></A> </P></TD></TR></TBODY></TABLE> This is the sharepoint "content editor web part" code that works with the default aspx (only used tables to align because separate CSS formatting Sucks with Sharepoint.) Code: <DIV align=center> <TABLE style="WIDTH: 1231px; HEIGHT: 902px" summary="" background=https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/bg.png><BR><BR> <STYLE>A:hover IMG { FILTER: alpha(opacity=30) } </STYLE> <TBODY> <TR> <TD colSpan=8> <P><A title="" href="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/html/helpfile.html" target=_blank><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; WIDTH: 282px; BORDER-BOTTOM: 0px solid; HEIGHT: 265px" alt=HELP!!! src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/link.png" border=0></A></P> <P> </P> <P> <A title="" href="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/IDP/Forms/AllItems.aspx" target=_blank><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; BORDER-BOTTOM: 0px solid" alt=IDP src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/idpbut.png" border=0></A><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; BORDER-BOTTOM: 0px solid" alt=NQR src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/nqrbut.png" border=0><A title="" href="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/Command%20Center%20Call%20Totals/Forms/AllItems.aspx" target=_blank><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; BORDER-BOTTOM: 0px solid" alt="Call Totals" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/ct.png" border=0></A><A title="" href="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/stats_usage/Sharepoint%20-%20KnowledgeBase%20Usage%202011.xls" target=_blank><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; BORDER-BOTTOM: 0px solid" alt=NQR src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/kb.png" border=0></A><A title="" href="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/Quality/Forms/AllItems.aspx?RootFolder=%2fsites%2fDepartmentCommunities%2fInvestorServices%2fQuality%2fQuality%20Analysts%2fNQR%20Reports%20%2d%20Names%20Included&FolderCTID=&View=%7b2D817F74%2d9FF3%2d4326%2d9426%2dA9282BD600DC%7d" target=_blank><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; BORDER-BOTTOM: 0px solid" alt=NQR src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/nqrbut.png" border=0></A> </P> <P> <A title="" href="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/ScoreCards/Forms/AllItems.aspx" target=_blank><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; BORDER-BOTTOM: 0px solid" alt=Scorecards src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/scbut.png" border=0></A><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; BORDER-BOTTOM: 0px solid" alt=NQR src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/nqrbut.png" border=0><A title="" href="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/Shared%20Documents/Forms/AllItems.aspx?RootFolder=%2fsites%2fDepartmentCommunities%2fInvestorServices%2fShared%20Documents%2fCommand%20Center%2fDaily%20Reports%2fEfficiency%20Reports&FolderCTID=&View=%7b9A6F0DB3%2d0681%2d4156%2dBB8C%2d19F58142F97A%7d" target=_blank><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; BORDER-BOTTOM: 0px solid" alt="Efficiency Reports" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/er.png" border=0></A><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; BORDER-BOTTOM: 0px solid" alt="Mel's RFPs" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/mrfp.png" border=0><A title="" href="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/Quality/Forms/AllItems.aspx?RootFolder=%2fsites%2fDepartmentCommunities%2fInvestorServices%2fQuality%2fQuality%20Analysts&FolderCTID=&View=%7b2D817F74%2d9FF3%2d4326%2d9426%2dA9282BD600DC%7d" target=_blank><IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; BORDER-BOTTOM: 0px solid" alt="Quality Folder" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/qf.png" border=0></A> <A title="" href="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/Lists/Messages/AllItems.aspx" target=_blank></A> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P><A title="" href="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/html/helpfile.html" target=_blank></A> </P> <P> </P> <P> </P> <P><A title="" href="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/html/helpfile.html" target=_blank></A> </P></TD> <TD colSpan=7> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> </P> <P> <IMG style="BORDER-RIGHT: 0px solid; BORDER-TOP: 0px solid; BORDER-LEFT: 0px solid; WIDTH: 210px; BORDER-BOTTOM: 0px solid; HEIGHT: 229px" alt=HELP!!! src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/link.png" border=0></P></TD></TR></TBODY></TABLE> <TABLE style="WIDTH: 100%" summary=""> <TBODY></TBODY></TABLE> <P> </P></DIV> <DIV></DIV> <BR> <BR> Now that i figured my javascript wasnt working with the above code on Sharepoint, I opted to make a completely separate HTML page to replace Sharepoint's default ASPX page (seeing that its such a mess with all the nbsp's and crap, css is much cleaner to position the icons that i need in the proper spots. This might confuse some because i'm in a rush to figure this all out. Code: <style type="text/css"> body { background-color:black; width: 1231px; height: 902px; } div.BACKGROUNDD { position: middle; top: 100px; left: 40px; width: 1231px; height: 902px; } div.NQRBUTTON { position: absolute; top: 320px; left: 250px; width: 80px; height: 80px; } div.IDPBUTTON { position: absolute; top: 320px; left: 330px; width: 81px; height: 81px; } div.CTBUTTON { position: absolute; top: 319px; left: 405px; width: 80px; height: 80px; } div.KBBUTTON { position: absolute; top: 323px; left: 485px; width: 77px; height: 77px; } div.QFBUTTON { position: absolute; top: 323px; left: 568px; width: 81px; height: 81px; } div.SCBUTTON { position: absolute; top: 323px; left: 653px; width: 80px; height: 80px; } div.IDPBUTTON1 { position: absolute; top: 323px; left: 733px; width: 80px; height: 80px; } div.KBBUTTON1 { position: absolute; top: 423px; left: 250px; width: 80px; height: 80px; } div.QFBUTTON1 { position: absolute; top: 423px; left: 330px; width: 80px; height: 80px; } div.SCBUTTON1 { position: absolute; top: 423px; left: 405px; width: 80px; height: 80px; } div.container { position: absolute; width: 1231px; height: 902px; margin: 0 auto; text-align: left; } table.center { position: absolute; width: 1231px; height: 902px; margin-left:auto; margin-right:auto; } table#table1 { width:70%; margin-left:10%; margin-right:15%; }</style> <table border="0" class="center" id="table1" style="width: 1231px; height: 902px"> <tbody> <tr> <td> <div class="Backgroundd"> <img border="o" height:="902" position="absolute" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/bg.png" width:="1231" /></div> <div class="NQRBUTTON"> <a href="http://www.google.com"><img position="absolute" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/nqrbut.png" style="border-right: 0px solid; border-top: 0px solid; border-left: 0px solid; width: 80px; border-bottom: 0px solid; height: 80px" /></a></div> <div class="IDPBUTTON"> <img border="0" height="80" position="absolute" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/idpbut.png" width="80" /></div> <div class="CTBUTTON"> <img border="0" height="80" position="absolute" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/ct.png" width="80" /></div> <div class="KBBUTTON"> <img border="0" height="78" position="absolute" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/kb.png" width="78" /></div> <div class="QFBUTTON"> <img border="0" height="78" position="absolute" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/qf.png" width="78" /></div> <div class="SCBUTTON"> <img border="0" height="81" position="absolute" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/scbut.png" width="81" /></div> <div class="IDPBUTTON1"> <img border="0" height="80" position="absolute" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/idpbut.png" width="80" /></div> <div class="KBBUTTON1"> <img border="0" height="80" position="absolute" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/kb.png" width="80" /></div> <div class="QFBUTTON1"> <img alt="" border="0" height="80" position="absolute" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/qf.png" width="80" /></div> <div class="SCBUTTON1"> <img border="0" height="80" position="absolute" src="https://bfsiteportal/sites/DepartmentCommunities/InvestorServices/ISMC2/images/scbut.png" width="80" /></div> <div> </div> <div> </div> </td> </tr> </tbody> </table> <p> </p> Can anyone tell me why the javascript isnt compatible with either of these codes? I really need this because the lightbox is what my supervisor needs. I would've taken more time to properly introduce myself, but i'm in deperate need to finish this code this week and make it perfect, whether it's in the Sharepoint aspx or through a completely new html to replace the aspx. Thanks in advance. I really appreciate any help available here. I am working on a javascript for my blackberry. I am trying to capture the latitude and longitude of that phone. I am able to get the coordinates in an alert box but am having a little trouble writing it to a form input field. Can anyone help me with this? 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" xml:lang="en" lang="en"> <head> <title>GPS Testing</title> </head> <body> <script type="text/javascript"> if(blackberry.location.GPSSupported){ document.write("Your device supports GPS locating"); blackberry.location.onLocationUpdate(window.alert("Latitude: " + blackberry.location.latitude + " Longitude: " + blackberry.location.longitude)); var lat = blackberry.location.latitude(); var lng = blackberry.location.longitude(); blackberry.location.refreshLocation(); document.write(lat); } </script> </body> </html> I am only able to test with Blackberry. I was trying to create a couple of variables with the "var lat =" and var lng =". With this script I get the alert window and when I click ok it writes "Your device supports ..." Thanks for any help! I would like to apologize in advance if my question sounds too simple. I am a novice to Javascript and have not had any real formal training here. I am creating a webpage which utilizes a separate .xml file to populate values in my webpage. This is my webpage (links.html): and here is my xml file (links_data.xml): This is my output: I have a link at the bottom of the page that points to the device being displayed. In this case, the link should be: http://10.90.139.201 If my xml file changes, it should point to the new IP address. My question is, how do I get the link to work? Currently, my current link (<a href="http://"IP_address"">Link</a>) does not populate any information. Appreciate any guidance here... thanks. Hi.. I am facing identifier starts immediately after numeric literal error in firefox onclick="document.location.href='<%= themeDisplay.getPathMain() %>/portal/ext/asite/assignOrg'"/> can any 1 solve this?? Is this possible? Code: String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g, ""); } var myStr = " Hi what's up? "; myStr.trim(); alert("{" + myStr + "}"); //will result in the original string, not the trimmed version It's possible with numbers: Code: var myNum = 10; myNum++; alert(myNum); //11 I'm using a form data reference, something like P-1234 for example to create a text file and a link to the file. This is during the construction of a new table or table row with javascript. I have an array of one or more references submitted via form using $_POST. On my action page I am creating a txt file P-1234. If I am creating a table ot table row using createElement(), one of the cells will have a link to the file. If the file is created as follows: PHP Code: $File = $_POST['ref'][$i] . "txt"; After creating the cell Code: var Cell = document.createElement('td'); I assign the file to a variable var File = "<?= $File ?> "; I assume the link is inserted using innerHTML? If so, do I just append the filename to the end of the file path like this? Cell.innerHTML = "http://localhost/Project/+File"; If this is not the right way can someone point me in the right direction? Very new to javascript, so I apologize in advance. I honestly tried to figure this out on my own, and I'm just not able. I'm trying to create a family tree online that has several other related family charts. I want each person's name and birth year to be stored in javascript variables, then I want to be able to just go through the tree, and put the persons name once, and have it put the appropriate name and birthyear in the little boxes that the css is creating. In the js file... I would do this for each family member. Code: var johnname = "John Smith"; var johnbirthyear = "Jan 1 1930"; var janename = "Jane Doe"; var janebirthyear = "Jan 1 1940"; var mikename = "mike wilson"; var mikebirthyear = "Jan 1 1950"; var saraname = "sara johnston"; var sarabirthyear = "Jan 1 1960"; In the HTML file... Code: <div id = "boybox"> <script type="text/javascript"> id = "john"; <!-- this is the only thing I want to have to change --> name = id+"name"; document.write(name); </script> <div id = "year"> <script type="text/javascript"> birthyear = id+"year"; document.write(birthyear); </script> </div> </div> So I thought I had it all figured out. I thought that the above would take the id of John that I added, go to the line that sets the name, add john to the word name, and then document write the variable of johnname from the js file. I know you're laughing at me because of course it instead made the value of name to johnname, then wrote the word johnname in the box. Can anyone point me in the right direction please? ultimately I want to go through and be able to just type the persons name in the html for that box once, and have it update with their appropriate info. Thanks, and sorry for such a rookie question. 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? 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 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 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> 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.
I'm a PHP guy and haven't used jQuery much. I have a script I found in a book and I am trying to get working and am having trouble. It's a drop down list. I am using it in place of an HTML select box, so I want to pass the value selected from the list along with the form in a hidden field. My question is how do I extract the value out of the JS function and get it into the hidden field? Code: $(document).ready(function() { createDropDown(); $(".dropdown dt a").click(function(event) { event.preventDefault(); var dropID = $(this).closest("dl").attr("id"); $("#" + dropID).find("ul").toggle(); }); $(document).bind('click', function(e) { var $clicked = $(e.target); if (! $clicked.parents().hasClass("dropdown")) $(".dropdown dd ul").hide(); }); $(".dropdown dd ul a").click(function() { var dl = $(this).closest("dl"); var dropID = dl.attr("id"); var text = $(this).html(); var source = dl.prev(); $("#" + dropID + " dt a").html(text); $("#" + dropID + " dd ul").hide(); source.val($(this).find("span.value").html()) }); }); function createDropDown() { var selects = $("select.dropdown_value"); var idCounter = 1; selects.each(function() { var dropID = "dropdown_" + idCounter; var source = $(this); var selected = source.find("option[selected]"); var options = $("option", source); source.after('<dl id="' + dropID + '" class="dropdown"></dl>'); $("#" + dropID).append('<dt><a href="#">' + selected.text() + '<span class="value">' + selected.val() + '</span></a></dt>'); $("#" + dropID).append('<dd><ul></ul></dd>'); options.each(function() { $("#" + dropID + " dd ul").append('<li><a href="#">' + $(this).text() + '<span class="value">' + $(this).val() + '</span></a></li>'); }); idCounter++; }); } Can anyone tell me of how to take or assign a javascript variable into php.
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? On this page http://jimpix.co.uk/ecards/262-no-words.html I get this Javascript error in IE6: Code: Line: 5 Character: 1 Code: 0 Error Message: Syntax error URL: http://jimpix.co.uk/ecards/262-no-words.html I'm using the DebugBar add in for IE (http://www.debugbar.com/) The error message in DebugBar is this: http://jimpix.co.uk/junk/error.png And the view-source of the page is he http://jimpix.co.uk/junk/source-code.png I don't get the error in Firefox 3 or IE7. I can't work out how to fix it. Any advice would be much appreciated. Thanks! Can someone point where i'm going wrong? I want to evaluate the values of 'miles' to be >=0 and 'putime' to between 0 and 24 only. Code: <script type = "text/javascript"> function TaxiFare() { // calculates taxi fare based upon miles travelled // and the hour of the day in military time (0-23). var baseFare = 2.50; var costPerMile = 2.00; var nightSurcharge = 0.50; // 8pm to 6am, every night var milesTravelled = Number(document.getElementById("miles").value); var pickupTime = Number(document.getElementById("putime").value); var cost = baseFare + (costPerMile * milesTravelled); // add the nightSurcharge to the cost if it is after // 10pm or before 6am if (pickupTime >= 22 || pickupTime < 6) { cost += nightSurcharge; } if((document.getElementById('miles').value>=0)&&(document.getElementById('putime').value>=0||<=24) { alert("Your taxi fare is $" + cost.toFixed(2)); } else{return 0;} } </script> |