0

I have a drop down menu that looks like this:

alt text

It works fine, but I need to replace the text "Choose an Action" with whatever link the user selects from the box. What is the best way to handle this?

Here is the code for the drop down:

$("#dd_open a").click(function(event) {
event.preventDefault();
$("#dd_open a").removeClass('selected');
$(this).addClass('selected');
return false;
}); 
$("#dd_btn").click(function(event) {
window.location.href = $("#dd_open a.selected").attr('href');
}); 
Glorfindel
22.8k13 gold badges97 silver badges124 bronze badges
asked Aug 6, 2010 at 5:43

2 Answers 2

1
$('#ChooseAnActionElement').val( $(this).val() );

The above will replace the contents of an element with the contents of the selected element.

Or as @slaks has done

$('#ChooseAnActionElement').text( $(this).text() );

depending on the element.

answered Aug 6, 2010 at 5:48
Sign up to request clarification or add additional context in comments.

1 Comment

.val() will only work on a textbox. None of those are textboxes.
1

You can set the text of the Choose an Action element by calling $('some selector').text(something).

You can get the text of the clicked element by calling $(this).text() in the click handler.

answered Aug 6, 2010 at 5:47

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.