문제

I've built a simple time picker within a form and decided to use a button which toggles between "am" and "pm" onClick. My problem is that if I use

<input type="button" value="AM" name="someName[]" onClick="clockswap(this)">

The $_POST data doesn't contain the button's value. I can get the value to come through as expected if I change the input type to "submit"

<input type="submit" value="AM" name="someName[]" onClick="clockswap(this)">

However, when type="submit" this button will trigger the form to submit and I obviously don't want the form to submit when the user chooses between "AM" and "PM"

Is there something I've overlooked to allow me to have a button who's value get's posted with the rest of the form data but does not also trigger the submission of the form?

도움이 되었습니까?

해결책

I normally don't see a button used like this, but usually something like a radio button.

The best way I would know how to handle this, while maintaining the button, would be to add a <input type="hidden"/> field, and since you already have a clockswap JavaScript function, update the value of the hidden field with the value that you want to be posted as part of your form as part of that function.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top