JavaScript - Passing Variables To A Pop-up Page Function
I'm new to javascript and have come across what I'm sure its a really easy problem to solve. I want a page with a hyperlink that passes a variable to another 'pop-up' page (in this case a name, its just an example) and new pop-up page prints a message followed by the variable thats passed.
Here is the code as it is right now Code: <html> <head> <script language="javascript" type="text/javascript"> function popitup(a) { var reply = 'a'; newwindow=window.open('','name','height=200,width=150'); var tmp = newwindow.document; tmp.write('<html><head><title>popup</title>'); tmp.write('</head><body><p>"Hello there" + reply </p>'); tmp.write('<p><a href="javascript:self.close()">close</a> the popup.</p>'); tmp.write('</body></html>'); tmp.close(); } </script> </head> <body> <a href="testpopup.html" onclick="popitup('Toby')" >Link to popup</a> </body> </html> In short, I just want the pop-up page to print 'Hello there Toby' or whatever name I choose to pass across. Any help much appreciated!! The 'testpopup.html' url is just the initial webpage. Similar TutorialsHi, I am quite new to javascript but I'm quite sure this problem is very easy to solve. I have a vague idea of what might be going wrong but I have no idea what I should be doing instead. Here is what I'm trying to do: User inputs X and Y coordinates into form validate that they are numbers do a little bit of maths redirect to a php script with a single variable tacked onto the end of the url Here is the form code: Code: //part of a larger php script to make the form echo "<form name='gotoForm' onsubmit='return coordCalc()'> <fieldset> <legend>Go to Square</legend> X <input type='text' id='X' size='1' maxlength='3'/> Y <input type='text' id='Y' size='1' maxlength='3'/> <input type='submit' value='Go To' /> </fieldset> </form> "; which references these functions in the header: Code: //Is it a number function isNumeric(elem, helperMsg){ var numericExpression = /^[0-9]+$/; if(elem.value.match(numericExpression)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } //deal with the input, check if they are both numbers with the above function //if they are do some maths on the input //add the result onto a url and redirect function coordCalc (){ var Xcoord = document.getElementById('X'); var Ycoord = document.getElementById('Y'); if(isNumeric(Xcoord, "Please enter a Number for X")){ if(isNumeric(Ycoord, "Please enter a Number for Y")){ //Takes the X and Y coordinates and transforms them into a single number //not fully coded in case you try putting some numbers into the formula btw :) var X = parseInt(document.getElementById('X').value); var Y = parseInt(document.getElementById('Y').value); var G = 16; var Z = (((G + 1) - Y) - Y); var A = (Y + Z); var B = (X - 1); var L = ((A * (G - 1)) + B); window.location = "map.php?start=" + L; } } return false; } The number validation works but the url ends up as map.php?start=NaN. Now, this simply must be the way I am assigning the Xcoord and Ycoord variables with the document.getElementByID() function I am sure. But like I said, I have no idea what to do instead, any help is massively appreciated. Thankyou! First off I didn't know whether to post this here or in the PHP section since it deals with both, but mostly JS. I have a PHP scraper that scrapes the job title, company name and location from a website and stores them in separate arrays. These values are then extracted out one at a time from the array and stored into a string, that is then passed to a Google Maps API. I can make this successfully happen once, the thing is I need to do it multiple times. I have an idea on what I should do but don't really know how to implement it (correctly). The idea I had was to create a function in the JavaScript section that accepts three values from PHP. This function would be called in my PHP for loop that extracts the values from the array into a string. The thing that confuses me is that the Map function is called via <body onLoad="initialize()">. Here's the link to my code I want to pass 2 variables from a html page and collecting in another html page using javascript. say i pass xyz and abc to a page 2.html from 1.html without using cookies. In 1.html page i have many links. each link should be able to pass different variable to 2.html. when some one clicks on a link the variables should be passed to 2.html I want to know how to collect them and use them. please provide me code snippet. Hi, I am facing a problem in passing replace() function as an argument in user defined java function, can any one help me how to resolve it? intention is to pass a file path to my user defined function, but before passing the path i want to replace the character '\' to '\\' I am posting my javascript function he <a href="#" onclick="OpenDocPreview('<%# Eval("PATH")%>'.replace(/\\/g,"\\\\"), '<%# Eval("Filename")%>')"><%# Eval("DocTitle") %></a> function OpenDocPreview(url, docname) { alert('message from search base : ' + url + ' ' + docname); } thank you, if i have: function someFunction(){ var original = "Original Variable"; anotherFunction(original); } function anotherFuntion(){ /* 1.does the original variable automatically get passed? 2. will var transformed = original + "Transformed" give me a result of "Original Variable Transformed"? 3. Or does it have to be declared in the function: anotherFunction(original) */ } thanks for any help hi, I am building a web app, I have a list of towns and a list of counties as you can see he http://www.mypubspace.com/mobile/#home (best viewed in Safari) What I would like to do is to pass through the Town value as a variable and then change my SQL query based on which town is selected here is the code Code: <!doctype html> <?php include "../config.php"; $loggedIn = (isset($_COOKIE['loggedin']) && $_COOKIE['loggedin'] == 'true')?true:false; $query1 = "SELECT DISTINCT rsTown FROM pubs ORDER BY rsTown asc"; $result = mysql_query($query1); $town = $_REQUEST['RSTOWN']; $townpubs = mysql_query("SELECT * FROM pubs WHERE RSTOWN = ".$town." ORDER BY RSTOWN ASC"); $towns = mysql_query("SELECT DISTINCT RSTOWN, COUNT(PUBID) As PubCount FROM pubs GROUP BY RSTOWN ORDER BY RSTOWN ASC"); $counties = mysql_query("SELECT DISTINCT RSCOUNTY, COUNT(PUBID) As PubCount1 FROM pubs GROUP BY RSCOUNTY ORDER BY RSCOUNTY ASC"); ?> <html> <head> <meta charset="UTF-8" /> <title>My Pub Space v1.0 β</title> <style type="text/css" media="screen">@import "jqtouch/jqtouch.min.css";</style> <style type="text/css" media="screen">@import "themes/jqt/theme.min.css";</style> <script src="jqtouch/jquery.1.3.2.min.js" type="text/javascript" charset="utf-8"></script> <script src="jqtouch/jqtouch.min.js" type="application/x-javascript" charset="utf-8"></script> <script type="text/javascript" charset="utf-8"> var jQT = new $.jQTouch({ icon: 'jqtouch.png', addGlossToIcon: false, startupScreen: 'jqt_startup.png', statusBar: 'black', preloadImages: [ 'themes/jqt/img/back_button.png', 'themes/jqt/img/back_button_clicked.png', 'themes/jqt/img/button_clicked.png', 'themes/jqt/img/grayButton.png', 'themes/jqt/img/whiteButton.png', 'themes/jqt/img/loading.gif' ] }); </script> </head> <body> <div id="about" class="selectable"> <p><img src="jqtouch.png" /></p> <p><strong>My Pub Space</strong><br />Version 1.0 beta<br /> <a href="http://www.jbiddulph.com" rel="nofollow" target="_blank">By John Biddulph</a></p> <p><em>Mobile Web Development</em></p> <p><a href="mailto:xxxxx@gmail.com" rel="nofollow" target="_blank">E-mail</a></p> <p><a href="http://twitter.com/#!/jmbiddulph" rel="nofollow" target="_blank">@jmbiddulph on Twitter</a></p> <p><br /><br /><a href="#" class="grayButton goback">Close</a></p> </div> <div id="home" class="current"> <?php if (!$loggedIn){ ?> <div class="toolbar"> <h1>My Pub Space</h1> <a href="#about" id="infoButton" class="button slideup">About</a> </div> <ul class="rounded"> <li class="forward"><a href="#signup">Sign up (FREE!)</a></li> <li class="forward"><a href="#login">Login</a></li> <li class="forward"><a href="#towns">View pubs by town</a></li> <li class="forward"><a href="#counties">View pubs by county</a></li> </ul> <div class="info"> <p>All Rights Reserved © 2011 mypubspace.com Created by: jbiddulph.com</p> </div> <?php } else { ?> <div class="toolbar"> <h1>Welcome <?php echo $_SESSION['s_username'];?></h1> <a href="dologoff.php" rel="external" class="button">Logout</a> </div> <ul class="rounded"> <li class="forward"><a href="#towns">View Towns</a></li> <li class="forward"><a href="#counties">View Counties</a></li> </ul> <div class="info"> <p>All Rights Reserved © 2011 mypubspace.com Created by: jbiddulph.com</p> </div> <?php } ?> </div> <!-- TOWNS --> <div id="towns"> <div class="toolbar"> <h1>View Towns</h1> <a class="back" href="#home">Back</a> </div> <ul class="edgetoedge"> <?php while($row1 = mysql_fetch_array($towns)) { echo '<li class="forward"><a href="#townpubs-?RSTOWN='.$row1['RSTOWN'].'" rel="external">'.$row1['RSTOWN'].'<small class="listcounter">'.$row1['PubCount'].'</small></a></li>'; } ?> </ul> </div> <div id="townspubs"> <div class="toolbar"> <h1>Pubs in <?php echo $town ?></h1> <a class="back" href="#home">Back</a> </div> <ul class="edgetoedge"> <?php while($row1 = mysql_fetch_array($towns)) { echo '<li class="forward">'.$row1['rsPubName'].'</li>'; } ?> </ul> </div> <!-- COUNTIES --> <div id="counties"> <div class="toolbar"> <h1>View Counties</h1> <a class="back" href="#home">Back</a> </div> <ul class="edgetoedge"> <?php while($row1 = mysql_fetch_array($counties)) { echo '<li class="forward"><a href="countypubs.php&rsCounty='.$row1['rsCounty'].'" rel="external">'.$row1['RSCOUNTY'].'<small class="listcounter">'.$row1['PubCount1'].'</small></a></li>'; } ?> </ul> </div> <div id="countypubs"> <div class="toolbar"> <h1>View Counties</h1> <a class="back" href="#home">Back</a> </div> <ul class="edgetoedge"> <?php while($row3 = mysql_fetch_array($county_pubs)) { echo '<li class="forward"><a href="#countypubs&rsCounty='.$row3['rsCounty'].'">'.$row3['RSPUBNAME'].'</a></li>'; } ?> </ul> </div> <form id="login" action="dologin.php" method="POST" class="form"> <div class="toolbar"> <h1>Login</h1> <a class="back" href="#">Back</a> </div> <ul class="rounded"> <li><input type="text" name="rsUser" value="" placeholder="Username" /></li> <li><input type="Password" name="rsPass" value="" placeholder="Password" /></li> </ul> <a style="margin:0 10px;color:rgba(0,0,0,.9)" href="#" class="submit whiteButton">Submit</a> </form> <form id="signup" action="dosignup.php" method="POST" class="form"> <div class="toolbar"> <h1>Sign up</h1> <a class="back" href="#">Back</a> </div> <ul class="rounded"> <li><select name="rsTown" class="postcodedrop"> <option value="">Choose your Town...</option> <?PHP while($row = mysql_fetch_array($result)) { echo '<option value="'.$row['rsTown'].'">'; echo $row['rsTown']; echo '</option>'; }?> </select></li> <li><input type="Password" name="rsPass" value="" placeholder="Password" /></li> </ul> <a style="margin:0 10px;color:rgba(0,0,0,.9)" href="#" class="submit whiteButton">Submit</a> </form> </body> </html> Please help! Hi, I hope someone can help me! I have a list of buttons, each with a different id which is taken from the ids of these values from the database. When I click one of the buttons it shows the items that correspond to this id in the database. Therefore, when different buttons are clicked the display changes to match the objects relating to this particular button. When a button is clicked, this shows various other objects which I can then select (using a checkbox). When a checkbox is clicked, a Javascript function is called to change the html text next to the appropriate button. However, I can't get this to work as I need to pass the id of the button, and the html span, to the Javascript in order to change the correct text. Here is my Javascript : Code: function questionnum(checkbox) { if(checkbox.checked) { var qdesNumElement = document.getElementById('<?php echo $q;?>'); var qdesNum = qdesNumElement.innerHTML; qdesNumElement.innerHTML = ++qdesNum; } This code only gets the last button. Please help. ive just started really to develop my javascript out of individual functions and appreciate and help with this. I start outside of the external JS file by: reviews.init(); reviews.initialiseContent('comment'); This loads my data and loads + sets the comment tab as default. My problem is that in the external JS file (shown below) the loadTabs variable will not allow me to pass it a variable: contentDiv.onclick = this.initialiseContent; Whenever I pass a variable here it errors, am I setting this up correctly, should I be using prototype for my this. variables? Interested to hear back on if this structure of code is the right way to go about this and also how I can pass a variable in this way Thanks, Phil Code: var reviews = new reviews(); var xmlhttp; var classArray = Array('comment', 'review', 'video', 'stats', 'add'); function reviews(){ /*--------------------------------------------*/ // Setup tab events, rating and thumb content /*--------------------------------------------*/ this.init = function() { /*--------------------------------------------*/ // Load and display tabs /*--------------------------------------------*/ this.loadTabs(); /*--------------------------------------------*/ // Load and display rating /*--------------------------------------------*/ this.loadRating(); /*--------------------------------------------*/ // Load and display thumbs /*--------------------------------------------*/ this.loadThumbs(); } /*--------------------------------------------*/ // Initialise and populate tab /*--------------------------------------------*/ this.loadTabs = function() { for(key in classArray) { var contentDiv = document.getElementById( 'pp-content-tab-' + classArray[key] ); contentDiv.style.cursor = 'pointer'; contentDiv.onclick = this.initialiseContent; } document.getElementById('pp-content-tab-add').style.visibility = 'hidden'; document.getElementById('add-review').style.cursor = 'pointer'; document.getElementById('add-review').onclick = this.showElement; } this.showElement = function() { document.getElementById('pp-content-tab-add').style.visibility = 'visible'; this.id = 'pp-content-tab-add'; this.initialiseContent; } this.initialiseContent = function( tab ) { if( this.id ) { var tab = this.id.substring( 15 ); } if( !in_array( tab, classArray ) ) { var tab = 'comment'; } for(key in classArray) { if( classArray[key] == tab ) { document.getElementById( 'pp-content-tab-' + classArray[key] ).className = 'pp-tabon'; } else { document.getElementById( 'pp-content-tab-' + classArray[key] ).className = 'pp-taboff'; } } sendrequest( tab, 'loadtab', stateChanged ); } Hi, Need some help here. To formulate the problem simple i have two buttons with the onclick function: Code: <a href="#" ONCLICK="function1('this')">Click for this!</a> <a href="#" ONCLICK="function1('that')">Click for that!</a> When I click this button I actually need to pass the value 'this' or 'that' to function2.. Code: <script language="javascript"> var name = '' function1(name) { ??? } function2() { document.all.textbox.value = name; } </script> I guess what im asking is how can you set a variable by one onclick function and then use it in any other function? Thanks a bunch! Col Hi I want help with trying to pass some variables from one function to another. so with the following example: Code: // main body of script function exercise() { fnLLR_Calculate(); fnLLR_Calculate2(); } function fnLLR_Calculate() { //-------Gets values from web page------// var $Shares; _set($Shares, _getText(_textbox("CALC_STOCK_INPUT"))); $Shares = Number($Shares); _log("$Shares =" + $Shares); var $GrantPrice; _set($GrantPrice, _getText(_textbox("GRANT_PRICE_INPUT"))); $GrantPrice = Number($GrantPrice); _log("$GrantPrice = " + $GrantPrice); var $FMVPrice; _set($FMVPrice, _getText(_textbox("FAIR_MARKET_VALUE"))); $FMVPrice = parseFloat($FMVPrice).toFixed(2); _log("$FMVPrice = " + $FMVPrice); var $TaxWitholdRate; _set($TaxWitholdRate, _getText(_textbox("TAX_WITHHOLDING_RATE"))); $TaxWitholdRate = $TaxWitholdRate / 100; _log("$TaxWitholdRate = " + $TaxWitholdRate); } function fnLLR_Calculate2() { //----uses values from fucntion 1 to calculate----// $Result_Shares = ($Shares- $GrantPrice) * $TaxWitholdRate / $FMVPrice; $Result_Shares = $Result_Shares.toFixed(0); _log("$Result_Shares = " + $Result_Shares); } So i need to pass some variables from function fnLLR_Calculate to fnLLR_Calculate2. What is the best way to do this? I am developing a site that adds multiple dynamic buttons. I would be ideal if the event these buttons trigger could pass a 'variable' (the passed variable is constant with respect to each button). My attempt... myButton.setAttribute("onClick", "myFunction(" + myVar +")"); ...doesn't seem to work. Can anyone help out? Hi all, I'm quite new to Javascript, and I'm stuck with a problem here. I have a website, I won't go in to detail, but it generates some javascript code for the user. Well, that's the idea. The user puts this javascript on his or her website. Now everytime the page with that javascript is loaded, a page on my server is called, and is supposed to display something on the place of the javascript of that website. I however have not the slightest clue how to do this. The script on my server has to get some values from a database (I'll be doing this with php). Therefore are some variables needed, like ID's. Those are put in the javascript at the website of that person. (I know they could just change it, but that'd only disadvantage them) And example of the code the person with the website would get is this: (This was also generated on user basis somewhere, which does about the same thing) Code: <script language="javascript" type="text/javascript" charset="utf-8"> var border = '#000000'; id = 1337; </script> <script language="JavaScript" type="text/javascript" src="http://somesite.com/scriptname.php"> </script> If you don't understand what I'm trying to do here, please ask, because I might not've explained it clear enough. Thanks, lordstyx. [edit] Someone said to look in the direction of XMLHttpRequest. I don't really know what that is, but I'll try and find a bit more info about it. I have a concatenated list of posts like this: Code: <?php // this generates a list of divs with unique id's as $post_id's $my_posts .= ' <div class="storypost' . $post_id . '"> <a href="mystorypost.php?id=' . $post_id . '>' . $member_name . ' Post</a> <a href="#" onclick="DoAction(' . $mem_id . ', ' . $post_id . ');">Remove?</a> </div> '; ?> And here is the javascript/ajax, which sends the variables to the _removepost.php, in order to run that code, and delete the post from the database... Code: <script> function DoAction(mem_id, post_id) { var r = confirm('Are you sure you want to remove this post?'); if (r == true) { $.ajax({ type: "GET", url: "_removepost.php", data: "mem_id=" + mem_id + "&post_id=" + post_id, }); $(".storypost"+post_id).hide(); return false; } else { return; } } </script> So, the thing actually works (the post gets deleted from the database). But what does not work, is: 1) the div is not getting hidden via the .hide() 2) after I click the onClick link, the page scrolls back to the top of the page... and I have to end up reloading the page to see the change. I believe there is something wrong with where I placed the "return false;" and something wrong with how I call the variable in .hide(). Hi, There are different ways by which values of variables can be passed between forms. One of the ways is to use the setTimeout to pass the values or data. Here the biggest advantage is we can pass data to a different site even running automatically. I would need from someone a bit of help to pass the variable links from form1 to variable strLink in form2 using SetTimeout. We have the following schema: An options select menu where value of the option, sent with a submitted form, is specified with the value attribute. In the absence of a VALUE attribute, the value is the content of the option element. Quote: <html> <head> </head> <body> <form name="form1" method="get" > <select name="links"> <OPTION VALUE="http://www.as.com/">El Mundo <OPTION VALUE="http://www.atb.com.bo/">El Pais <OPTION VALUE="http://www.cadenadial.com/">Bizgrok <OPTION VALUE="http://www.cadenaser.com/">Eclab <OPTION VALUE="http://elsa.berkeley.edu/">Elsa <OPTION VALUE="http://www.caracol.com.co/">Factfinder <OPTION VALUE="http://fairmodel.econ.yale.edu/">Fairmodel <OPTION VALUE="http://www.cincodias.com/">Village <OPTION VALUE="http://www.continental.com.ar/">Levine <OPTION VALUE="http://www.literature.org/">Literature.org <OPTION VALUE="http://www.literatura.org/Gusman/frasquito.html">Frasquito <OPTION VALUE="http://www.literatura.org/Gusman/villa1.html">Villa <OPTION VALUE="http://www.literatura.org/Gusman/lgcrific.html">Mapa <OPTION VALUE="http://www.literatura.org/Gusman/lgcrific.html">Mapa </select> </form> Timing events. We are executing some code after a specified time-interval. Quote: <script> setTimeout('document.form1.links.value = document.form2.strLink.value',2000); </script> You can see in the below case the values can be posted to another form. Quote: <form name=form2 method=post action="convertx.asp"> <input type="text" name="strLink"> <input type="submit" name="btnSubmit" value="Show"> </form> By post method of form submission we can automatically send more number or length of data using SetTimeout. Quote: <script type="text/javascript" language="JavaScript"> btnsubmit = document.form2.submit(); setTimeout('btnsubmit',2000); </script> Quote: </body> </html> Any help will be much appreciated! Just he! Hi, Any one help me In one variable i have some data ex: var data = document.getElementById("imageId").value; I want to pass this data to another function inside another function ex: var button1 = '<img src="images/Remove-button.gif" width="70" height="15" onclick="removeVerifyImageRow(this),saveLibData('+data+')"/>'; while running the application i am getting an error incase if the data is string ex:if data is 'image1' i am getting an error, but with number there is no problem ex: if data is '1122'. this is very urgent to solve this problem plz any one help me Thank you in advance if someone can help. I have been banging my head against the wall for hours now. Here is the code: Code: for (var i = 0; i < BS_crm['activityTypes'].length; i++) { var clickFunc = function(){ activityList.showForm( -1, {blockType:[""+BS_crm['activityTypes'][i]['id'], "0"]} ); }; var type = { value: BS_crm['activityTypes'][i]['id'], label: "Add New "+BS_crm['activityTypes'][i]['label'], css: BS_crm['activityTypes'][i]['css']+"_16", onClick: clickFunc }; previewLinks.items.push( type ); } Now, basically what I am doing here is running through one array to create an array of objects, that will be used to create links that will use whatever onClick function I pass it. The problem is that on the second line I need the BS_crm['activityTypes'][i]['id'] to be a value, not a reference. If that line was simply changed to: Code: var clickFunc = function(){ activityList.showForm( -1, {blockType:["3", "0"]} ); }; then everything would work as I need. How can I make this happen? I would really appreciate any help. Thank you again in advance. Afternoon All, I have managed to secure some JavaScript code from another site that allows me to access values from within my Google Analytics cookie: <!-- begin Referer Check --> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write("<script src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'>" + "</sc" + "ript>"); </script> <script type='text/javascript'> var pageTracker = _gat._getTracker("UA-1-1"); pageTracker._trackPageview(); // // This is a function that I "borrowed" from the urchin.js file. // It parses a string and returns a value. I used it to get // data from the __utmz cookie // function _uGC(l,n,s) { if (!l || l=="" || !n || n=="" || !s || s=="") return "-"; var i,i2,i3,c="-"; i=l.indexOf(n); i3=n.indexOf("=")+1; if (i > -1) { i2=l.indexOf(s,i); if (i2 < 0) { i2=l.length; } c=l.substring((i+i3),i2); } return c; } // // Get the __utmz cookie value. This is the cookies that // stores all campaign information. // var z = _uGC(document.cookie, '__utmz=', ';'); // // The cookie has a number of name-value pairs. // Each identifies an aspect of the campaign. // // utmcsr = campaign source // utmcmd = campaign medium // utmctr = campaign term (keyword) // utmcct = campaign content // utmccn = campaign name // utmgclid = unique identifier used when AdWords auto tagging is enabled // // This is very basic code. It separates the campaign-tracking cookie // and populates a variable with each piece of campaign info. // var source = _uGC(z, 'utmcsr=', '|'); var medium = _uGC(z, 'utmcmd=', '|'); var term = _uGC(z, 'utmctr=', '|'); var content = _uGC(z, 'utmcct=', '|'); var campaign = _uGC(z, 'utmccn=', '|'); var gclid = _uGC(z, 'utmgclid=', '|'); // // The gclid is ONLY present when auto tagging has been enabled. // All other variables, except the term variable, will be '(not set)'. // Because the gclid is only present for Google AdWords we can // populate some other variables that would normally // be left blank. // if (gclid !="-") { source = 'google'; medium = 'cpc'; } // Data from the custom segmentation cookie can also be passed // back to your server via a hidden form field var csegment = _uGC(document.cookie, '__utmv=', ';'); if (csegment != '-') { var csegmentex = /[1-9]*?\.(.*)/; csegment = csegment.match(csegmentex); csegment = csegment[1]; } else { csegment = '(not set)'; } // // One more bonus piece of information. // We're going to extract the number of visits that the visitor // has generated. It's also stored in a cookie, the __utma cookis // var a = _uGC(document.cookie, '__utma=', ';'); var aParts = a.split("."); var nVisits = aParts[5]; /* function populateHiddenFields(f) { f.source.value = source; f.medium.value = medium; f.term.value = term; f.content.value = content; f.campaign.value = campaign; f.segment.value = csegment; f.numVisits.value = nVisits; alert('source='+f.source.value); alert('medium='+f.medium.value); alert('term='+f.term.value); alert('content='+f.content.value); alert('campaign='+f.campaign.value); alert('custom segment='+f.segment.value); alert('number of visits='+f.numVisits.value); return false; } */ document.forms["cforms2"].elements["cf2_field_1"].value = source; </script> The key outputs from this code are the vars: source medium term content campaign csegment nVisits My question is, how can I get the source var into the hidden field in the form in my footer http://www.yogaholidays.co? I have tried to pass just the source var from within the <script> tags. document.forms["cforms2"].elements["cf2_field_1"].value = source; I have commented out part of original code that I did not think I needed. Any help that can be offered I would be grateful, ultimately I would like to be able to pass all these values to hidden fields. Thanks Paul Brown How do I pass an id to a function?? Or is this even possible. Code: <html> <head> <title> JavaScript array passing example </title> <script type="text/javascript"> function init(){ display(addText1); display(addText2); display(addText3); display(addText4); } function display(var myText){ var newText = '<h2>' + "Will this change anything..." + '</h2>'; document.getElementById('myText').innerHTML = newText; } </script> </head> <body onload="init()"> <div id="addText1"></div> <div id="addText2"></div> <div id="addText3"></div> <div id="addText4"></div> </body> </html> Hi, I want to pass a javascript function's return value, to an anchor tag's href parameter i.e. <a href> Suppose I have a function called getTrackingCode( ) that contains a value "testSite" Code: <script language = "JavaScript"> function getTrackingCode( ) { return "testSite"; } </script> Now I want to pass this function's value to anchor's href, I have attempted these: Code: 1. <a href="http://www.helloworld.com/?id=" + getTrackingCode( )> 2. <a href="javascript: document.location= 'http://www.helloworld.com/?id=' + getTrackingCode( );"> So that the resulting URL becomes http://www.helloworld.com/?id=testSite But none of the procedures work. Please help me do it. NOTE: Please note that I can't use the function with document.write to write the whole tag because that would be very hard to manage as I will have to use it in case of text links, image links, hotspots etc. and for each I would have to write a separate function. Furthermore, I don't want the Status bar of the browsers to show something like javascript:location.href (); etc. I want the actual href link to be seen in the Status bar, as if no javascript manupulation is done. In a nutshell, the code should be reusable for the href paramater in anchor tag's href of any element, be it a text link, image link, script link, hotspot or link area and doesn't show javascript function calling in the Status bar of the browser. I've heard that I can do such a thing using ElementbyID etc. but have no idea. Please help me with this, Thanks much! |