JavaScript - Html Variable
hi i have a hidden variable in html like this
<input type="hidden" name="searchword" value=""> and i need to change the value using javascript. You can do it in vbscript with searchword.value="test" but i dont know how to in javascript ive tried document.searchword.value=cookie_text; cookie_text is a variable by the way thanks Similar TutorialsHi I want to use the javascript variable value in html , for example <script > var alignment = "Right"; </script> <html> <p align = alignment > Hi </p> </html> How can i do like this ! 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? I have two versions of this document. The first version uses only JavaScript and the standard PROMPT(). It works very well, but I would like to insert the name prompt into the page using the input command. For some reason the variable loaded in the HTML statement doesn't get passed to the JavaScript. Any ideas would be appreciated! This is only a small test page. Sorry I don't know about the [code] tag... <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)"> <meta name="created" content="Sat, 10 Sep 2011 19:40:31 GMT"> <meta name="description" content=""> <meta name="keywords" content=""> <title>Enter golfers name</title> <!--[if IE]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <SCRIPT LANGUAGE="JavaScript" type="text/javascript" src="script1.js"></SCRIPT> <SCRIPT LANGUAGE="JavaScript"> function GetPage(){ document.write("OK") var lab = ""; var result = fullname.toUpperCase(); var word=result.split(" "); fname = word[0] lname = word[1] alpha = lname.slice(0,1); lab = fname.concat("_") lab = lab.concat(lname) if(word[2]){ ext = word[2] lab = lab.concat("_") lab = lab.concat(ext) } var intro = "./Stats_"; page = intro.concat(alpha); page = page.concat("_golfers.html#"); page = page.concat(lab) document.write(page) <!-- window.location.pathname = page } </script> </head> <body> <center> <form action="form_action.asp" method="get"> You can enter the golfersname or select him from the above list.<br><br> <input type="text" name="fullname" /> <button type="submit" onclick="GetPage()">GO</button> </form> </center> <BR><BR><BR> This is the end </body> </html> Is it possible to make it so if you click on a <a href> the information such as the name or link changes the <title> of the page and replaces existing opened <div>s with information from the link or such. eg If i had a list of swf files that were attatched to links how could I display each swf file onclick without redirecting whilst changing the title and content? 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 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 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> 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.
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.
favorite I'd like to modify a form on www.formsite.com (form builder app): username: testuser password: password I would like to use the nicedit.com's inline content editor's js to transform my textarea's into a richtext area. At present the nicedit editor works well in creating the richtextarea. However, the KEY point is that I would like formsite's form to pipe in the the created html and render it with the html component of formsite. Currently, the pipe function in formsite will only put out the html syntax in it's html module. action seen he http://fs8.formsite.com/testform/form1/index.html So this would be: 1. checking out my form on formsite.com 2. the script from nicedit.com is already installed in an html component. 3. changing or telling me the scripts/tags/or whatever for formsite form using formsites form builder (which allows some html/script editing). 4. changed so as to render the rich text entered on page 1 in page 2 instead of the html syntax. Any other solutions using formsite and any other richtextarea solutions would be great too! If I have a javascript var in a webpage(html form textarea VALUE - yui) that contains html code, and want to appear it, in confirmformpage.php, then how to transfer it...? is it really needed go via PHP ...? and ofcourse use innerHTML to write it....yes I usually use an intermitened processform.php script. http://developer.yahoo.com/yui/editor I'm trying to store the name of an element ID into a variable, because i need to use it in the second branch of the If-then code. The problem is, when i use: var FirstPiece = e.id alert(FirstPiece); it works, but, when i try to access the data that should still be stored in the FirstPiece variable in the second branch of the If-then structure, i get an error: "undefined". This makes no sense at all to me, because the Scope of the variable is within the function, so it should have access. But for some reason it doesn't. Am i doing something wrong? The code snippet in question: Code: // Set the PieceSelected Flag if (PieceSelectedFlag == 0) { // First Piece Selected var FirstPiece = e.id; PieceSelectedFlag++ return; } if (PieceSelectedFlag == 1) { // Move the piece //document.getElementById(Move).style.left = NewXpos; //document.getElementById(Move).style.top = NewYpos; alert(FirstPiece); // Record the PGN data // Reset the flags and visibilities document.getElementById("PieceBorder").style.visibility = "hidden"; PieceSelectedFlag = 0; MoveFrom = ""; MoveTo = ""; } Full Code: Code: <html> <body> <head> <script lanugage="javascript"> var BlockSize = 50; var BlockBorderWidth = 4; var PieceSelectedFlag = 0; // Create an Array for storing the Positions of the ChessPieces var PieceLocationName = [32]; var PieceLocationXcoord = [32]; var PieceLocationYcoord = [32]; function Start() { // Draw a 400x200 Canvas starting at the bottom of the Chess Board with // White as color on top, and black underneith it //DrawCanvas(0, 500, 400, 200); // Init the Height and Width of the Chess Piece Highlighter border DIV document.getElementById("PieceBorder").style.height = BlockSize -BlockBorderWidth; document.getElementById("PieceBorder").style.width = BlockSize - BlockBorderWidth; // Resize the Chess Piece Images to the appropriate size AdjustPieceSize(BlockSize); // Put the Chess Pieces in their correct places SetPieces(); } function SetPieces() { var LocationArrayIndex = 0; var Pieces = ["Castle1", "Knight1", "Rook1", "King", "Queen", "Rook2", "Knight2", "Castle2"]; // Put down the Black Pieces On the Top var PieceIndex = 0; var PawnIndex = 1; for (var x = 0; x < BlockSize * 8; x=x+BlockSize) { var y = 0; SetPieceID = "Black" + Pieces[PieceIndex] + "Image"; document.getElementById(SetPieceID).style.left = x + "px"; // Set the Chess Piece in the correct place document.getElementById(SetPieceID).style.top = y + "px"; // Load the Piece Name and Location into the PieceLocation Array PieceLocationName[LocationArrayIndex] = SetPieceID; PieceLocationXcoord[LocationArrayIndex] = x; PieceLocationYcoord[LocationArrayIndex] = y; LocationArrayIndex++ document.getElementById("BlackPawn" + PawnIndex + "Image").style.left = x + "px"; // Also set down the pawns document.getElementById("BlackPawn" + PawnIndex + "Image").style.top = y + BlockSize + "px"; // Load the Pawn Name and Location into the PieceLocation Array PieceLocationName[LocationArrayIndex] = SetPieceID; PieceLocationXcoord[LocationArrayIndex] = x; PieceLocationYcoord[LocationArrayIndex] = y; PieceIndex++; PawnIndex++; LocationArrayIndex++ } // now put down the white pieces PieceIndex = 0; PawnIndex = 1; for (var x = 0; x < BlockSize * 8; x=x+BlockSize) { var y = BlockSize * 7; SetPieceID = "White" + Pieces[PieceIndex] + "Image"; document.getElementById(SetPieceID).style.left = x + "px"; // Set the Chess Piece in the correct place document.getElementById(SetPieceID).style.top = y + "px"; // Load the Piece Name and Location into the PieceLocation Array PieceLocationName[LocationArrayIndex] = SetPieceID; PieceLocationXcoord[LocationArrayIndex] = x; PieceLocationYcoord[LocationArrayIndex] = y; LocationArrayIndex++ document.getElementById("WhitePawn" + PawnIndex + "Image").style.left = x + "px"; // Also set down the pawns document.getElementById("WhitePawn" + PawnIndex + "Image").style.top = y - BlockSize + "px"; // Load the Pawn Name and Location into the PieceLocation Array PieceLocationName[LocationArrayIndex] = SetPieceID; PieceLocationXcoord[LocationArrayIndex] = x; PieceLocationYcoord[LocationArrayIndex] = y; PieceIndex++; PawnIndex++; LocationArrayIndex++ } } function AdjustPieceSize(NewSize) { // Adjust the size of the Chess pieces var ColorPiece = ["White", "Black"]; var PieceName = ["Pawn1", "Pawn2", "Pawn3", "Pawn4", "Pawn5", "Pawn6", "Pawn7", "Pawn8", "Castle1", "Castle2", "Knight1", "Knight2", "Rook1", "Rook2", "King", "Queen"]; for (var ColorIndex = 0; ColorIndex < ColorPiece.length; ColorIndex++) { for (var PieceIndex = 0; PieceIndex < PieceName.length; PieceIndex++) { var String = ColorPiece[ColorIndex] + PieceName[PieceIndex] + "Image"; document.getElementById( String ).style.width = NewSize; document.getElementById( String ).style.height = NewSize; } } } function RoundNearest(num, acc) { if ( acc < 0 ) { // alert("warning!"); // return; num *= acc; num = Math.round(num); num /= acc; return num; } num /= acc; num = Math.floor(num); num *= acc; return num; } function SelectChessLocation(e, event) { // Get the current mouse x,y position var xCoord = event.clientX; var yCoord = event.clientY; // What is the closest Square var ClosestX = RoundNearest(xCoord, BlockSize); var ClosestY = RoundNearest(yCoord, BlockSize); // Draw a Red Border around the closest square document.getElementById("PieceBorder").style.visibility = "visible"; document.getElementById("PieceBorder").style.top = ClosestY; document.getElementById("PieceBorder").style.left = ClosestX; // Set the PieceSelected Flag if (PieceSelectedFlag == 0) { // First Piece Selected var FirstPiece = e.id; PieceSelectedFlag++ return; } if (PieceSelectedFlag == 1) { // Move the piece //document.getElementById(Move).style.left = NewXpos; //document.getElementById(Move).style.top = NewYpos; alert(FirstPiece); // Record the PGN data // Reset the flags and visibilities document.getElementById("PieceBorder").style.visibility = "hidden"; PieceSelectedFlag = 0; MoveFrom = ""; MoveTo = ""; } } </script> </head> <body bgColor="green" onLoad="Start();"> <img id="ChessBoard" src="ChessBoard.png" style="position: absolute; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackPawn1Image" src="Black-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackPawn2Image" src="Black-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackPawn3Image" src="Black-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackPawn4Image" src="Black-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackPawn5Image" src="Black-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackPawn6Image" src="Black-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackPawn7Image" src="Black-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackPawn8Image" src="Black-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackCastle1Image" src="Black-Castle.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackKnight1Image" src="Black-Knight.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackRook1Image" src="Black-Rook.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackKingImage" src="Black-King.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackQueenImage" src="Black-Queen.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackRook2Image" src="Black-Rook.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackKnight2Image" src="Black-Knight.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="BlackCastle2Image" src="Black-Castle.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhitePawn1Image" src="White-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;"OnClick="SelectChessLocation(this, event);"> <img id="WhitePawn2Image" src="White-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhitePawn3Image" src="White-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhitePawn4Image" src="White-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhitePawn5Image" src="White-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhitePawn6Image" src="White-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhitePawn7Image" src="White-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhitePawn8Image" src="White-Pawn.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhiteCastle1Image" src="White-Castle.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhiteKnight1Image" src="White-Knight.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhiteRook1Image" src="White-Rook.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhiteKingImage" src="White-King.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhiteQueenImage" src="White-Queen.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhiteRook2Image" src="White-Rook.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhiteKnight2Image" src="White-Knight.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <img id="WhiteCastle2Image" src="White-Castle.png" style="position:absolute; width: 50px; height: 50px; top: 0px; left: 0px;" OnClick="SelectChessLocation(this, event);"> <div id="PieceBorder" Style="position: absolute; top: 0px; left: 0px; height: 50px; width: 50px; border: 2px solid red; visibility: hidden;"> </div> </body> </html> I cant seem to get the value of var drivingDistanceMiles1 outside the function it is given a value in. I need "resultsC" to return the value of the variable drivingDistanceMiles1 but can only return the value at "resultsA" Please help. PHP Code: function initialize() { geocoder = new GClientGeocoder(); gDir1 = new GDirections(); GEvent.addListener(gDir1, "load", function() { var drivingDistanceMiles1 = gDir1.getDistance().meters / 1609.344; document.getElementById('resultsA').innerHTML = drivingDistanceMiles1; }); document.getElementById('resultsC').innerHTML = drivingDistanceMiles1; } I have to create a code that will prompt the user to enter a hypothetical width and length of a pool, show the area of that, then get prompt them to enter a hypothetical charge of a pool cleaning company, and get the webpage to tell how much the hypothetical bill would be. Here's the code I'm using, but it won't work for me, any suggestions would be appreciated! <script type="text/javascript"> var width= parseFloat ( window.prompt ("What is the width of the pool?")) var length= parseFloat ( window.prompt ("Length of pool")) document.write ( "The area is:"+width * length) var charge= parseFloat ( window.promt ("Charge of pool company")) var area= parseFloat ( width * length ) document.write ( "The bill would be:"area * charge) </script> Hi, The following loop works: Code: <html> <body> <script type="text/javascript"> var i=0; for (i=0;i<=5;i++) { document.write("The number is " + i); document.write("<br />"); } </script> </body> </html> But the following doesn't: Code: <html> <body> <script type="text/javascript"> var i=0; var x="i=0;i<=5;i++" for (x) { document.write("The number is " + i); document.write("<br />"); } </script> </body> </html> I'd just like to create a simple variable. Please bear with me as I'm a newbie in JavaScript and let me know what I'm missing. Many thanks in advance! Rain Lover |