dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: How would I use an array for this?

  1. #1
    Join Date
    Nov 2002
    Posts
    10

    How would I use an array for this?

    I have a script which gets data from a form field in one window and puts it into a corresponding form field in another window. This script is repeated 5 times, once for each weekday. The script looks like this:

    function receiveDataFriday_Entree(frm)
    {
    var str = "\n", fld;
    for (var i=0; i<frm.elements.length; i++) {
    fld = frm.elements[i];
    if (fld.type == 'radio') {
    if (fld.checked) {
    str += fld.value;
    }
    }
    window.opener.document.menuPlanner.Friday_Entree.value = str;
    }

    I end up calling the script 5 times, specifying the different days of the week, but I know there's a better way to do this. Can someone tell me how I can define an array in Javascript so that I only have to call the script once?

    Much appreciation in advance,

    Heidi

  2. #2
    Join Date
    Nov 2002
    Posts
    4,473

    Re: How would I use an array for this?

    function receiveDataEntree(frm, dy)
    {
    var str = "\n", fld;
    for (var i=0; i<frm.elements.length; i++) {
    fld = frm.elements[i];
    if (fld.type == 'radio') {
    if (fld.checked) {
    str += fld.value;
    }
    }
    window.opener.document.menuPlanner[dy].value = str;
    }


    Call it with dy = "Friday_Entree".

  3. #3
    Join Date
    Nov 2002
    Posts
    10

    Yes, that's what I was looking for

    Thanks, Gil and Dave. That works much better because I don't have to have 5 of the same script with just one variable changed for each.

    You guys are very helpful and this forum is a real lifesaver! Thanks again.

  4. #4
    Join Date
    Nov 2002
    Posts
    10

    Well, now that you mention it...

    That would be even better!

    And it would probably shed some light on the issue of passing the data from the second window back to the corresponding field in the first window.

    For a stripped down version of what I've described above, go to www.todaysmenu.ca/plan/test.htm

    The part that I mention occurs when you click the CHANGE button and the new meal you choose gets put in the field on the first page.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles