<!-- 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>
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;