`
var e = document.getElementById("select_list");
var textselected= e.options[e.selectedIndex].text;
var Select1 = [ "Text1", "Text2", "Text3", ];
var Select2 = [ "Text1", "Text2", "Text3", ];
var Select3 = [ "Text1", "Text2", "Text3", ];
$("#click-button").click(function() {
if (textselected.includes('textselected1')) {
$("#quote-box p").html(Select1[Math.floor(Math.random()*Select1.length)]);
} else if (textselected.includes('textselected2')) {
$("#quote-box p").html(Select2[Math.floor(Math.random()*Select2.length)]);
} else if (textselected.includes('textselected3')) {
$("#quote-box p").html(Select3[Math.floor(Math.random()*Select3.length)]);
} });
`
I have a drop down list in website with ID = 'select_list' Basically when user selecting something then the selection inner text will need to be used as a criteria for random text qoutes.
I have three items in drop down list named: textselected1, textselected2, textselected3
If user selected 'textselected1' then when button clicked random text will be generated in 'quote-box' from random text list 'Select1'
If user selected 'textselected2' then same button clicked but random text will be generated in 'quote-box' will be from random text list 'Select2' etc..
Please need some help with the code as I started to write something but it doesnt work.
Any help will be much apprieciated.
Aucun commentaire:
Enregistrer un commentaire