HTML आउटपुट एलिमेंट
In this page:
<form oninput="result.value = expression">
<output name="result" for="input1 input2"></output>
</form>
<output> एलिमेंट क्या है?
<output> element एक form element है जो किसी calculation का result दिखाने के लिए इस्तेमाल होता है, जैसे कोई total, sum, या दूसरे inputs से निकाला गया कोई value। यह दूसरे form controls की तरह ही बर्ताव करता है और form submit होने पर शामिल किया जाता है।
- जब भी दिखाया गया text form inputs से जुड़ा calculated result हो, तो किसी generic element की बजाय <output> इस्तेमाल करें।
- Accepted attributes:
- for — space-separated ids of input elements
- form — id of associated form
- name — key for form.elements
उदाहरण: What Is the <output> Element?
<output>42</output>
'for' से Output को फॉर्म इनपुट्स से लिंक करना
<output> पर for attribute input IDs की एक space-separated list accept करता है, जो स्पष्ट रूप से बताता है कि displayed result किन fields पर निर्भर करता है। यह assistive technology और markup पढ़ने वाले developers दोनों के लिए relationship को मज़बूत करता है।
- for attribute के अंदर calculation में योगदान देने वाला हर input ID लिस्ट करें, भले ही वे कई हों।
- Accepted values:
- for — space-separated list of element ids that contribute to the result
उदाहरण: Linking Output to Form Inputs with 'for'
<input type="number" id="a" value="2">
<input type="number" id="b" value="3">
<output for="a b">5</output>
JavaScript से Values कैलकुलेट करना
चूँकि <output> खुद कुछ भी calculate नहीं करता, JavaScript का इस्तेमाल related inputs पर changes सुनने और output की value property को calculated result से अपडेट करने के लिए किया जाता है।
उदाहरण: Calculating Values with JavaScript
<input type="number" id="a" oninput="document.getElementById('result').value = Number(a.value) + Number(b.value)">
<input type="number" id="b">
<output id="result"></output>
आउटपुट एलिमेंट को स्टाइल करना
चूँकि <output> एक inline form element है, इसे किसी span या input की तरह साधारण CSS से style किया जा सकता है, जिससे आप element के बर्ताव को बदले बिना calculated results को visually emphasize कर सकते हैं।
उदाहरण: Styling the Output Element
<output style="font-weight: bold; color: green;">100</output>
एक्सेसिबिलिटी और आउटपुट एलिमेंट
<output> element में कई browsers में एक implicit ARIA live region role होता है, यानी screen readers इसकी value में हुए बदलावों को अपने आप announce कर सकते हैं, जो calculated totals के लिए खासकर उपयोगी है जो बिना page reload के अपडेट होते हैं।
उदाहरण: Accessibility and the Output Element
<label for="total">Total:</label>
<output id="total">0</output>
Chapter Quiz — Complete all 20 topics to unlock
0/20 topics done
Complete these topics first:
- HTML Keyboard Shortcuts
- HTML Browser Support
- HTML Character Sets
- HTML Doctypes
- HTML Audio/Video Reference
- HTML Meta Tags
- HTML ARIA Roles
- HTML Input Validation
- HTML Iframe Security
- HTML Responsive Images
- HTML Web Fonts
- HTML Icon Fonts
- HTML Progress & Meter
- HTML Output Element
- HTML Datalist
- HTML Image Maps
- HTML Browser DevTools
- HTML Validation
- HTML Quiz
- HTML Interview Prep