An open API service indexing awesome lists of open source software.

https://github.com/awran5/conditional-script

Native JavaScript ES6 script lets you conditionally show/hide DOM elements based on user input
https://github.com/awran5/conditional-script

conditional es6 form javascript

Last synced: about 2 months ago
JSON representation

Native JavaScript ES6 script lets you conditionally show/hide DOM elements based on user input

Awesome Lists containing this project

README

        

# conditionalScript

conditionalScript is a simple native JavaScript ES6 script which lets you conditionally show/hide Form or any other elements by using custom HTML5 attributes. conditionalScript currently works with checkboxes, radios and select lists.

This script does not requires **jQuery** though, it should work on any modern browser, If you have an issue/idea, please feel free to fork the repo or send me a push request and i'll be more than happy to push it.

### [Demo & Examples](https://awran5.github.io/conditional-script/)

# Usage

1. Place the script before the closing Body tag for better page speed performance.
```html

```
2. Create 2 **divs** with the same class name, you can name them whatever you like.
```html


Main Markup here...


Conditional Markup here...

```
3. Add additional `data-conditional-name` and `data-conditional-value` attributes to your newly created (Conditional Markup). Please note that the `data-conditional-name` attribute will target the **Field Name** attribute, so you need to set the Name attribute to the field in order to work properly.
```html




Conditional Markup .. data-conditional-name="exampleName" data-conditional-value="main field value"

```
Also, `data-conditional-value` accepts more than 1 value but they must be separated by **comma** followed by **space** (", ") for example:
```php
data-conditional-value="value 1, value 3"
```

## You final markup should look like this:

```html




yes



no


Show on radio check with value Yes and hide if No


```