javascript - Submit an input box OR a select box (not both) -


i want have option users submit form have option either use either select box or input text box, not both. here form code:

    <!-- text input-->     <div id="incident-type" class="control-group">       <label class="control-label" for="textinput">incident type (use box or common incident box)</label>       <div class="controls">         <input id="textinput" name="incident_type" type="text" class=" form-control">       </div>      </div>    <!-- select box -->            <div id="incident-control-box" class="control-group">       <label class="control-label" for="textinput">common incidents (use box or incident type box)</label>       <div class="controls">         <select onclick="hideinputbox()" id="textinput incident-type1" name="incident_type" type="text" class=" form-control" >             <option value="blank"></option>       <option value="afa commercial">afa commercial</option>       <option value="afa residential">afa residential</option>       <option value="mva w/injuries">mva w/injuries</option>       <option value="gas leak outside">gas leak outside</option>       <option value="gas leak inside">gas leak inside</option>       <option value="investigation">investigation</option>       <option value="possible structure fire">possible structure fire</option>            </select>       </div>      </div> 

then here code php gets input boxes of form:

  $incident_type     = $row['incident_type']; 

the problem run want either 1 of them submit depending on user chooses fill out. select input works, not text box input also.

update: see answer added below, have figured out.

unfortunately, won't able way you're trying because incident_type parameters collide. when happens, servers pick 1 arbitrarily - i've seen take last 1 in parameter list. you're going want give inputs different names, have lots of options:

  • use text box if it's not empty, since it's more custom.
  • use text box if select blank.
  • force select selection , provide other option. use text box if other selected.
  • make user explicitly pick use toggle (that can hide input not being used, if like). submit toggle's value too, , use field specifies.

if want keep logic out of server, write javascript toggles name attribute 1 input other. way, 1 sent over, feels sort of gross me.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -