JavaScript - Variable Command ()
How to set a js command using a variable?
var name = 'field'; var number = '1'; name.number(); doesn't work [when the js function is called field1] I am using a set of dynamically created textareas and need to be able to reference each one by number. Any thoughts? Similar TutorialsI am modifying a small online text editor. I have a series of dynamically generated fields: sub0 sub1 sub2 etc. I get stuck feeding the modified data back. subX.selection.setContent() - where X is the field number. how can I set X as a variable? im not sure now to word it, or how to do it, im a php coder not a javascript -.- but here it is, basicly i have one ajax file and wish to use it for everypage, i tryed to do it so i can just call one function for all ajax uses, but forms seem to be thowing me off the idea is when i call it, i stat if its a form or a element, Code: function ajax(str, b, c) { a = b; type = c; if (type === 'form') { document.form.b.value='Reading in progress...'; } if (type === 'element') { document.getElementById(a).innerHTML='Reading in progress...'; } xmlhttp = GetXmlHttpObject(); if (xmlhttp === null) { alert('Your browser does not support XMLHTTP!'); return; } xmlhttp.onreadystatechange = stateChanged; xmlhttp.open('GET', str, true); xmlhttp.send(null); } in this, the variable a is set as the id of the elemnt/form, it works fine for elemnts, but not for forms, i think this is because its thinking a is the id, not the variable, any way around this? Hi, I have this code.. Code: javascript:function showMore() {ProfileStream.getInstance().showMore(); setTimeout(showMore, 2000)}; showMore(); i want to loop it 10 times, but do not know how to do it. I have been told that the for var command is what I want, but I cannot get it to work. Any help would be appreciated. Thanks I am trying to use the LPR command inside a javascript to print a PDF file directly to the printer. Want just a simple webpage with a button which will print test.pdf when clicked. lpr -S xxx.xxx.xxx.xxx -P print -o l C:\Users\xxxxxx\Desktop\test.pdf I know very little when it comes to javascript. If you know of a better way to use the lpr command, please let me know. I need to set something up so every X amount of second on a page it goes a certain command, and keeps resetting the counter after everytime and goes again. I thought of many of the timer commands I have found on Google but didn't know if this was the RIGHT way to do it since I want it to be a document command that repeats. If what is returned to the command is true instead of false it needs to be able to change location of the browser, so I didn't know if the timer commands I found were right or not. Thanks. Sorry for the stupid question but i can't find a specific answer and i'm a newby. Here is a example of what i have: <html> <head> <script type="text/javascript"> function open_win() {window.open("http://www.microsoft.com","Window1","menubar=no,width=660,height=300,toolbar=no,scrollbars=yes");} </script> </head> <body> <form> <input type=button value="Open Window" onclick="open_win()"> </form> </body> In stead of a button to open one window, i would like a numeric input box that asks "How many windows do you want to open?" then incorporate a loop command to loop the open_win() x amount of times. Any help would be appreciated. Thanks hey everyone, I am having some trouble with one of my buttons, the one button works fine but my second one doesnt work at all. The second button should open the same page as the first and maximize it. Could someone please help me with this? Thanks. Code: <html> <head> <title>commands</title> <script type="text/javascript"> /* <![CDATA[ */ var maxWindow function createWindow() { var winWidth=300; var winHeight=100; var winLeft = (screen.width-winWidth)/2; var winTop = (screen.height-winHeight)/2; var winOptions = ",width=" + winWidth; winOptions += ",height=" + winHeight; winOptions += ",left=" + winLeft; winOptions += ",top=" + winTop; maxWindow = window.open("MaxWindow.html", "newWindow", winOptions); maxWindow.focus(); } function maximizeWindow() { maxWindow.moveTo(0,0); maxWindow.resizeTo(screen.availWidth,screen.availHeight); maxWindow.focus(); } /* ]]> */ </script> </head> <body> <input type="button" name="Create New Window" value="Create new Window" onclick="createWindow();"/> <input type="button" name="Maximize New Window" value="Maximize New Window" onclick="maximizeWindow();"/> </body> </html> For example, how can I write "Hello!" on the page every Friday at 8:40?
I'm a newby that just finished an online javascript course. When I do a search on Math.random() I receive sites that all describe the command as returning a number 'between 0 and 1'. My question is - are the expected numbers limited to - 0.0000000000000001 thru 0.9999999999999999 or is it possible to get the 0 and 1 also. Seems like the definition should be 'from 0 thru 1' rather than 'between 0 and 1'. JoeF Hi, I've ben trying to figure this one out for days now and so I'd thought to give it a shoot here to see whether anybody can give me any advice or inspiration. Basically what I am trying to do is command a click of a bottom for a certain set time. for example: On the google main search engine page. Once ive typed in a search for "skateboards". I would then like to command the "search" bottom to clicked at 10 pm at night thus executing the search for "skateboards" going into the next page with all the search results. I was wondering if it would be possible to right a Java command that could be run in the Mozilla Fire Fox Scratch pad tool. ( Which is found under Tools --> Web Developer.) Please let me know of anything. It would be very grateful. Thanks, Jon57 Very naive coding question... i'm a novice coder and i think javascript is the solution i need but - maybe there's better ways... Ok - my website accepts a login password to access certain pages. Depending on the password entered i set a javascript variable to either 'true' or 'false'. If the variable is set to 'true' then i want to give the user access to shopping cart buttons, if 'false' then the shopping cart buttons should be hidden. My current solution is to wrap javascript around each shopping cart button and display only if the variable is set to 'true'. The shopping cart button looks a bit like this: Code: <form method="post" action="http://www.shoppingcart.com"> <input type="hidden" name="product" value="product" /> <input type="hidden" name="price" value="9.99" /> <input type="hidden" name="return" value="http://www.home.com"/> <input type="submit" value="add to basket" /> </form> I've tried displaying this using document.write() - but it gets confused when it encounters the ":" in the web address. Also i get the impression from trawling the forums that document.write is not flavour of the month these days. And another thought - I accept the variable on one page - then move to multiple other pages to reference it.... will the variable still be there when i move to other pages or do i need to somehow pass it across each time? Trying to keep my coding XHTML compliant... Any pointers and idiot proof suggestions would be much appreciated. hi, i am trying to make my website so that when i click on a button it makes the selected text into bold or when i click another button it makes the selected text italic and finally when a thrid button is clicked it makes it underlined. i have tried searching for a way of doing this throught javascript but i cant seem to find any. any suggestions or examples on how i can achieve this would be much appreciated as i really need to get this working, thanks for any advice given I am trying to run a stored proc from my page using JScript and I am stuck on this error: Quote: Microsoft OLE DB Provider for ODBC Drivers error '80040e14' [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or Function 'AD_AdminInsert2' expects parameter '@CourseID', which was not supplied. The param @CourseID is requested in the stored proc but I don't know why it is not finding it from the following code: Code: cmdAdminInsert = Server.CreateObject("ADODB.Command"); cmdAdminInsert.ActiveConnection = connStringforTest; cmdAdminInsert.CommandText = "dbo.AD_AdminInsert2"; cmdAdminInsert.CommandType = adCmdStoredProc; cmdAdminInsert.Parameters.Append(cmdAdminInsert.CreateParameter ("RETURN_VALUE", adInteger, adParamReturnValue)); cmdAdminInsert.Parameters.Append(cmdAdminInsert.CreateParameter ("@CallerAdminID", adInteger, adParamInput, 1709)); cmdAdminInsert.Parameters.Append(cmdAdminInsert.CreateParameter ("@CourseID", adInteger, adParamInput, 65)); cmdAdminInsert.Parameters.Append(cmdAdminInsert.CreateParameter ("@AdminID", adInteger, adParamOutput)); cmdAdminInsert.Parameters.Append(cmdAdminInsert.CreateParameter ("@OutputResult", adVarChar, adParamOutput, 255)); cmdAdminInsert.Execute(); cmdAdminInsert.ActiveConnection.Close(); An insight or links would be appreciated. Thanks, JJ So im working on a case where I need to make a random ad pop up every time I refresh that web page. I've got all the steps down except to where I need to insert a command to write the text to the document. *Insert a command to write the following text to the Web document: Code: <a href="URL"> <img src="adn.jpg" alt="description" /> </a> where URL is the value of the rLink variable, n is the value of the rNumber variable, and description is the value of the rAD variable. what I have so far (all steps completed) is Code: <script type="text/javascript"> var rNumber= randInt(5);// generate a random integer from 1 to 5. var rAd= adDescription(rNumber);// description of the random ad. var rLink= adLink(rNumber);// URL of the random ad. document.write('<a href'"+rLink+"'><img src="ad'+rNumber+'.jpg" alt="'+rAd+'"/></a>'); </script> the bolded is the question, I know some quotes are out of order but I cant figure out which. any help would be appreciated Dear all, attached is a page for my website to allow visitors to purchase photos. It is made from 2 Paypal example scripts - one for the form and another for an additional text box. It works fine apart from one detail, the text being entered does not get sent - instead, the information it forwards is "6x4 Colour Prints. Item Number id10" The "6x4 Colour prints" bit is good - the "Item number id10" is where I'd ideally like to see the custom text being entered and the guys at Paypal developer forums have said that a Javascript command is overriding the text being forwarded and to seek advice from those who know Javascript. I've tried for a day by trial and error to see if I can take this command out but it has got to the hair pulling out stage so I'm calling on those who know best to cast a wise eye over the code and see if there is an easy fix to this. Any help or suggestions as to howe to alter this will be most gratefully received. Thanks in advance, Dave. Please help me out with this. I have Vista and the easier way to compile java programs using Textpad is just not working. I have a deadline soon so I'm using command prompt. I have ensured that javac is now recognized in command prompt, and even "programname.java" is recognized in the command prompt, but for some reason, when I type javac programname.java it tells me: C:\Users\name>javac programname.java javac: file not found: programname.java Usage: javac <options> <source files> use -help for a list of possible options Thank you so much for your help! Additional information: I added javac to the "Path" system variable, following instructions I found elsewhere on this thread. When I type java -version it all looks good. I decided when it initially failed to find programname.java to add the location of the .java to the "Path" as well. I can now open the program using command prompt, but when I try javac it can't find it. I am perplexed. 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... 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. 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? |