Accessing Variable From Within Function?

Aug 23, 2010

Is it possible to print out the variable from within a function? In this particular case, I am trying to show the 'soundfile' variable I set in the playRandomSoundNoWindow function.

View 11 Replies


ADVERTISEMENT

Accessing Variable From Another Function?

Jun 9, 2009

I have the following function:
function containsurl(index){
var theurl = "[URL]";
..
}
I need to use the theurl variable in another function, how can I do that?

View 2 Replies View Related

Accessing A Variable Defined In A Function, Outside The Function?

Sep 18, 2010

I'm making some changes to a google chrome extension I made and am having some trouble. Heres my code on a content script page (removeAttr.js) :

chrome.extension.sendRequest({greeting: "whitelist"}, function(response) {
var whitelist = response.whitelist;
console.log(response.whitelist);//working
});
alert(whitelist);//alerts "undefined"

How do I acess the whitelist variable from outside the sendrequest() function?

Iv tried saving it to a window.var variable with no luck. Iv tried creating a div and assigning it's innerHTML as the whitelist variable and getting it later with no luck. The fact that it's a chrome extension complicates things because i dont actually know if i can create elements from where the script is located.

View 7 Replies View Related

Accessing A Variable Through A Form Name

Jul 23, 2005

I have 2 arrays:

var A1 = new Array();
A1[ 0 ] ="Y2";

var B1 = new Array();
B1[ 0 ] ="Y1";
B1[ 1 ] ="sink";

I also have a drop down menu with the names of the arrays. Say:

document.form.option[1].text returns 'B1'

Can I transform the string 'B1' into the array B1, so that:

document.form.option[1].text[1] returns 'sink'

Currently I'm doing this with conditionals, e.g.

if(document.form.option[1].text =="B1){do stuff}

but this gets a bit messy.

View 2 Replies View Related

Accessing Javascript Variable In Xsl

Jul 23, 2005

I have this problem in xsl wherein i want to access a variable in
javascript and use it my xsl. How would i access or use a javscript
variable in my xsl file?

View 5 Replies View Related

Accessing Hidden Variable In FIREFOX

Jan 13, 2006

In some hidden variable (<input type="hidden" name="hiddenId"
value="test" /> ,i stored some value.I accessed the value "test" using

var id = document.getElementById( 'hiddenId' );

It is working fine in IE. But in Mozilla Firefox , null value is
returned.Is there any way to use hidden variables compatible to
browsers......?

I don't know browser compatibility in javascript.

View 19 Replies View Related

Accessing Value Of String Variable In Assignment

Sep 26, 2011

I am new to Javascript but fluent in C++ and other languages, I have a query, I made a global variable to hold string information, can the value of this string be assigned to a form input field value? I mean in the 'default value sense' I am just wondering if there is any syntax to accomplish this. EG in my javascript I have the string nameVal; It is a global variable, I would like to know if it is poosible access its value for use in the line below shown with italics, or is it basically always a case of 'type the value in manually yourself' and then rely on events functions to update the field thereafter?
Name: <br><input type = "text" name = "nameField" size = "50" value = my string val here onChange ="this.value=storeVal(this.value, '0')"></input></br>

View 5 Replies View Related

Accessing Variable In Hover Event

May 13, 2011

In hover, the structure is
Code:
$("div.x2").hover(
function(){
var a = 1;},
function(){
alert(a);}
);

If I want to access a that was set in the mouseover part of this structure, or I want to change the value of a from the second function, do I have to create a global variable that can be accessed by both or is there a way to pass this variable back and forth between the two functions since they are both within the hover event?

View 2 Replies View Related

Accessing Dynamic Script Variable

May 10, 2005

i have script variables which are generated through a loop and i have a function which should return me the value of particular variable given a key as input to that function
Here is how my code looks like:

<script>
variable_0 = 'avlue1' ;
variable_1 = 'value2'
variable_2 = 'valeu3'
...........

function getVaribleValue(id)
{

// here i want to return the value of the particular variable given id as 0,1,2 .........

return (variable_id); // this is not working

return ('variable_'+id); // this is also not working
}

return (variable_id); gives an error as it expects a variable with name 'variable_id'

return ('variable_'+id) will give me a string named 'variable_id'

but how to get the value of the variable_0/variable_1 ......... by just replacing the id and looking for that variable.

View 5 Replies View Related

Two Select Boxes - Accessing Variable In HTML

Mar 15, 2009

I have two Select Boxes on my web page, 2nd being populated based on selection of first select box. Now I am suppose to get the selected value of 2nd Select and put it in a link i.e.
Code:
<a href='abc.html?id=<2nd select box value>

I can get the selected value using Javascript with the following code:
Code:
2ndid = form.2ndodf.options[form.2ndodf.options.selectedIndex].value;
Where 2ndid is a global javascript variable.
How I can use this variable into <a href> tag.

View 3 Replies View Related

Accessing Width Variable - Returns Undefined

Feb 13, 2009

I am trying to access the width variable from my main page. Within the imageinfo.js script functions I can alert() the width value which returns 1024. But I can't seem to pass this variable to my main page or access it directly so that I can use document.write() to write the variable on the page. Whenever I try to call the 'width' variable directly from the main page I get undefined. How can I access this variable? However, with the test code below, I was able to get ducument.write() to write the 'width' variable on the page but now the page doesn't stop loading - there's an endless loop in the code...

Code:
BinaryAjax(url,function(http) {findEXIFinJPEG(http.binaryResponse);test(width)},null,useRange ? [0, Range] : null);

Main page
Code:
<html>
<head>
<script>
function test(width){
document.write('Image Width = ' + width)
} </script>

<script type="text/javascript" src="binaryajax.js"></script>
<script type="text/javascript" src="imageinfo.js"></script>
</head>
<body>
<script type="text/javascript">readFileData('image.jpg')</script>
</body>
</html>

Imageinfo script - This script uses the binaryajax script found below.
Code:
/*
* ImageInfo 0.1.2 - A JavaScript library for reading image metadata.
* Copyright (c) 2008 Jacob Seidelin
*/ .....

View 22 Replies View Related

Jquery :: Accessing Object Using Variable String

May 8, 2011

I have an object whose name is mural. I have assigned the name mural to the title of an anchor element. When user clicks and element I want to store the title of the anchor in a variable called sprite. I then want to access that object whose name corresponds to the sprite variable string.

Here is my code:
HTML Code:
var mural= new Object();
mural.top='0px';
mural.left=-'510px';

var stamps= new Object();
stamps.top='0px';
stamps.left=-'1886px';
var sprite=$(this).attr('title');
$(".image-holder").css("background-position",'sprite.top, sprite.left');

It's not working because the the variable sprite is just a reference to $(this).attr('title'), how do I make it reference the object? Oh and I know that .cc jquery statement probably wont work, I'm not sure yet of the correct way to have two values that don't need quotations in as the second argument.

View 1 Replies View Related

Accessing Global Variable - DropDown List

Apr 3, 2010

I'm trying to pupulate a web page with javascript. I have 2 functions. One that runs on-load so I can populate a dropdown list. The second one to process the selection when the user selects an item from the list. I have a global variable in the top of my javascript that I use in the functions and as long as I set it in it's global scope, everything works fine. But what I really want to do is to pass this into the javascript running on this page via [URL]

I cannot get this to work. First here is what I have that works:
<script type="text/javascript">
weekNumber = "00"
function processSelection(sel) {.....
... [includes references to weekNumber]
.....}

function populateList() {
...
}
window.onload = populateList;
</script>
...
<select name="team" onchange="processSelection(this)">
...

I've got the code to gets the variable passed in properly:
var sGet = document.location.search;
sGet = sGet.substring(1); // Eliminate the leading "?"
var sGetPairs = sGet.split("&") //Get 1st pair
var sGetValue = sGetPairs[0].split("="); //Split it
var weekNumber= sGetValue[1]; //Save it

Where do I put this code so that I can use it to set the global variable "weekNumber"? I've tried putting this code in the populateList function. I've tried referencing it via window.weekNumber and this.weekNumber. I've spent far too many hours trying to understand this without success. Where to put this code so I can set the global variable weekNumber?

View 2 Replies View Related

JQuery :: Accessing Variable Earlier In Page?

Feb 3, 2011

We have a web site provided by the software company that created our vacation rental management software, so, as such, I don't have entire control over the pages -- just bits and pieces. They recently started including jQuery 1.4.4 along with jqueryUI and cookie plugin on the pages and utilizing it a bit (as well as a custom jquery bit of code they wrote up). here's the relevant code (that I have control over):

HTML Code:
<script type="text/javascript">
var phoneflat = $.util.getCampaignPhone('MCPH').replace(/[^0-9]/g, '');
if(phoneflat=="null"){var DNISPh='88812345678'}
else{var DNISPh=phoneflat}

[Code]....

Basically, we have a phone-number tracking system on our Web site, and the toll-free number on our site gets replaced depending on how the MCPH cookie is set. The above code pulls formatted number from that campaign cookie, removes the formatting from the number, and sets the pop-up URL to include the number, passing the number after the "?DNIS=" (which is required for this specific campaign tracking to work properly).

This all works fine and dandy if the jquery and cookie code is all before the above code snippet on the page, but the developers of the software are trying to follow best practices and are loading all the javascript files at the end of the page, and this is far earlier in the page. So there's really no way for me to pull that ".util.getCampaignPhone('MCPH')" as the cookie may not have been set yet, nor is the campaign data ready.

View 2 Replies View Related

JQuery :: Ajax Post - Accessing Return Data / Result Variable

Nov 30, 2010

So I'm currently working on a ASP.NET Webforms site and I've run in to a small problem. On my .cs file I have the following Webmethod

[WebMethod]
public static string IsJobEditable(int jobid){
try{
string isEditable = "false";
JobsBLL jbl = new JobsBLL();
int jobStatusId = jbl.GetJobStatusId(jobid);
//If the jobs is either waiting or being edited it is
okay to edit it
if(jobStatusId ==
Convert.ToInt32(ConstantsUtil.JobStatus.Waiting) || jobStatusId ==
Convert.ToInt32(ConstantsUtil.JobStatus.Edit)){
isEditable = "true";
}return isEditable;
}catch (Exception ex){
throw ex;
}}

This function in this case will ALWAYS return TRUE as a string. On Aspx page I have the following
$(function () {
$.ajax({
type: "POST",
url: "Coordination.aspx/IsJobEditable",
data: "{jobid:" + jobid + "}",
contentType: "application/json; charset=utf-8",
dataType: "text",
success: function (result) {
alert(result);

//This is written out in the alert {"d":"true"}
I want this in a variable as a string so I can do a check on it before I do some other actions. The format is not a String so I cannot split on it to retrieve the "true" part.
},
error: function (err, result) { alert(err); }
});});

As you can see in the comments the value I get back in the Callback method is in to me a weird format. The type is unknown and I need this value to be able to proceed with my entire method surrounding the small portion of the Javascript. Where to access the result variable / data as a var or anything else that will let me put it into a var (as a string).

View 1 Replies View Related

Accessing Function Through URL?

Apr 3, 2009

all on the same page that are accessed by the classic show/hide DIV functionality.

So user clicks button 2, which shows story 2, hide stories 1 and 3. (all on the same page).

The issue is that I've been asked to provide a method to directly link to story 2 or 3, which currently isn't possible since you need to load the page, then click the button to show story 2 or 3 (naturally 1 loads by default).

So I'm looking for any method to go right to story 2/3 from a link.

Perhaps I can pass a variable through the URL which executes the function as soon as the new page loads (which would mean a quick double page load but I could handle that)

Here's the function:
var showMe = function(me) {
document.getElementById(me)["style"]["display"] = "block";
}, hideMe = function(me) {
document.getElementById(me)["style"]["display"] = "none";

[Code]....

View 9 Replies View Related

Accessing Var Via Another Function

Oct 21, 2011

I'm not an ace JSer by any means--the problem I'm about to pose could easily be solved with pointers in C++ (the language with which I am most familiar), unfortunately that is not an option.I am making a webapp using the google visualization API:URL...My problem may be related to the API, but I think it's more Javascript oriented--the Google group for the API is helpful,I have a function, drawDash(), which declares some elements of the visualization, some filters for the visualization, then binds them together and draws them. Now what I need to do is access the elements of one of those vars, specifically a filter, and add/change properties of it with an HTML form.

I've set up an onclick function for a set of checkboxes in my form that calls another function. The problem I face is that I can't really access the filter correctly.[code]So basically, I want to have a function be able to edit the var serviceSearch from another function.

View 4 Replies View Related

Accessing Array From Function

Jul 9, 2007

<script type="text/javascript">

function popsizes(colorcode) {
var BLK=new Array();
BLK = ["2XL","3XL","4XL","5XL","LG","MD","SM","XL","XS"];

elem = document.getElementById("selcolor");
for (i=0; i<elem.options.length; i++){
sizelist = colorcode[i];
document.getElementById("selsize").options[i] = new Option(sizelist);
}}

</script>

In an event, i'm passing in "BLK" as the colorcode param. This is creating my selsize select box with B, L, K, and undefined options until the for loop finishes. ie, its taking the passed in colorcode as a literal string, instead of referencing the array. Anyone have a pointer as to how i can access the arry, instead of the literal string?

View 1 Replies View Related

JQuery :: Accessing Variables Outside Of Function?

Apr 21, 2011

I don't know what I'm doing wrong probably pertains more to Javascript than jQuery.Why can't I access the 'myVar' variable my clicking 'myButton2'?

View 5 Replies View Related

Accessing Global Arrays From Within A Function In IE7?

Feb 8, 2011

I have a javascript function that dynamically generates a select menu based on the region that was previously selected.

Code:
/* Inside my functions.js file I have this function */
function createCountrySelect(regionID, selectID, msg, defaultCID) {

[code]....

View 2 Replies View Related

Accessing Variables Inside A Function?

Sep 19, 2010

I've attached a cut-down version of a script I am working on. It's a pretty simple button with a function attached, which creates a random number and compares it with a preset value.I can't seem to get the function to read the variables

Code:
#<html header>
<script language="javascript" type="text/javascript">

[code]....

View 7 Replies View Related

Declare A Variable Inside A Function - Returns White Space - Not Variable Value

Aug 17, 2010

I am trying to declare a variable inside a function and use it later on in my code... but it just already returns white space... i.e. not variable value. I am setting it within this function:

function show_video1(){
document.getElementById('video1').style.display="block";
var video1Name = "Education World News (Part 1)";
document.getElementById('video2').style.display="none";
document.getElementById('video3').style.display="none";
document.getElementById('video4').style.display="none";
[Code]...

and trying to call it later on with this: <script type="text/javascript">document.write(video1Name)</script> It might be worth noting that each one of my 11 videos will hace a different name.

View 13 Replies View Related

JQuery :: Accessing Variables That Are Outside Of My $.get(str, Function(data){ ....?

Nov 2, 2010

var attrIndexes = [];
$.get(queryString, function(data) {
attrIndexes = data.split(",");
});

after running this code the original variable is empty so something is wrong

View 3 Replies View Related

JQuery :: Accessing The Function Of An IFrame Parent

Jan 5, 2011

In parent window

function f1()
{
..code..
}

Inside IFrame

$(document).ready(function()
parent.f1;
);

The above works without any problem But,I am getting the "TypeError: f1 is not a function" on accessing the below code

[Code]...

View 4 Replies View Related

Accessing Global Variables - Function DisplayResults - ImageArray

May 5, 2009

I've got a function displayResults(imageArray); that first calls removeElements(); to get rid of the currently displayed list items. Both functions are part of class function eventBox(array, string, date). both displayResults(imagearray); and removeElements(); have been bound to eventBox(); by e.g. this.removeElements = removeElements;

However, from within displayResults(imageArray); this.removeElements(this.identifier + "eventsul"); evaluates to "undefined". Also, this.identifier called from within the function also evaluates to undefined (it doesn't in other functions). For some reason I can't access global functions and variables from displayResults(imageArray);. Any ideas?

Here is the code for displayResults(imageArray); :

View 1 Replies View Related

JQuery :: Use A Variable Declared In A Function Outside A Function?

Nov 17, 2011

So I've got this checkbox thing going on, where an array converted with the value of each checkbox in it.It looks like this:

[Code]...

What I want out of this function is the variable newworkdays to use in another function.

How do I access the "newworkdays" outside the function? I've already try to declare the variable outside of the function, though that resulted in that I didn't get the value of the variable inside the function.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved