Implementing A Variable's Value Inside A Function
Jan 9, 2008
I'm making a project which creates tabs with a class. I don't really know how to explain it better but this is how it works:
<a href="#" id="tbs_tabs">Create</a>
<script type="text/javascript">
var tbs = new Tabs('tbs_tabs');
tbs.theme = 'classic'
tbs.create_option('abc','#');
tbs.create_option('abz','#');
tbs.create_option('abf','#');
tbs.create();
</script>
It first creates the new class and tells it the id, then it creates as many options as you want and creates it.
My problem is with this line:
for(i=0;i<this.option_values.length;i++)
{
li = document.createElement("LI");
li.appendChild(document.createTextNode(this.option_values[i]));
addEvent(li,"click",function(){oThis.select_option(i); return false;};
ul.appendChild(li);
}
What I was trying to do here is add an event to the LI element that refers to the current tab class but doesn't use the CURRENT i value but the value that was when the event was first created.
For example.. If my i value is currently 2 and I add the function, then I want that when I call the function, the value will still be 2 and not the current i value. What happens now is when I call the function the value is something like 5 or 6.
View 2 Replies
ADVERTISEMENT
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
Jun 19, 2010
I have a grid of items that when clicked lead to a new page. I would like to implement a function so that if a user clicks on an item and holds for at least 1000ms, a menu will be shown next to the item and they will not be taken to the next page.
However, all of my current attempts either lead to the menu not being shown, or it is shown and the user is redirected to the next page anyways.
Here's my current code:
jQuery(document).ready(function(){
var mousehold;
jQuery('.item').mousedown(function(){
[Code].....
View 4 Replies
View Related
Oct 28, 2011
I'm trying to create a small javascript menu.I have 4 images which serves as menuitems.
<div class="myMenuButton"><img goes here />
<div class="myMenuContent">
Random content1 here <br />
is there a simple way of implementing a slider function to the images to toggle slide up/down the contents belong to this button? And if another image is clicked then all OTHER open slides should be closed while opening this one etc
View 3 Replies
View Related
Jul 15, 2010
there,is possible to do some math in this type of selector:
$( ' li:eq (0) ' ) like this $( ' li:eq (some variable + 1 ' )
View 2 Replies
View Related
Aug 12, 2011
we have a list of names, generated by parsing an array JS source file.The site and the main page is ASP, linked to a Database.Is there a way to store the JS-generated text, inside the Database?To be more clear:Code:
<!-- excerpt from mypage.asp -->
<script type="text/javascript">
// VariableNames are an array result, but here we list a simple example:
[code]....
View 1 Replies
View Related
Apr 30, 2007
I've always wonder if there is diference when declaring and
initializing a varible inside/outside a loop.
What's a better practice?
Declaring and initializing variables inside a loop routine, like this:
for(var i=0; i<list; i++)
{
var name = list[i];
}
or outside a loop routine, like this:
var i;
var name;
for (i=0; i<list; i++)
{
name = list[i];
}
or are both the same....
As a programmer, i always try to practice good programming. I always
thought that by declaring and initializing the variable inside the
loop, i was creating a new memory space every time instead of just 1
time...
What do you think?
View 8 Replies
View Related
Aug 29, 2011
I am having a strange problem with a javascript function that does not return the value but returns the code inside the function. My best guess is that I am incorrectly calling the function hasLandedOn()and jquery is interpeting it. Why is this happening? I highlighted the parts in red.-Tom ReeseThe following is returned NOT the variable imageName.
function hasLandedOn(){
var selectorLoc = $("#selector").offset();
var imageName = "";
[code]....
View 2 Replies
View Related
Jan 17, 2011
I have what I think is a strange issue but others may see something I am missing.I am using AJAX functionality to process a php script on a server and then place the output of the script into a div element.Here is the code snippet
Code:
function doWork13(typeCode,colorBlockName,objectCategory,imgID){
httpObject = getHTTPObject();
if (httpObject != null) {[code]....
This code shown here works perfectly BUT....I do not want the alert message to be there. When I remove that line of code the script fails to function. There is no error just nothing happens.The function is to replace one image with another and the variable in question is simply the ID tag of the particular image being modified.As I said it works with the alert but does not with out, could it be a timing issue in that the alert gives enough time for the if statement in the setOutput13 function become TRUE
View 6 Replies
View Related
Feb 3, 2010
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'.
View 7 Replies
View Related
Feb 10, 2010
Here is the 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 = {
[Code]....
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:
var clickFunc = function(){ activityList.showForm( -1, {blockType:["3", "0"]} ); };
View 4 Replies
View Related
Feb 3, 2010
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'.
View 5 Replies
View Related
Apr 27, 2011
The inside alert works, but the outside one says undefined. Need halps please.
coder = new google.maps.Geocoder();
var coded;
function codeAddress(address) {
[code]....
View 8 Replies
View Related
Jun 15, 2007
In jslint's doc it says, "JSLint does not expect that a var will be defined in a block. This is because JavaScript blocks do not have block scope. This can have unexpected consequences. Define all variables at the top of the function." What are some of those unexpected consequences?
View 1 Replies
View Related
Sep 13, 2010
i declared 2 variables which i want to use depending on a conditional statement inside a jquery function unfortunately they don't seem to be working. do they need to be globals?[code]i know for a fact that the code works, when i add an alert inside the conditional statement it pops up fine, but these variables don't seem to get their values applied.
View 2 Replies
View Related
Jul 20, 2010
How do i get a variable from one function into another function. I am new to javascript.
Here is my code ...
View 4 Replies
View Related
Oct 11, 2010
I'm trying to reuse a script I have but, I'm not able to due to the fact I can't use some variables in a function.
I would like to know why I am not able to use passed variables in javascript.
For example: I call a function submit_data( 'newDomainForm', 'add_domain', 'list_div' ), in the function itself I would like to use the form name (first variable passed) as document.form.domain_name.value.
Later on I would like to use the div id: list_div in document.getElementById( div_id ).innerHTML. This doesn't work.
I have to put the name of the actual div like this: document.getElementById( 'result' ).innerHTML
And to get the value of a form element I have to put the actual name like this:
HTML Code:
View 9 Replies
View Related
Dec 2, 2011
I'm looking for examples of variables.
This is what I have. Does this make sense?
function formValidator(){
View 3 Replies
View Related
May 2, 2010
urrently I have the user log in, choose their character, and then go to a page where they can fight random monsters. When they get to the page to fight with the random monsters, the character's information as well as the random monster's information is pulled from tables in my database.
What I would like to do is when the user clicks the Attack button, perform a function that takes the monster's hp ($hp) and subtracts from it the character's attack combat value ($acv1).
how I can access the php variables within my JavaScript code and how I can go about doing this type of calculation?
I'd like to store the monster's hp in a javascript variable, so that when the character attacks, the hp can be updated until the character has reduced the monster's hp to zero, in which case a php script should be run that updates the character's table.
View 1 Replies
View Related
Sep 5, 2006
What i want is this div to expand:
<div id="info"><a onclick="Effect.toggle('toggle','Blind')" href="javascript:void(0)">More Info</a>
and show the rest of the content, for example it will say "More Info" when the user clicks it will toogle down and reveal the rest of the content which for example sake can be "Heres more info".
View 2 Replies
View Related
Nov 4, 2010
is there a way in jQuery to bind variables to function calls similar as prototype.js does it? See [URL]
E.g. in the slideUp method of jQuery you can specify a callback that is called after the effect has finished. I would like to bind a variable to this call so that it is used inside of this callback as a closure.
View 2 Replies
View Related
Oct 19, 2005
Below is a stripped down example of code I'm using to count links in a
list. My intent with the ShowLinkNumber() function was to display the
number of the current link. (e.g. click on link 2, and the message "2"
pops up; click on link 4, and you see a "4.")
For reasons I can't trace, my function always displays the last number
in the list. Why does it do this, and can anyone suggest a way to
achieve my goal without adding markup? Code:
View 3 Replies
View Related
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
Jun 15, 2010
I've got the following source code: function MyMenu()
[Code]...
I wish to execute the lambda function given at menuEntries[i].action. The list is build, but at a click i've got the error that menuEntries[i] is not defined. What should I do? I think
View 2 Replies
View Related
Mar 30, 2010
Im trying to do the following thing, I have a function in javascript which I want to use to call anAJAX event, during this event the variable that is set in the function needs to be passed to the file called by the AJAX event. Basically I create 2 different versions of the same stuff inside the AJAX called files using the variables. But im running into some cross browser related issues, this all works fine in FireFox. However in Internet Explorer it sometimes works but gives javascript errors on line 99999ish. I have the following setup:
My index (currently calling startExample via onclick):
var exampleTest = 1;
function startExample()
{
example = exampleTest;
[Code].....
View 3 Replies
View Related
May 24, 2010
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
<html>
<head>
<script language="javascript" type="text/javascript">
function popitup(a)
[Code]....
In short, I just want the pop-up page to print 'Hello there Toby' or whatever name I choose to pass across. The 'testpopup.html' url is just the initial webpage.
View 2 Replies
View Related