Form action incorrect when set with Javascript -


i have form on page 2 inputs. on submission, page redirected link contains values of 2 inputs, plus preceding string. html following:

<form name="searchform">     <label for="property_type">property type</label>     <select name="property_type" id="property_type_number">         <option value>- property types -</option>         <option value="1432">commercial</option>         <option value="1433">land</option>         <option value="1434">multifamily</option>         <option value="1435">rental</option>         <option value="1436">residential</option>         <option value="1988">residential / condo</option>         <option value="1987">residential / single family</option>     </select>      <label for="city">city</label>     <select name="city" id="city_number">         <option value>- property types -</option>         <option value>--</option>         <option value="cambridge">cambridge</option>         <option value="zanesville">zanesville</option>     </select>      <input type="submit" value="search properties" onclick="searchform()"> </form> 

and javascript following:

function searchform()  {     var propertytype = document.getelementbyid("property_type_number").value;     var city = document.getelementbyid("city_number").value;      target = "/idx/?" + city + propertytype + "hi";      document.searchform.action = target; } 

when submit form, seems use first string of target variable ("/idx/?") ignore rest. inserts values form automatically. go custom target such 1 above.

if want see on web, address is: http://lainegabriel.net/ (it last widget on left).

well, can't explain why form behaves such, or why doesn't work, since appear every bit of information online says you're doing.. can however, provide work-around:

firstly, change html this, deleting 'onclick' submit button, , replacing form tag:

<form name="searchform" onsubmit="return searchform();"> 

secondly, in searchform() function:

function searchform() {     var propertytype = document.getelementbyid("property_type_number").value;     var city = document.getelementbyid("city_number").value;       target = "/idx/?" + city + propertytype + "hi";      document.searchform.action = target; // left in here in case wanted it.     window.location.href = target; // redirect window new url/action     return false; // prevent default submit action occurring } 

demo


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

What is the difference between data design and data model(ERD) -

ios - Can NSManagedObject conform to NSCoding -