AKor
AKor

Reputation: 8882

Setting a value to already be in a text input/textarea

Firstly, I'm using a jQuery plugin called inlineFieldLabel to put labels inside my textareas/text inputs.

I have a multi-part form. The idea is to fill the fields in the first part of the form if you decide to go back.

Now, it seems like I can either disable my jQuery plugin if any fields have been previously filled, or I can somehow work around this.

I tried putting something between <textarea> and </textarea>, as well as putting a value attribute into my text input, but it seems that the plugin is blocking that from working.

Is there a way I can simply insert text into the text fields, using jQuery perhaps, in the same manner as a keyboard input (which would cause the plugin to function correctly)?

Upvotes: 0

Views: 2235

Answers (2)

Edgar Villegas Alvarado
Edgar Villegas Alvarado

Reputation: 18354

You could simulate keypress as this links explains:

Is it possible to simulate key press events programmatically?

Hope this helps. Cheers

Upvotes: 0

Shadow Wizard
Shadow Wizard

Reputation: 66388

If you mean have some default text then it's pure HTML:

<input type="text" value="hello I'm default value" />
<textarea>hello I'm default value</textarea>

For input field of type text you need to assign the value attribute and for textarea element just have the value between the tags.

If you mean via jQuery then for both element types you can have:

$("#myInput").val("I come in peace from jQuery");

Where myInput is the ID of the desired element.

Upvotes: 3

Related Questions