Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

form-value

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

form-value

Gets the form item value and assigns a value to the form item

latest
Source
npmnpm
Version
1.0.5
Version published
Maintainers
1
Created
Source

form-value

简体中文

Introduction

Does not rely on any libraries or frameworks, Use only the native DOM.

val() function is provided,you can use val(form) gets the form values and use val(form, data) assign a value to the form item.

Install

npm i form-value

and in browser

<script src="./browser/form-value.js"></script>

Gets the form values

first, you must be set every item name attribute.

let form = document.querySelector('form')

let data = val(form)
/**
returns
{
  key: value,
  key: value,
  key: [value1, value2], // if form item type is checkbox
  ...
}
*/

// if you want to get querystring
let data = val(form, 'querystring')
/**
returns   key=value&key=value...
*/

// if you want to get FormData
let data = val(form, 'formdata')
/**
returns the FormData Object
*/

Assign

You need to pass in a literal object, and the key of the object must be equal to the name attribute of the form item.

supported DOMStringMap (HTMLElement.dataset) type since 1.0.4

let data = {
  text: 'hello world',
  password: 123456,
  sex: 'M'
}
let form = document.querySelector('form')

val(form, data) // Set default values for form entries

Keywords

form

FAQs

Package last updated on 30 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts