DotDragnet
February 08, 2012, 11:10:06 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: jquery again  (Read 563 times)
Charisma Bypass
Hero Member
*****
Posts: 512



View Profile Awards
« on: March 02, 2010, 12:08:05 PM »

Code:
$("select[name=id9]").change(function () {
        abc = $(this).val();       
        $("#display div").prepend("motif" + abc + ".gif");       
    });

This gives a result like this:

motif120.gif

which is based on this selector;

Code:
<select name="id9">
  <option value="136">None</option>
  <option value="120">Football</option>
  <option value="121">Rugby</option>
  <option value="122">Cricket</option>
</select>

Which works just fine.  But when the person then chooses another option, I need the original option to be removed.  At the moment it's doing this (which it should do as that's what I'm asking it to do);

motif120.gifmotif136.gifmotif121.gif

assuming they chose football, then none, then rugby

This has to be simple, but I am braindead today.

Thaank you in advance!
Logged
samhs
Administrator
Hero Member
*****
Posts: 1669



View Profile WWW Awards
« Reply #1 on: March 02, 2010, 12:57:16 PM »

it's because you're using prepend() use html() instead or text()
Logged

Loose adj a not held together; not fastened or firmly fixed in place
Lose verb to misplace something. To fail to keep or obtain something, especially because of a mistake, carelessness, etc.
---
Blog: www.ohwrite.co.uk
Twitter: www.twitter.com/samhs
Charisma Bypass
Hero Member
*****
Posts: 512



View Profile Awards
« Reply #2 on: March 02, 2010, 01:26:31 PM »

Sam - thanks.

I think have to use prepend, as it is going in front of another textual input.

So in the text input box, the user might insert "Liverpool", then select a football.  Then he might change that football to a picture of a pair of shorts or jersey or similar.

Hope that makes sense?
Logged
samhs
Administrator
Hero Member
*****
Posts: 1669



View Profile WWW Awards
« Reply #3 on: March 02, 2010, 01:40:04 PM »

well you need to rebuild the whole string then - you're inserting content, prepend does this before anything that already exists. The other options is to delineate the content parts with <span>s or similar - which would allow you to use the html() or text() methods. Otherwise you'll need to grab the data from the other selectors on your page each time any of them changes, IYSWIM?
Logged

Loose adj a not held together; not fastened or firmly fixed in place
Lose verb to misplace something. To fail to keep or obtain something, especially because of a mistake, carelessness, etc.
---
Blog: www.ohwrite.co.uk
Twitter: www.twitter.com/samhs
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!