0

In the below code I am able to get the alert message to display correctly displaying the message and the number "3". Does anyone know how to use that passes variable/number to declare a form element named "priority" to be passed to the form before submitting?

My goal is to use $_POST["priority"] and generate the number 1, 2, or three based on which link/button is clicked.

 <script language="JavaScript">
    function submitForm(priority)
    {
      alert("Changing to Priority " + priority);
      document.frm.submit();
    }
 </script>

<a href="javascript: submitForm('3');" class="ddm"><span class="label">Low</span></a>
<a href="javascript: submitForm('2');" class="ddm"><span class="label">Medium</span></a>
<a href="javascript: submitForm('1');" class="ddm"><span class="label">High</span></a>
m1e1b1
  • 71
  • 1
  • 8

2 Answers2

0

Add a hidden field in the form:

<input id='priority' name='priority' type='hidden'/>

Before the last form submit call, add something like this:

document.getElementById('priority').value = priority;
su-
  • 3,116
  • 3
  • 32
  • 42
  • There are going to be 3 different submit links (buttons) which i am marking as high, medium, and low. When I click on the link the value is sent to the function... hence, i don't see how a hidden field would work – m1e1b1 May 15 '13 at 02:46
  • You have a form, right? Just place the hidden field in that form. When a link is clicked, the priority value (either 1, 2 or 3) is passed to the function, and in the function you set that value as the hidden field's value. Then when you submit the form, the hidden field would be submitted since it's part of the form. – su- May 15 '13 at 02:53
  • Thank you! I am new to JS. You were a big help. It worked great. – m1e1b1 May 15 '13 at 03:13
0

You don't need any script, use 3 submit buttons:

<button type="submit" name="priority" value="1">Priority 1</button> 
<button type="submit" name="priority" value="2">Priority 2</button> 
<button type="submit" name="priority" value="3">Priority 3</button> 

Only the one that is clicked will send it's value to the server.

RobG
  • 142,382
  • 31
  • 172
  • 209