Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> JavaScript

JavaScript से ड्रॉपडाउन लिस्ट में चयनित विकल्प का इंडेक्स कैसे दिखाएं?


ड्रॉप-डाउन लिस्ट में चयनित विकल्प का इंडेक्स दिखाने के लिए, JavaScript में selectedIndex प्रॉपर्टी उपयोग करें।

उदाहरण

चयनित विकल्प का इंडेक्स प्रदर्शित करने के लिए निम्न कोड चलाएं:

<!DOCTYPE html> <html>    <body>       <form id="myForm">          <select id="selectNow">             <option>One</option>             <option>Two</option>             <option>Three</option>           </select>           <input type="button" onclick="display()" value="Click">       </form>       <p>Select and click the button to get the index of the selected option.</p>       <script>          function display() {             var index = document.getElementById("selectNow").selectedIndex;             document.write(index);          }       </script>    </body> </html>

  1. JavaScript में ड्रॉपडाउन (सिलेक्ट) की सिलेक्टेड वैल्यू कंसोल पर कैसे डिस्प्ले करें? JavaScript में ड्रॉपडाउन (सिलेक्ट) की सिलेक्टेड वैल्यू कंसोल पर कैसे डिस्प्ले करें?

    उदाहरण onchange इवेंट और selectedIndex से सिलेक्टेड ऑप्शन का टेक्स्ट प्राप्त करें। <!DOCTYPE html> <html lang=en> <head> <meta charset=UTF-8> <meta name=viewport content=width=device-width, initial-scale=1.0> <title>Document</title> </head> <

  1. JavaScript में चयनित विकल्प होने पर छिपा हुआ डिव दिखाना JavaScript में चयनित विकल्प होने पर छिपा हुआ डिव दिखाना

    जब एक चयन विकल्प चुना जाता है तो छिपा हुआ डिव दिखाने के लिए, आप मान style.display को ब्लॉक पर सेट कर सकते हैं।उदाहरणकोड निम्न है:<!DOCTYPE html> <html lang=en> <head> <meta charset=UTF-8> <meta name=viewport content=width=device-width, initial-scale=1.0> <title>Do

  1. Tkinter Combobox में चयनित विकल्प का इंडेक्स कैसे प्राप्त करें? Tkinter Combobox में चयनित विकल्प का इंडेक्स कैसे प्राप्त करें?

    यदि आप आइटम की ड्रॉपडाउन सूची बनाना चाहते हैं और सूची के आइटम को उपयोगकर्ता द्वारा चुने जाने में सक्षम बनाना चाहते हैं, तो आप Combobox विजेट का उपयोग कर सकते हैं। Combobox विजेट आपको एक ड्रॉपडाउन सूची बनाने की अनुमति देता है जिसमें आइटम की सूची को तुरंत चुना जा सकता है। हालांकि, यदि आप Combobox विजे