Event Driven GUI, Looping Through An Array

Sep 9, 2006

I have an associative array that I need to loop through, allbills,
however, each element in this array requires processing by the user and
I need to capture the users actions on the element and then return to
the next element in the list but suspend looping until I have the users
desired action...

For example,

for(mybill in allbills)
{
GetWhatToDo(mybill); // gets the information about what user wants to
do with the currentBill
}

The problem is that the function "GetWhatToDo" doesn't "block" so the
loop completes without waiting for the users input from GetWhatToDo...

So, my thought was I need to design things more 'event-driven' and
handle things like so:

function handleABill() {
mybill=GetNextBill();
GetWhatToDo(mybill);
}

A "Next" button inside the popup generated by GetWhatToDo will have an
onclick event that calls handleABill again...

The problem is that I can't figure out how to write GetNextBill so that
it maintains the state of the loop through 'allbills', especially since
'allbills' is an associative array and I can't keep track of the array
index. The only thing I can think of is to initialize a regular array
from the associative array and keep track of the index number.

View 1 Replies


ADVERTISEMENT

Event Driven Js In A Form

Jul 23, 2005

so is it really possible to have a javascript app that runs when a
"go" button is clicked (ie requiring a <FORM> tag) inside a form with
a "submit" button? seems so simple, can't figure it out without doing
illegal nested forms.

View 1 Replies View Related

Create 2D Array Driven Drop Down Menu?

Oct 18, 2010

What I'm trying to do is create a document which allows you to select a size of box from a drop down menu, and then select a size of product to go into the box on a second drop down. The products on the second drop down menu will be allocated based on the box size that you've selected to make sure that you can only choose products which will fit in the box you've selected.

In order to do this I've set up a 2D array, which lists each product and which boxes they will fit in using 0 for no and 1 for yes. When you select a box size from the drop down a value appears in a text box next to it (1, 2, 3, or 4) and what I need to do is use the number which appears in this text box to pull data from the array to populate the next drop down list. i.e. If option 2 appears from the first drop down selection then the second drop down should be populated with data from column 2 of array (In this example 1212, 1515, and 2020 would be shown in the second drop down)

Im having trouble with the Java script to pull the values from the html text box in order to manipulate the array. If you look at the function 'top_biochill_addOption_list()' you will see that the second drop is populated here from row [itop2][3] of the array, which means the second drop down is permenantly populated as if option 3 had been selected from the first drop down. I need to get the value selected from the first drop down as a variable and replace the '3' in the above statement with that variable to get this to work but I have no idea how to go about that.

Hopefully all will become clear when you see the code. As I say, I am very new to Javascript so I'm sure this code is probably messy and inefficient, but with that in mind I'd appreciate replies being in simplified terms so I can understand what you're getting at, or if anything gets re-written then a brief explaination of whats going on would be handy so I can understand what the code is actually doing!

<html>
<head>
<script type="text/javascript">
var linebreak = "<br />";

[code]...

View 9 Replies View Related

JQuery :: Looping Through Array Using Each

Jan 26, 2011

If got problem with .each looping in jquery. im am trying to make a animation with jQuery. And i want to switch between three quotes of the array. and now it only works for the first quote of the array.

[Code]...

View 2 Replies View Related

Looping Array Of Objects In IE6?

Jul 7, 2009

Well let's say i have a bunch of div tags with name attribute 'hello'

<div name='hello'></div>
<div name='hello'></div>
<div name='hello'></div>

I want to use JavaScript so that i can look through the array of these div objects.

var helloDivs = document.getElementByName('hello');
var len = helloDivs.length;
.....

So, it works for all the recent version of browsers but not for IE6. There is still about a 10% market share who are still using IE6. What is the workaround for this browser support?

If i were to print the variable len in IE6 says that is 0 and if i print helloDivs, it says it is an object as if helloDivs is a variable that contains an object but not an array of objects.

View 4 Replies View Related

Possible To Search An Array Without Looping Through All The Elements?

Aug 24, 2006

Is it possible to search an array without looping through all the elements?

hoping for something like this;

myarray.exists("one")

which may return the element number or a true or false depending if the element being searched exists.

View 14 Replies View Related

Looping Through An Array To Find Highest Value?

Jun 28, 2010

<SCRIPT LANGUAGE = "JAVASCRIPT">
var contestantNamesArray = ['Tom and Nazia', 'Pat and Dan', 'Sandra and Kofi', 'Ian and Adele', 'Paul and Costas'];
var judgesPointsArray = [2,1,5,4,3];

[Code]....

Basically i need it to loop though the array and find who has the highest points / if more than one have the same points so i dance off is required.

View 7 Replies View Related

Looping Through Arrays: For/in Versus Using Array Length?

Aug 3, 2009

I'm a JS beginner and I find looping through arrays with for/in is very easy. Yet I find lots of code examples where array length is used instead of for/in and I'm thinking to myself, why do it this (somewhat) hard(er) way?

View 11 Replies View Related

JQuery :: Doesn't Looping Through An Array - Always Prints The First Item

Jun 7, 2010

I don' t know what I'm missing here..

$("div#carousel a").each(function(i) {
$(this).click(function(e) {
e.preventDefault();
console.log(myArray[i]);
});
});

it doesn't loop, it always prints the first item in the array (there are 18 <a>'s inside div#carousel, and 18 items in the array...)

View 4 Replies View Related

Looping Through An Array Of Images, Called With SetInterval Method?

Apr 24, 2011

I have an image sitting in a <td> tag, and I want the image to change every 5 seconds. I have a total of 3 images that I need to cycle, and I need it to go back to image1 after displaying image3 for 5 seconds.

I want to call the changeAd() function from the setInterval method within the startAdPAge() function because I am going to be adding more statements to the startAdPage() function, so the body onload event will call the startAdPage() function, which will in turn, call all the other functions.

I was using an if/else statement in the changeAd(), but that only changed between image1 and image2, so i am trying this array, but now it is not changing at all.

[Code]...

View 3 Replies View Related

JQuery :: Conditionally Looping Through Array - Determine If The Function That Runs The Ajax Call Has Succeeded Or Not?

Oct 11, 2011

I've got an array of names, and one ID. I need to run an ajax call using the ID and each lastname, until I get a successful hit on the ajax call. I can't quite figure out how to determine if the function that runs the ajax call has succeeded or not, it always returns false for me... Here's the code for the loop:

[Code]...

View 2 Replies View Related

Looping Through Array - "test" Alert Displays For Both 13 And 14 But The Second Drop Down Only Appears When Selecting ID 14

Oct 15, 2009

function loadSecondaryNetworks() {
var secondaryNetworks = new Array('13','14');
var select_list_field = document.getElementById('network');
var select_list_selected_index = select_list_field.selectedIndex;
var value = select_list_field.options[select_list_selected_index].value;
value = value.split('-');
[Code]...

this code is supposed to display and load a secondary drop down menu if a particular ID(13 OR 14) is selected from the first dropdown. it works fine for 14, but not for 13. the "test" alert displays for both 13 and 14, but the second drop down only appears when selecting ID 14. I changed my array to ('13','14','13') and then it worked for both 13 and 14. is there something i am not aware of?

View 1 Replies View Related

JQuery :: Toggle And Driven Content?

Dec 6, 2010

jQuery and based on a tutorial for a toggle function I want to do a toggle with a dynamic content for the collapsed DIVs. My code looks like that:

$(document).ready(function(){
//Hide (Collapse) the toggle containers on load
$(".toggle_container").hide();

[code]....

View 4 Replies View Related

SetTimeOut - DHTML - CSS Driven Zoom Feature

May 25, 2010

I have a CSS driven zoom feature which shrinks a large image down to a specified size and when hovered over, the image enlarges to its full size. I need to be able to either make it stay opened (enlarged) when clicked, unless it is clicked to close OR to have the hovered (enlarged) image on a time delay to stay open for a specified amount of time.

I have already tried 2 scripts that I've found, but they are very over-complicated for what I need.

I thought, I'd only need to put something in the <a> tag or <img> tag, but I'm so new to Javascript and it is wearing me so out that I'm exhausted.

I did, however, get the effect that I wanted when I applied a:Active, instead of a:Hover) - It's just that can't get the image to close upon a second click.

My guess is that I need a js with an if open then onclick close it - but I'm not sure how to construct it or exactly where it wiill go.

Here is the CSS that operates the zoom (external CSS):

Code:

Here is the markup for the image:

Code:

The example can be seen here: [url]

View 8 Replies View Related

Creating Basic Data-driven Combo Boxes?

May 27, 2009

Here is the link to a page on my work web: -

[URL]

You will see that I have three combo box objects on this form - one containing dates (Date) and the other two containing times (Time1 & Time2). Each time on each date is an available appointment.

I would like the content of the date combos to be read from a file whenever the page is opened - a text file with one record per row would be fine (by way of an example - but this may be insufficient). On the face of it this would seem fairly rudimentary but I don't code in JavaScript of PHP and, having found this site I can make a start. I used to be a VB coder.

On each date the following appointment times are available: -

10:00
11:00
12:00
14:00
15:00

This assumes that no appointments on a given day are taken.This leads me to conclude that each date should have records for each time - possibly as a CSV text file as follows: -

"29th May 2009","10:00"
"29th May 2009","11:00"
"29th May 2009","12:00"

[code]...

The second time combo should make unavailable the time selected in the first time combo and present only those times available on the chosen date in the CSV file on the server.When I confirm appointments, at present I have to edit the page objects and update the web - which is quite messy and slow whereas uploading a simple text file, whilst an imperfect solution, is much better than what I currently have.

I believe that a PHP or Javascript routine based on events on the three objects would remove the inherent problems and would provide a useful set of building blocks for other routines of a similar nature.The routine would trigger whenever the page is loaded (or refreshed) or the content of any one of the three objects gets or loses the focus or a selection is made in an object.

The Date Combo would need to look up the available dates - keeping the currently selected date selected or, if that date is no longer available defaulting to the first date in the list. The user then makes a selection or makes no change to the selected date.The Time1 Combo then reads the available times for that date, retains the currently selected time (if available) or the first available time (if the selected is not available) and the user makes a selection or accepts the current selection.The Time2 Combo does the same as the Time1 Combo and in addition it eliminates the time selected in the Time1 Combo from the available choices.

The result is that visitors are only offered available times on available dates (insofar as this solution provides).When the form is submitted I would receive the email and confirm the appointment with the client and, in addition, I would modify and upload the modified data file to the web server using Filezilla. The benefit is that there is a slim to none chance of two people wanting to book the same times on the same date at exactly the same time (though it is possible). In addition, I can add new dates and add new times if there is a demand and I can even add previously deleted times if there is sufficient demand to warrant bringing in a second consultant to take the meetings.

View 1 Replies View Related

JQuery :: Dynamically Load Data Driven Html Page?

Jun 30, 2010

So here is my problem...I've been banging my head against the wall for days with this one.How do you send data through the URL to be handled by a script in page.html, where page.html processes the data and dynamically displays the data in a modal. I can get the script to execute without trying to display in a modal, but as soon as I attempt to display in a modal, all I get is the static HTML without the jquery dynamic html.I know some code should be given, but if anyone could just walk me through the logic of why static html might be shown but not the dynamic, I think i can figure it out.

View 1 Replies View Related

JQuery :: Simple Replace - Rendering Some CMS-driven Content With Empty Paragraphs

Feb 1, 2010

I have a site which is rendering some CMS-driven content with empty paragraphs. I'd like to remove these spaces dynamically with jquery. I'm trying this but it doesn't work:

How to just replace all occurences of '<p> </p>' within nothing (i.e. remove them)?

View 1 Replies View Related

Using Array Values In Onclick Event

Jul 23, 2005

Can a javascript array value be used in an onclick event?
I haven't been successful in getting it to work so I'm wondering if it
even can be done.

onclick="calculate('some array value');

I've tried:
onclick="calculate('<script
type="text/javascript">document.write(points[0]);</script>');

There's conflict with the quotes, but beyond that, I'm unclear if this
is even a viable option...anyone?

View 9 Replies View Related

Passing An Array Into An Event Handler?

Apr 28, 2011

I'm having trouble passing an array into an event handler.This does not work:

var lightbulb = [1,1,1,0,1,0]
var banana = [0,0,1,1,0,1]
function changetextimage(arr){

[code]....

View 8 Replies View Related

Add Event Handlers To Objects In Array?

Jun 2, 2010

I am trying to add onclick event handler to many objects but I can't understand why it doesn't work. To assign event handler I use traditional approach as described in [URL]Heres the code (extract.js):

Code JavaScript:
//the class
function extract(){

[code]....

I know that both select tags don't have options, but I generate them with JS because they hold sequential numbers and this part has no impact on the problem at hand.Both functions help select next or previous index in a given select tag for greater comfort

View 5 Replies View Related

Passing Array To Function Using Onclick Event?

Apr 23, 2011

Do I have a simple syntax problem or something more serious.... I get the errror "foo is not defined" when the image is clicked in the following:

[Code]...

View 2 Replies View Related

Storing Values In Array With Left Mouse Click Event?

Apr 10, 2009

I have a program where I will get Terrain coordinate values x and y in a pop up with left mouse click event hovering in a 3D window like google earth. I want to store those values in an array.

View 1 Replies View Related

Loop Through Form.elements Array Validating With Custom Event Handlers?

Jun 27, 2011

Nice module, but I can't get it too work.

Code:

/**
* validate.js: unobtrusive HTML form validation.
*

[code]....

but the script alerts me nothing?

View 6 Replies View Related

Looping Through <li>'s

Jul 23, 2005

Hopefully I 'm missing something silly, but I can't find an easy way to loop
all list items in a simple <ol>. I was hoping a for loop as shown below
would be enough, however clicking "alert all" in the following example gives
me all but the first <li> element. The alertfirst() function finds the first
<li> with no problem. There are multiple lists on the page, so
getElementsByTagName('li') is probably not the most elegant solution. Btw.
my Mozilla crashed when I tried this code, but this is for IE only.

<script type="text/javascript">
function alertfirst() {
var ol=document.getElementsByTagName('ol')[0];
alert( ol.firstChild.firstChild.nodeValue );
}
function alertall() {
var ol=document.getElementsByTagName('ol')[0];
for( var i=ol.firstChild; i=i.nextSibling; i!==null) {
alert( i.firstChild.nodeValue );
}
}
</script>
<ol>
<li>first</li>
<li>second</li>
<li>third</li>
</ol>
<a href="" onclick="alertfirst();return false">alert first</a>
<a href="" onclick="alertall();return false">alert all</a>

View 4 Replies View Related

Looping With For Var Command?

Dec 23, 2010

I have this 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.

View 2 Replies View Related

Looping Using SetTimeout()?

Nov 7, 2011

function funt()
{
var link = document.getElementsByClassName("class")[0];

[code]....

View 5 Replies View Related







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