rez
rez

Reputation: 95

HTML textbox default value update with every input

I have this simple Html code here.

<form action="" method="post">
    Text Box:<input type="text" name="host" value="default value" size=30 onchange="updateTextBox()" />
    <input type="submit" name="submit" value="update value in text box to current value"/>
</form>

Every time I click the button, I want the default value of the textbox to be updated to the value I most recently entered.

Upvotes: 1

Views: 562

Answers (1)

Avinash Kadimisetty
Avinash Kadimisetty

Reputation: 143

<script>
    /* give a name to the form and write it where "form_name" is */
    var newText = document.forms["form_name"]["host"].value;

    /* add this chunk in the submit button (onclick = "changeText()") */
    function changeText()
    {
        /* give an id to the text box input tag and replace "input_id" with that */
        document.getElementById("input_id").value = newText; 
    }
</script>

Upvotes: 1

Related Questions