0

I've got the a piece of a form where I've applied some javascript (the end-purpose of the js is to show the appropriate follow up question), but the part that loads the input's and select's values into variables doesn't seem to be working.

Here's the exact code:

# HTML
<ul id="m_mlt_t">
<li>How long have you known <span class="nom">__</span>?</li>
    <li><input name="m_mlt_n" type="text" maxlength="3" /> <select name="m_mlt_t"><option></option><option>days</option><option>months</option><option>years</option></select></li>
    <li><input name="m_mlt_n" type="radio" value="777" />I prefer not to answer</li>
    <li><input name="m_mlt_n" type="radio" value="999" />Don't know</li>
    <li><span class="m_mlt_t" style="display:none;"></span></li>
</ul>

# JAVASCRIPT
$('select[name="m_mlt_t"], input[name="m_mlt_n"]').change(function() {
    var time = $('input[name="m_mlt_n"]').val();
        $("span#m_mlt_t").text(time);
        $("span#m_mlt_t").fadeIn();
    var period = $('select[name="m_mlt_t"]').val();
        $("span#m_mlt_t").append(" " + period);
        $("span#m_mlt_t").fadeIn();
});

In the fiddle, I expect the span to fade in and display the values of the textfield and the dropdown. http://jsfiddle.net/vxvSU/


btw the code for the following custom functions isn't included, but I know they work
counter_multiChoice(),fadeOUT_sect(),fadeIN_sect()

7
  • your code is short enough to post here too - please do so! Commented Dec 22, 2011 at 22:37
  • 2
    You cannot have more than one element with the same id. Commented Dec 22, 2011 at 22:38
  • I'm sure you know those other functions work, but the javascript engine doesn't, and won't let us see what's going wrong without them including the undefined qArray... Commented Dec 22, 2011 at 22:42
  • okay, i'll remove it from the code. Commented Dec 22, 2011 at 22:44
  • All I did was remove your line of code and add the comma like I originally suggested ... jsfiddle.net/vxvSU/4 Commented Dec 22, 2011 at 22:51

1 Answer 1

3

A first problem is your selector

$('select[name="m_mlt_t"] input[name="m_mlt_n"]')

This selects any child input elements inside the select element, which doesn't make any sense and should probably be...

$('select[name="m_mlt_t"], input[name="m_mlt_n"]')

Which selects all matching select, and input elements with the appropriate names.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! (filler text to meet min req)

Your Answer

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.