Follow us on...
Follow us on Twitter Follow us on Facebook
Register

User Tag List

Page 36 of 59 FirstFirst ... 26343536373846 ... LastLast
Results 351 to 360 of 590
  1. #351
    VPL Supporter Hituro's Avatar
    Join Date
    01 Feb 2011
    Posts
    1,293
    Threads
    220

    My User Ranks


    My Reputation

    Re: Learning PHP.. yay me.

    You should never have more than one element with the same ID on the same page. ID should be unique.

    Honestly though, follow the advice we gave you before Use a Javascript framework before you go mad. I recommend JQuery, it really is good. Then you'd have

    Code:
    $('radio[name="send"]').click(function() {
         $(this).parent().child('input[name^="price"]').hide();
         $(this).parent().child('input[name^="reciver"]').show();
         $(this).parent().child('input[name^="gallery"]').hide();
    });

  2. #352
    VPL Supporter
    Join Date
    09 May 2011
    Posts
    902
    Threads
    100

    My User Ranks

    My Reputation

    Re: Learning PHP.. yay me.

    I have installed Jquery but its like learnign PHP over again.. nothing makes sense.. :-/

  3. #353
    VPL Supporter
    Join Date
    09 May 2011
    Posts
    902
    Threads
    100

    My User Ranks

    My Reputation

    Re: Learning PHP.. yay me.

    I have Jquery but again, it's a foreign language to me.. literally.. this is what the code looks like now based off the example you gave me..

    Code:
    <script type=text/javascript src = 'jq.js'>
    $('radio[name="gallery"]').click(function() {
         $(this).parent().child('input[name^="price"]').hide();
         $(this).parent().child('input[name^="reciver"]').hide();
         $(this).parent().child('input[name^=gallery"]').show();
    });
    
    $('radio[name="send"]').click(function() {
         $(this).parent().child('input[name^="price"]').hide();
         $(this).parent().child('input[name^="reciver"]').show();
         $(this).parent().child('input[name^="gallery"]').hide();
    });
    $('radio[name="send"]').click(function() {
         $(this).parent().child('input[name^="price"]').hide();
         $(this).parent().child('input[name^="reciver"]').hide();
         $(this).parent().child('input[name^="gallery"]').show();
    });
    </script>
    It's not doing anything..

    is the show() and hide() supposed to refer to a separate function?

  4. #354
    VPL Supporter Hituro's Avatar
    Join Date
    01 Feb 2011
    Posts
    1,293
    Threads
    220

    My User Ranks


    My Reputation

    Re: Learning PHP.. yay me.

    No, they are built in.

    Okay, lets dissect what each bit is doing, and then maybe we can see why it's not working

    Code:
    <script type=text/javascript src = 'jq.js'>
    How come your script tag has a source and a content? That doesn't seem right. Also where is your tag? Is it at the bottom of the page, after the table with the buttons? If not you need to tell jquery not to execute it till after the page has loaded, like this

    Code:
    <script type=text/javascript>
    $(document).ready(function() {
    $('radio[name="gallery"]').click(function() {
         $(this).parent().child('input[name^="price"]').hide();
         $(this).parent().child('input[name^="reciver"]').hide();
         $(this).parent().child('input[name^=gallery"]').show();
    });
    
    $('radio[name="send"]').click(function() {
         $(this).parent().child('input[name^="price"]').hide();
         $(this).parent().child('input[name^="reciver"]').show();
         $(this).parent().child('input[name^="gallery"]').hide();
    });
    $('radio[name="send"]').click(function() {
         $(this).parent().child('input[name^="price"]').hide();
         $(this).parent().child('input[name^="reciver"]').hide();
         $(this).parent().child('input[name^="gallery"]').show();
    });
    });
    </script>
    Okay lets assume you have done that, so now we analyse the actual body of the script. What this does is identify some element on the page and thne attach an action to it that happens when you click it (with click()). So ...

    Code:
    $('radio[name="gallery"]').click(function() {
    Means, find all radio buttons on the page whose name is 'gallery', and do something when they are clicked. Then

    Code:
    $(this).parent().child('input[name^="price"]').hide();
    Means, find that button (identified as (this)), then find it's parent (the td), then find anything else in that td that is an input with a name starting with 'price' and hide it. If you want to imagine, each step in this (separated by a . ) is traversing up and down the tree of elements on the page till you find one you want to do something to. You can read this as

    [pre]start with this -> go up to it's parent -> go down to it's children -> find the ones which are inputs with names starting with price -> hide them[/pre]

    I hope that makes some sense!

  5. #355
    VPL Supporter
    Join Date
    09 May 2011
    Posts
    902
    Threads
    100

    My User Ranks

    My Reputation

    Re: Learning PHP.. yay me.

    It makes more sense now. :-) I'm going through a javascript tutorial which I should have done weeks ago.. lol but things are becoming more clear and more possible for me, although it's still trickier than regular php

  6. #356
    VPL Supporter
    Join Date
    09 May 2011
    Posts
    902
    Threads
    100

    My User Ranks

    My Reputation

    Re: Learning PHP.. yay me.

    Okay, I have been tweaking your code and it is still not working.. this is the script:

    Code:
    <script type="text/javascript">
    $(document).ready(function() {
    $('radio[name="gallery"]').click(function() {
         $(this).parent().child('input[name^="price"]').hide();
         $(this).parent().child('input[name^="receiver"]').hide();
         $(this).parent().child('input[name^="gallery"]').show();
    });
    
    $('radio[name="send"]').click(function() {
         $(this).parent().child('input[name^="price"]').hide();
         $(this).parent().child('input[name^="receiver"]').show();
         $(this).parent().child('input[name^="gallery"]').hide();
    });
    $('radio[name="price"]').click(function() {
         $(this).parent().child('input[name^="price"]').show();
         $(this).parent().child('input[name^="receiver"]').hide();
         $(this).parent().child('input[name^="gallery"]').hide();
    });
    });
    </script>
    I took out all the onClick's in the form section.. so it looks like this:

    Code:
    <input type = 'radio' name = 'action[$id]' value = 'send'>
    the onClick = show() is completely taken out.

    This code is still not working.

  7. #357
    VPL Supporter
    Join Date
    09 May 2011
    Posts
    902
    Threads
    100

    My User Ranks

    My Reputation

    Re: Learning PHP.. yay me.

    Back to a PHP problem. I have been tweaking an item window that pops up. I've used javascript to show errors before the form passes which is now successfully coded.

    Testing it out, I sent items from my on hand items to my shop inventory and the $_POST is not getting the form information for some reason.

    Code:
    $price = htmlspecialchars(@$_POST['receiverprice']); //I also tried the id "price"
    $price = mysql_real_escape_string($price);
    and here's the form snippet:

    Code:
    <input type='text' id = 'price'  name = 'receiverprice' style = 'display:none' size = '15'>
    It's just not getting the information.

  8. #358
    VPL Supporter
    Join Date
    09 May 2011
    Posts
    902
    Threads
    100

    My User Ranks

    My Reputation

    Re: Learning PHP.. yay me.

    I've been coding for about 10 hours now and I haven't moved forward much at all because I'm trying to integrate javascript into already written scripts.

    I'm kind of thinking that going through old scripts to input some of this javascript isn't even worth the time or effort because I just sat here waisting hours on revamping my bank, which is exactly fine the way it is without any fancy stuff, and i just ended up screwing everything up trying to get javascript in there..

    Hmm.. thoughts..? Should I move forward and integrate java then or am I doing things correctly by going back and redoing things?

  9. #359
    VPL Supporter
    Join Date
    09 May 2011
    Posts
    902
    Threads
    100

    My User Ranks

    My Reputation

    Re: Learning PHP.. yay me.

    Also, a lot of my scripts involve a ton of forms.. like the adoption and gallery areas.. everything is basically a form, rather than a simple link.. it was the most effective way I know how to do things.. :-/

  10. #360
    Junior Member
    Join Date
    22 Nov 2011
    Posts
    79
    Threads
    3
    Blog Entries
    2

    My User Ranks

    My Reputation

    Re: Learning PHP.. yay me.

    Quote Originally Posted by BigThinker View Post
    Code:
    $price = htmlspecialchars(@$_POST['receiverprice']); //I also tried the id "price"
    $price = mysql_real_escape_string($price);
    ...

    It's just not getting the information.
    Not sure if you've already fixed this problem... but the @ in @$_POST['receiverprice'] doesn't look familiar. Is that for Jquery? When I first saw that it made me think of the ampersand ( & ) for variable references, but that wouldn't work in this case because the variable is being passed through a function first.


    As for coding all the javascript, it's probably not going to make things easier for you to code. Sure, you'll have more flexibility to do more dynamic things, and maybe get some extra coding experience under your belt while you're at it, but really what matters the most is how much it improves the experience for the player. Sure, a popup box can be flashy or convenient, but in the end what matters is that you're making something fun that you would want to play. You can always come back to a page later and add that extra javascript in if you decide it would be a nice improvement.
    My virtual pet site!
    http://www.mystikpets.com/

 

 

Bookmarks

Posting Permissions

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