# set-input-value

> Set input value and keep cursor position

Latest version **1.0.0** (published 2014-01-19) · Public Domain license · 0 weekly downloads

## Install

```sh
npm install set-input-value
pnpm add set-input-value
yarn add set-input-value
bun add set-input-value
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2014-01-19 |
| First published | 2014-01-19 |
| Weekly downloads | 0 |
| License | Public Domain |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Parsha Pourkhomami |
| Maintainers | parshap |
| Keywords | input, value, cursor, selectionStart, selectionEnd, setSelectionRange |

## Links

- npm: https://www.npmjs.com/package/set-input-value
- Repository: git@github.com:parshap/set-input-value
- Issues: https://github.com/parshap/set-input-value/issues
- npm.io page: https://npm.io/package/set-input-value

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2014-01-19

## README

# set-input-value

Set an input's value without losing the user's cursor position.

## Example

```javascript
var set = require("set-input-value");
var input = document.getElementById("my-input");

// Uppercase the value
set(input, input.value.toUpperCase());

// Add a prefix and shift the cursor accordingly
var prefix = "A: ";
set(input, prefix + input.value, prefix.length);
```

## API

### `set(input, value, shift)`

Update the value of the given input element.

 * *input*: input element to update
 * *value*: new value
 * *shift*: amount to shift the previous cursor by (*default: `0`*)

## Browser Support

This module currently uses the
[`input.setSelectionRange`](https://developer.mozilla.org/en-US/docs/Web/API/Input.setSelectionRange)
which is not supported in IE before version 9. A polyfill is possible -
see http://jsfiddle.net/EXH2k/6/.

## Installation

```
npm install set-input-value
```

---
_Source: https://npm.io/package/set-input-value · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
