Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

Change form field value based on the data submitted

Below is the form where a user can either enter the city name or zip code into the field name="city_dist_code" value ="". If the user enters numbers (as in zip code) into name="city_dist_code" value ="" then the name="city_dist_code" should change to name="postalcode_dist_code" right before the form us submitted.

And vise versa, if the letters and commas are entered (as in city name and state), then name="" should be: name="city_dist_code"
<form method="get" action="searchpage.html" onsubmit="return ray.ajax(); sendFormToCMS(this, '/searchpage.html?cmsrealty=user');">
<table>
<tr><td>
*City, ST: <input size="18" id="testinput" type="text" name="city_dist_code" value="" onfocus='if(this.value==this.defaultValue) this.value="";'/>
<select name="city_dist_dist">
<option value="10">+10 miles</option>
<option value="15">+15 miles</option>
<option selected value="30">+30 miles</option>
<option value="50">+50 miles</option>
<option value="100">+100 miles</option>
</select>
<select name="pclass[]">
<option value="">all prop. types</option>
<option selected value="1">homes</option>
<option value="2">land</option>
<option value="5">lease option</option>
<option value="6">multi fam.</option>
<option value="4">commercial</option>
<option value="3">business</option>
</select>
<select name="price-max">
<option value="">max. price</option>
<option value="50000">$50,000</option>
<option value="100000">$100,000</option>
<option value="150000">$150,000</option>
<option value="200000">$200,000</option>
<option value="250000">$250,000</option>
<option value="300000">$300,000</option>
<option value="350000">$350,000</option>
<option value="400000">$400,000</option>
<option value="450000">$450,000</option>
<option value="500000">$500,000</option>
<option value="550000">$550,000</option>
<option value="600000">$600,000</option>
<option value="650000">$650,000</option>
<option value="700000">$700,000</option>
<option value="750000">$750,000</option>
<option value="800000">$800,000</option>
<option value="850000">$850,000</option>
<option value="900000">$900,000</option>
<option value="950000">$950,000</option>
<option value="999999">$999,999</option>
<option value="100000000">$1,000,000+</option>
</select>
<input type="hidden" id="zipdist" name="city_dist_dist" value="30" />
<input type="hidden" name="action" value="searchresults" />
<input type="hidden" name="Itemid" value="2" />
<input type="submit" value="Search" />
</td></tr></table></form>

<div style="font-size: 10px;">Type city name followed by abbreviated state separated by a comma...<br /></div>
</div>

<script type="text/javascript">
var options = {
	script: "/modules/mod_ajaxsuggest/test.php?json=true&",
	varname: "input",
	json: true,
	maxresults:25
	};
var as = new bsn.AutoSuggest('testinput', options);
</script>

Open in new window

0
greenerpastures
Asked:
greenerpastures
  • 2
2 Solutions
 
Michel PlungjanIT ExpertCommented:
May I ask why you do not test on the server instead? If the change is not for the benefit of the user, it is not good practise the change the form field names sine it is not guaranteed the will change (JS off or blocked by the client)
0
 
greenerpasturesAuthor Commented:
Actually you have a good point. I was able to come up with the solution on the server-side. Thanks.
0
 
greenerpasturesAuthor Commented:
I used preg_replace() and header() to redirect after form submission
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now