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

जावास्क्रिप्ट के साथ तालिका में नल मान डालने से कैसे बचें?

<घंटा/>

तालिका में डाले गए शून्य मानों से छुटकारा पाने के लिए, आपको मान दर्ज करते समय स्थिति की जांच करनी होगी।

NULL की जाँच करने की शर्त इस प्रकार होनी चाहिए -

while( !( yourVariableName1==null || yourVariableName2==null ||
yourVariableName3==null…...N){
   // yourStatement1
   .
   .
   N
}

उपरोक्त तर्क कभी भी शून्य मान डालने की अनुमति नहीं देगा।

अब आप लूप के लिए उपयोग कर सकते हैं और NULL के बिना तालिका में मान सम्मिलित कर सकते हैं। निम्नलिखित कोड है -

उदाहरण

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<h2>Demo Of Inserting the value into the table</h2>
<p>This is demo on the javascript array</p>
<p id="demo"></p>
<script>
   var index = 0;
   var firstNameArray = new Array();
   var lastNameArray = new Array();
   var firstName = "";
   var lastName = "";
   while (!(firstName == null || lastName == null)) {
      firstName = prompt("Please Enter your First Name=");
      lastName = prompt("Please Enter your Last Name=");
      firstNameArray[index] = firstName;
      lastNameArray[index] = lastName;
      index++;
   }
   document.writeln("<table border='1' width='50%'>");
   document.writeln("<caption>DEMO TABLE IN JAVASCRIPT</caption>");
   document.writeln("<th>FirstName</th><th>LastName</th>");
   for (var startIndex in firstNameArray) {
      if (firstNameArray[startIndex] !== null &&
         lastNameArray[startIndex] !== null)
         document.writeln("<tr><td>" + firstNameArray[startIndex] +
         "</td><td>" + lastNameArray[startIndex] + "</td></tr>");
      }
      document.write("</table>");
</script>
</body>
</html>

उपरोक्त प्रोग्राम को चलाने के लिए, फ़ाइल नाम "anyName.html(index.html)" को सेव करें और फ़ाइल पर राइट क्लिक करें। वीएस कोड संपादक में "लाइव सर्वर के साथ खोलें" विकल्प चुनें।

आउटपुट

यह निम्नलिखित आउटपुट देगा -

जावास्क्रिप्ट के साथ तालिका में नल मान डालने से कैसे बचें?

अब पहला नाम दर्ज कर रहे हैं।

यह निम्नलिखित आउटपुट देगा -

जावास्क्रिप्ट के साथ तालिका में नल मान डालने से कैसे बचें?

OK बटन पर क्लिक करने के बाद, आपको निम्न आउटपुट मिलेगा -

जावास्क्रिप्ट के साथ तालिका में नल मान डालने से कैसे बचें?

अब, अंतिम नाम दर्ज करने से यह निम्न आउटपुट उत्पन्न करेगा -

जावास्क्रिप्ट के साथ तालिका में नल मान डालने से कैसे बचें?

OK बटन पर क्लिक करने के बाद अब Cancel बटन को दो बार क्लिक करें, आपको फाइनल आउटपुट मिलेगा।

अंतिम आउटपुट तालिका इस प्रकार है -

जावास्क्रिप्ट के साथ तालिका में नल मान डालने से कैसे बचें?


  1. जावास्क्रिप्ट के साथ फ़िल्टर तालिका कैसे बनाएं?

    जावास्क्रिप्ट के साथ एक फ़िल्टर तालिका बनाने के लिए, कोड इस प्रकार है - उदाहरण <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style>    * {       box-sizing: border-box;

  1. जावास्क्रिप्ट के साथ टेक्स्ट को कैसे टॉगल करें?

    जावास्क्रिप्ट के साथ टेक्स्ट को टॉगल करने के लिए, कोड इस प्रकार है - उदाहरण <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style>    body {       font-family: "Segoe

  1. जावास्क्रिप्ट में शून्य/खाली वस्तुओं वाले सरणी को मान कैसे असाइन करें?

    जावास्क्रिप्ट का उपयोग करके शून्य/खाली वस्तुओं के साथ एक सरणी को मान निर्दिष्ट करने के लिए कोड निम्नलिखित है - उदाहरण <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, init