JavaScript Submitting form depend of color clicked

i have form that's announcing user for error, warning or new content on my site. I have three buttons on class ann-right and each button have its color. When i click the button, the button input on class ann-left changed to color were clicked. What i want to ask is, how do i submit the form depend of color selected. Red is for "Error announcement", Green is for "Warning announcement" and Blue is for "New announcement". Red = #D91E18 Green = #3FC380 Blue = #5BBBFF

  <div class="ann-left">
  <form method="post" id="ann">
     <input id="announce-text" type="text" name="" placeholder="What's new?"></input>
     <input id="submit-post" type="button" name="" onsubmit="submitform();" value="Post"></input>
  </form>
  </div>
  <div class="ann-right">
   <button id="red" onclick="color1()" class="tooltip color" title="Error!"></button>
   <button id="green" onclick="color2()" class="tooltip color"title="Warning!" ></button>
   <button id="blue" onclick="color3()" class="tooltip color" title="New!"></button>
  </div>

<script>  
function color1() {
  document.getElementById("submit-post").style.backgroundColor = "#D91E18";
  sessionStorage.setItem('col1', "#D91E18");
}
function color2() {
  document.getElementById("submit-post").style.backgroundColor = "#3FC380";
  sessionStorage.setItem('col2', "#3FC380");
}
function color3() {
  document.getElementById("submit-post").style.backgroundColor = "#5BBBFF";
  sessionStorage.setItem('col3', "#5BBBFF");
}

color1(sessionStorage.getItem('col1'));
color2(sessionStorage.getItem('col2'));
color3(sessionStorage.getItem('col3'));

function submitform() {
}
</script>
Answer:1

You can use one input hidden to pass the type of annoncement to your form. Then you submit it normally.

  <div class="ann-left">
  <form method="post" action="announcement_post.php" id="ann">
     <input type="text" name="announcement_description" id="announce-text"  placeholder="What's new?">
     <input type="hidden" name="announcement_type" id="announcement_type">
     <input id="submit-post" type="submit" name="" value="Post">
  </form>
  </div>
  <div class="ann-right">
   <button id="red" onclick="color1()" class="tooltip color" title="Error!">&nbsp;</button>
   <button id="green" onclick="color2()" class="tooltip color"title="Warning!" >&nbsp;</button>
   <button id="blue" onclick="color3()" class="tooltip color" title="New!">&nbsp;</button>
  </div>

<script>  
function color1() {
  document.getElementById("submit-post").style.backgroundColor = "#D91E18";
   document.getElementById("announcement_type").value="Error announcement";
  sessionStorage.setItem('col1', "#D91E18");
}
function color2() {
  document.getElementById("submit-post").style.backgroundColor = "#3FC380";
   document.getElementById("announcement_type").value="Warning announcement";  
  sessionStorage.setItem('col2', "#3FC380");
}
function color3() {
  document.getElementById("submit-post").style.backgroundColor = "#5BBBFF";
   document.getElementById("announcement_type").value="New announcement";   
  sessionStorage.setItem('col3', "#5BBBFF");
}

color1(sessionStorage.getItem('col1'));
color2(sessionStorage.getItem('col2'));
color3(sessionStorage.getItem('col3'));

</script>

announcement_post.php:

<?php

if(!isset($_POST["announcement_type"])) die("Post was not sent.");

echo $_POST["announcement_type"];
echo '<br>';
echo $_POST["announcement_description"];
Answer:2

I have a input box. I enter the search term and the values get returned. What I am trying to do is click the dynamic button with the value attached to it. However when I click on the button it reloads ...

I have a input box. I enter the search term and the values get returned. What I am trying to do is click the dynamic button with the value attached to it. However when I click on the button it reloads ...

  1. jquery dynamic button click
  2. jquery dynamic button click handler
  3. jquery dynamic button event
  4. jquery dynamic button not working
  5. jquery dynamic button click function
  6. jquery dynamic button create
  7. jquery dynamic button bind
  8. jquery button dynamic id
  9. jquery dynamic radio button click event
  10. jquery dialog dynamic buttons
  11. jquery dynamic radio button
  12. jquery get dynamic button id
  13. jquery dialog dynamic button text
  14. jquery dynamic add button
  15. jquery dynamic change button text
  16. jquery dynamic radio button change
  17. jquery dynamic radio button checked
  18. jquery datatable dynamic button
  19. jquery disable dynamic button
  20. jquery ui dialog dynamic buttons

I have been trying to setup a server where users can send sign in using websockets, but I don't want to do this using ws. I want to be able turn on wss without having https. Sadly, there aren't any ...

I have been trying to setup a server where users can send sign in using websockets, but I don't want to do this using ws. I want to be able turn on wss without having https. Sadly, there aren't any ...

I have 2 select menus on my form: Type and Category. When a user selects something from the Type menu I want it to then perform a PHP script which queries a database and returns a list of matching ...

I have 2 select menus on my form: Type and Category. When a user selects something from the Type menu I want it to then perform a PHP script which queries a database and returns a list of matching ...

<form id="participantsForGd"> <span id="GroupID"></span> //in here group id is coming example: 2 <button id="GdStartTest">Start test</button> </form> I want to ...

<form id="participantsForGd"> <span id="GroupID"></span> //in here group id is coming example: 2 <button id="GdStartTest">Start test</button> </form> I want to ...