How can I set the value of a textbox to the user entered value(it's a number). <input type = "text" name = "somename" value = ""> User enters 3 in the textbox

The code should transform to <input type = "text" name = "somename" value = "3">

Recommended Answers

All 4 Replies

Member Avatar for stbuchok

Can you explain what exactly you need this for? When someone types a value in a textbox the code is not supposed to change, the value that is typed in the textbox is however available to be used in JavaScript (or available to be used in a GET or a POST response).

It's easiest if you give it an ID, first. Then:

document.getElementById('that_id_you_gave_it').value = '3';

Attach event handler.

<input type = "text" name = "somename" value = "" onkeydown="document.getElementById('myID').value=this.value" />

Onkeyup would be better for that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.