0

I have a textfield in HTML, where the value is predefined, e.g. "hello".

Now I change the value manually on my website from "hello" to "bye". When I click on a button, that calls the same site again, my value of the input type should be "bye" now and not "hello". Here you can see my code :

<form method="POST" id="ReloadPage" name="ReloadPage" action="MyWebsite" onsubmit="getValue();">  
<strong>word: </strong>
<input id="word" type="text" size="30" value="hello" name="WORD" />

<script type="text/javascript">
function getValue() {
  document.getElementById("word").value="bye";
}
</script>

But somehow, the value will always be hello and doesn't change to bye. Thanks a lot for help.

1
  • you can use localstorage or cookies for this. as each time the page reloads the javascript is freshly loaded. Commented Dec 8, 2016 at 12:51

1 Answer 1

1

You can't use function as name of function.Change name of your function

<form method="POST" id="ReloadPage" name="ReloadPage" action="MyWebsite" onsubmit="return GetValue();">  
<strong>word: </strong>
<input id="word" type="text" size="30" value="hello" name="WORD" />

function GetValue() {
 document.getElementById("word").value="bye";
 return false;
}

Also when you submit the form page will reload so it will show initial value again.

Sign up to request clarification or add additional context in comments.

5 Comments

Although what you posted is true but this wont solve the issue. page will be reloaded and entered value will be lost
Sorry, that was my fault. I just named the function "function()" that it's clear for everyone. The function has another name.
@anu yes i was updating that meanwhile you commented.
@Tobias to avoid submission you can simply call function on button click.
@Leopard I've seen it and it worked! Thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.