0

With an external JavaScript file, I'm changing the value of this button below to '5'.

This works, I used console.log to check if the value indeed got changed to '5'.

<form action="getdata.php" method="POST">
  <button type="submit" class="firstHeavyGame button" name='storage' value=''>PRESS THE BUTTON</button>
</form> 

Then, when this button is clicked it sends the value to the php site where it processes the data.
BUT, I think then clicking this button, the value gets reset to '' '' (blank). Basic HTML (I'm a newb).
So the php script is not receiving any data.

I checked to see if everything else is working by manually entering the value:

<form action="getdata.php" method="POST">
  <button type="submit" class="firstHeavyGame button" name='storage' value='5'>PRESS THE BUTTON</button>
</form>

This works correctly (gets the number 5 and passes it on to the php file where it gets processed).

Now I know I'm making a newbie mistake but I can't seem to find an answer for my example when doing my research.

Hope you guys can help me out!

2
  • 1
    Welcome @number42! Can you please give us some additional info, or the code you're using for changing the value of the button? Commented Jan 10, 2020 at 13:25
  • Hi @BrettDeWoody HK KNVB's answer is working. Thank you for the effort! Commented Jan 10, 2020 at 13:30

1 Answer 1

2

You may try:

<form action="getdata.php" method="POST" onSubmit="setValue(this)">
   <button type="submit" class="firstHeavyGame button" name='storage' value=''>PRESS THE BUTTON</button>
</form> 
<script>
    function setValue(v) {
         v.storage.value="5";
         return true;
     }
</script> 
Sign up to request clarification or add additional context in comments.

Comments

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.