Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 7 FirstFirst 1234 ... LastLast
Results 16 to 30 of 92
  1. #16
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,436
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Looks okay to me.

    I think you can accomplish the same thing by making a small change in my code.

    Change
    Code:
    var forward = ( nextButton != null && nextButton.value == winnerButton.value );
    to
    Code:
    var forward = ( nextButton != null && nextButton.value != "" && nextButton.value == winnerButton.value );
    Yes, I added in that "forward" check explicitly to handle the case where you changed your mind about (for example) who won in round 1. I noticed it propagated all the way and even thought about adding the code as here, but it didn't bother me enough to go back and change it. <grin>Shows what having somebody actually read and use your code can do for motivation.</grin>

    **********

    Just tested that change. Worked.

  2. #17
    New Coder
    Join Date
    Mar 2009
    Location
    Bakersfield, CA
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post
    One problem I have been trying to figure out is how to get the selections held in the <input type=button> posted to the next page. People have told me it is possible, but I can't get it to work at all.

  3. #18
    New Coder
    Join Date
    Mar 2009
    Location
    Bakersfield, CA
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post
    Ah, yes. Much cleaner forward checking then mine! Although many people would want to just clear out the picks in later rounds instead of replacing since different match ups may result in picking a different winner. No big deal though.

    Still can't figure out the posting of the results, however. I am beginning to think it isn't possible with the way this is set up.
    Last edited by mbrewer; 03-09-2009 at 04:39 AM.

  4. #19
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,083
    Thanks
    38
    Thanked 498 Times in 492 Posts
    If you still want to email the information,
    see: http://www.google.com/search?q=javas...ient=firefox-a

    I use 'formmail.cgi' supplied by my ISP to write to a file that I convert to a database later with an off-line program.

  5. #20
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,436
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    reading the form fields is trivial for most any server side system: PHP, ASP, ASP.NET, JSP, or (yes) CGI.

    Except for one thing: Buttons do *NOT* get submitted to the next page!!!

    So you would need to write a tiny JS script to copy the button values to one or more hidden form fields.

  6. #21
    New Coder
    Join Date
    Mar 2009
    Location
    Bakersfield, CA
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post
    Beautiful! I simply added the following to the end of current javascript:

    winner.form.<hidden field name>.value = winnerButton.value;

    Thanks so much for your help Old Pedant.

  7. #22
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,436
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    DOH on me! That's much simple that what I was going to do! LOL!

  8. #23
    New Coder
    Join Date
    Mar 2009
    Posts
    21
    Thanks
    1
    Thanked 2 Times in 2 Posts
    You guys are awesome!! I couldnt have done this without ya!

  9. #24
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,436
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Cooperative programming can work, can't it? <grin/>

  10. #25
    New to the CF scene
    Join Date
    Mar 2009
    Location
    York, PA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Final Product?

    Guys I found this code and it is Great, Do you have the final product? I would love to see it just to mess around with it.

    THanks,
    Brian

  11. #26
    New to the CF scene
    Join Date
    Mar 2009
    Location
    York, PA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Guidance Please

    Great script!
    Last edited by bcoleman; 03-10-2009 at 05:44 PM.

  12. #27
    New Coder
    Join Date
    Mar 2009
    Location
    Bakersfield, CA
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post
    I have had a couple of people ask me about submitting the data, so here is what I did. If you guys have any questions let me know.

    I simply collected all of the button values (i.e. picks selected by user) onClick on the submit button and stored as the hidden field values. On the next page I get the posted values and store in the db. Initially I tried just assigning the hidden field value in the win() function as they were selected by the user, however that caused problems when people returned to change their picks later (i.e. would only post picks they changed and erase all other unchanged picks).

    Submit Button:
    <input name="Submit" type="submit" value="Submit Picks" onClick="getvalues(this)">

    Button and Hidden field for each pick:
    <input type="button" class="team" name="WIN1_1" id="WIN1_1" onclick="win(this)" value="<?php echo $pick1_1; ?>">
    <input type="hidden" name="pick1_1" id="pick1_1">

    New Javascript function:
    function getvalues(winner) {
    winner.form.pick1_1.value = winner.form.elements["WIN1_1"].value;
    winner.form.pick1_2.value = winner.form.elements["WIN1_2"].value;
    winner.form.pick1_3.value = winner.form.elements["WIN1_3"].value;
    winner.form.pick1_4.value = winner.form.elements["WIN1_4"].value;
    winner.form.pick1_5.value = winner.form.elements["WIN1_5"].value;
    winner.form.pick1_6.value = winner.form.elements["WIN1_6"].value;
    winner.form.pick1_7.value = winner.form.elements["WIN1_7"].value;
    winner.form.pick1_8.value = winner.form.elements["WIN1_8"].value;
    winner.form.pick2_1.value = winner.form.elements["WIN2_1"].value;
    winner.form.pick2_2.value = winner.form.elements["WIN2_2"].value;
    winner.form.pick2_3.value = winner.form.elements["WIN2_3"].value;
    winner.form.pick2_4.value = winner.form.elements["WIN2_4"].value;
    winner.form.pick3_1.value = winner.form.elements["WIN3_1"].value;
    winner.form.pick3_2.value = winner.form.elements["WIN3_2"].value;
    winner.form.pick4_1.value = winner.form.elements["WIN4_1"].value;
    }
    Last edited by mbrewer; 03-10-2009 at 06:55 PM.

  13. #28
    New Coder
    Join Date
    Mar 2009
    Location
    Bakersfield, CA
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post
    Sorry, I intially posted an example, but got in trouble, so I took it down.
    Last edited by mbrewer; 03-10-2009 at 07:30 PM.

  14. #29
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,436
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    If you are lazy, as I am, you can type less code using mbrewer's basic solution thus:
    Code:
    Submit Button:
    <input name="Submit" type="submit" value="Submit Picks" onClick="getvalues(this)">
    
    Button and Hidden field for each pick:
    <input type="button" class="team" name="WIN1_1" id="WIN1_1" onclick="win(this)" value="<?php echo $pick1_1; ?>">
    <input type="hidden" name="pick1_1" id="pick1_1">
    
    New Javascript function:
    function getvalues(winner) 
    {
        var frm = winner.form;
        for ( var e = 0; e < frm.elements.length; ++e )
        {
            var fld = frm.elements[e];
            if ( fld.name.substring(0,3) == "WIN" && fld.name.substring(0,4) != "WIN0" )
            {
                 frm.elements["pick" + fld.name.substring(4)].value = fld.value;
            }
       }
    }
    Not clear what the purpose of the ID= in those form fields is. Can't see any use for it, since the ID is not used in posting to next page and since we refer to all the elements in the JS code by name.

  15. #30
    New Coder
    Join Date
    Mar 2009
    Location
    Bakersfield, CA
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post
    Yeah - I set up a for loop as well to collect the picks to clean up the code a bit, but I have other elements on my page, so it is a little different. This looks like it should work perfectly for our purposes here, though.

    You can definitely get rid of the ID's on the <input>'s. I used them for trying to get the data posted to the next page, but ended up not using them anyways and forgot to clean up the code. Thanks for pointing that out Pedant. Always want to make the code as clean and efficient as possible...


 
Page 2 of 7 FirstFirst 1234 ... LastLast

Tags for this Thread

Posting Permissions

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