简体   繁体   中英

dropdown not working when clicked a second time

I have a problem with my checkbox. If I select a value and validate, I can't do that a second time, it's not working. Looking at other questions, I saw that I may have to use the prop() function with the "checked" property, which I did, but it's still not working.

Here is my website : http://nts.nuvision.co.za/index.php/training/

Here is my javascript :

    $('#one').hide();
    $('#two').hide();
    $('#three').hide();
    $('#show').click(function() {
        $('#pgc-224-0-1').css("margin-top", "0px");
        switch(document.getElementById('trainingcourses').value) {
            case 'one':
                $('#one').show();
                $('#two').hide();
                $('#three').hide();
                $("#trainingcourses").prop('checked', false);

            break;
            case 'two':
                $('#two').show();
                $('#one').hide();
                $('#three').hide();
                $("#trainingcourses").prop('checked', false);

            break;
            case 'three':
                $('#three').show();
                $('#two').hide();
                $('#one').hide();
                $("#trainingcourses").prop('checked', false);

            break;
        }
    });

And here my HTML :

<form id="trainingform">
<select id="trainingcourses" style="font-size: 12pt;">
<option style="font-size: 12pt;" value="one">Sugar and Suite CRM End User Training</option>
<option style="font-size: 12pt;" value="two">Sugar & Suite CRM Advanced End User Training</option>
<option style="font-size: 12pt;" value="three">Sugar and Suite CRM Administrator : Getting Started</option>
</select><input id="show" style="margin-top: -25px; margin-left: 20px;" name="show" type="submit" value="Show more information" onclick="location.href='http://nts.nuvision.co.za/index.php/training/#' + document.getElementById('trainingcourses').value; return false;"/></form>

<div id="one"> (...) </div>
<div id="two"> (...) </div>
<div id="three"> (...) </div>

You are setting checked property to select box which is not valid. remove below lines from your switch case statement and it should work.

$("#trainingcourses").prop('checked', false);

Also not sure if you need a submit button here or not. If you need simple button which should not submit the page then change show button type="submit" to type="button" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM