Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-04-2010, 09:14 AM   PM User | #1
Crowds
Regular Coder

 
Join Date: May 2005
Posts: 235
Thanks: 0
Thanked 0 Times in 0 Posts
Crowds is an unknown quantity at this point
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
Crowds is offline   Reply With Quote
Old 02-04-2010, 10:08 AM   PM User | #2
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
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);
        }
    });
});
Spudhead is offline   Reply With Quote
Old 02-04-2010, 10:33 AM   PM User | #3
Crowds
Regular Coder

 
Join Date: May 2005
Posts: 235
Thanks: 0
Thanked 0 Times in 0 Posts
Crowds is an unknown quantity at this point
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
Crowds is offline   Reply With Quote
Old 02-04-2010, 04:14 PM   PM User | #4
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
PHP Code:
{class="<div id="style">Replace Me</div>"
I'm not familiar with that syntax; is that a template or something?
__________________
Fumigator is offline   Reply With Quote
Old 02-04-2010, 07:07 PM   PM User | #5
Crowds
Regular Coder

 
Join Date: May 2005
Posts: 235
Thanks: 0
Thanked 0 Times in 0 Posts
Crowds is an unknown quantity at this point
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
Crowds is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:23 PM.


Advertisement
Log in to turn off these ads.