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
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with replaceWith() and Select drop down

    I have a select Drop down. I want to use it to replace some text on the page but nothing is working so far.

    This is what I have

    Code:
     <script type="text/javascript">
    $(document).ready(function() {
        $("classSelector").change(function() {
            var val = $(this).selectedValues();
            if (val != '') {
     $('#style').replaceWith('<div id="style">'+ $('#classSelector').val()'</div>');
    
            }
        });
    });
            </script>
    
    {class="<div id="style">Replace Me</div>"}
    								   
    				<select id="classSelector" >
                                       <option>Please Select</option>
                                       <option value="floatl">Float Left</option>
                                       <option value="floatr">Float Right</option>
                                       <option value="floatc">Float Center</option>
                                     </select>
    Any ideas where I'm going wrong ?
    Never really messed around with javascript or Jquery before
    So I'm a bit lost

    Crowds
    PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    You were missing the # id selector from your change() handler, and I didn't see the point of replacing one div with an identical one:

    Code:
    $(document).ready(function() {
        $("#classSelector").change(function() {
            var selectedValue = $(this).val();
            if (selectedValue != '') {
     		$('#style').text(selectedValue);
            }
        });
    });

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for looking at it spudhead.
    I see your point about replacing the div with an identical one but i was unsure of how to get the value of the select box into the div and just tried it that way.

    I tried using

    Code:
    $(document).ready(function() {
        $("#classSelector").change(function() {
            var selectedValue = $(this).val();
            if (selectedValue != '') {
     		$('#style').text(selectedValue);
            }
        });
    });
    But nothing happens ?
    PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    PHP Code:
    {class="<div id="style">Replace Me</div>"
    I'm not familiar with that syntax; is that a template or something?

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, it's just for an example really.
    The actual tag would be something more like {exp:thistag:this_function vars"to pass" class"and stuff"}
    It's the tag syntax for Expression Engine.

    In use it would not contain div's but in this particular case the tag would be echoed out so the user could C&P.

    Crowds
    PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design


  •  

    Posting Permissions

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