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.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Get Text from div

    Hi, I'm new here I come to see if they can help me with a problem...

    I have this:

    php
    <div id="moneda">
    <?php echo $settings['currency_sign']; (you can edit with Dropdown https://code.google.com/p/jquery-in-place-editor/)
    ?>
    </div>
    js
    $("#currency_sign").change(function(){
    alert($(this).val()); (NOT WORKING)
    });
    thanks

  • #2
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    js
    $("#moneda").change(function(){
    alert($(this).val()); (NOT WORKING)
    });

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,486
    Thanks
    23
    Thanked 636 Times in 635 Posts
    I take it you know the first JS was bogus, right?
    I'll use the second:
    Code:
     $("#currency_sign").change(function(){
    alert($(this).val()); (NOT WORKING)  // THIS SHOULD BE EDITED AS A COMMENT
    });
    A.) You have this run on change, but you have no change in the HTML.

    B.) Why not just send the php variable to the js?

    This runs when the word 'STUFf' is clicked. The added jq/js runs when the page loads, because it's not a function.
    PHP Code:
    <?php
    $settings
    ['currency_sign'] = 'STUFf';
    $settings['currency'] = 'what is php';
    ?>
    <div id="moneda">
    <?php echo $settings['currency_sign'];
    ?>
    </div>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" type=""></script>
    <script type="text/javascript">
    /*    first your method    */
    $("#moneda").click(function(){
        alert($(this).text());       // HERE!!!!!
    });

    /*      Next sending directly    */
    var what = '<?php echo $settings['currency']; ?>';
    alert(what);
    </script>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #4
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the user can change the currency_sign on the web from a dropdown, I need javascrit save the new selecion in database...

  • #5
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Solved

    alert($("#moneda option:selected").text());

    Thanks.


  •  

    Posting Permissions

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