Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to check if all inputs are not empty with javascript

const inputFeilds = document.querySelectorAll("input");

const validInputs = Array.from(inputFeilds).filter( input => input.value !== "");

console.log(validInputs) //[array with valid inputs]
Comment

javascript check if input is empty

<!-- check if any input field in "Form" is empty using JS -->

<script type="text/javascript">
  function validateForm() {
    var a = document.forms["Form"]["answer_a"].value;
    var b = document.forms["Form"]["answer_b"].value;
    if (!a || !b) {
      alert("Please Fill All Required Fields");
      return false;
    }
  }
</script>

<form method="post" name="Form" onsubmit="return validateForm()" action="">
  <input type="text" name="answer_a" value="">
  <input type="password" name="answer_b" value="password">
</form>
Comment

Check For Empty Input Values


import * as React from 'react';
import {useState, useRef} from 'react';
import { View, Text, TouchableOpacity, TextInput, StyleSheet, SafeAreaView, Button } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import SelectDropdown from 'react-native-select-dropdown'


function HomeScreen({navigation}) { 

const [value, setValue] = useState("");
const countries = ["Egypt", "Canada", "Australia", "Ireland"]
 
 const checkTextInput = () => {
  //Check for the Name TextInput
  if (!value.trim()) {
    alert('Please Enter Name');
    return;
  } 
  //Checked Successfully
  //Do whatever you want
  alert('Success');
  navigation.navigate("Details", {value:value})
};

  
  return (
    <SafeAreaView style={{flex: 1}}>
    <SelectDropdown
	data={countries}
  defaultValue={value}
	onSelect={(selectedItem, index) => {
setValue(selectedItem);
  }}
	buttonTextAfterSelection={(selectedItem, index) => {
		// text represented after item is selected
		// if data array is an array of objects then return selectedItem.property to render after item is selected
		return selectedItem
	}}
	rowTextForSelection={(item, index) => {
		// text represented for each item in dropdown
		// if data array is an array of objects then return item.property to represent item in dropdown
		return item
	}}
/>
<TouchableOpacity onPress={()=>
checkTextInput()
}>
<Text>
  Click Me To Go To Details
</Text>

</TouchableOpacity>
    </SafeAreaView>
  );
}



const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 35,
  },
  textInputStyle: {
    width: '100%',
    height: 40,
    paddingHorizontal: 5,
    borderWidth: 0.5,
    marginTop: 15,
  },
});



function DetailsScreen({route}) {
 const {value} =route.params;

  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Details Screen</Text>
   <Text>{value}</Text>

    </View>
  );
}


const Stack = createNativeStackNavigator();

function App() {
  return (
    <NavigationContainer>
    <Stack.Navigator initialRouteName="Home">

      <Stack.Screen name="Home" component={HomeScreen} />

    <Stack.Screen name="Details" component={DetailsScreen} />
    </Stack.Navigator>
  </NavigationContainer>
  )
}

export default App;
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to check length checkbox has been checked 
Javascript :: add button to add item javascript 
Javascript :: angular ng build setting body min-width 
Javascript :: javascript refresh function every 5 seconds 
Javascript :: url-regex-improvement-to-allow-localhost-url 
Javascript :: Nested comparison operator in Javascript 
Javascript :: react foreach loop 
Javascript :: readonly checkbox angular 
Javascript :: javascript random to abs 
Javascript :: safari technology 
Javascript :: i wanted to detect when a user enters an alphabet key in input text javascript 
Javascript :: get current tab url in chrome extension in popup 
Javascript :: undefined ext in fn.dataTable.ext.search.push 
Javascript :: id generator using javascript 
Javascript :: js what does the vertical line symbol do 
Javascript :: node.js core modules 
Javascript :: Make a ReactNative component take the height and width of the current window 
Javascript :: Day of The Year 
Javascript :: return array odd or even outlier 
Javascript :: forward slash in ajax url 
Javascript :: javascript checkbox in table cell not working 
Javascript :: template.json replacing text in files 
Javascript :: vs code javascript type check 
Javascript :: fastest way to sort an array html tags front 
Javascript :: find invalid json files in directory 
Javascript :: Foreach array in JavaScript fsd 
Javascript :: how to create an object that stores personal data in javascript 
Javascript :: convert typescript to js online 
Javascript :: json serializable snake case 
Javascript :: write a program to print patter usign recursion in javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =