Change form field value based on the data submitted

Posted on 2011-10-22
Last Modified: 2012-05-12
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');">
*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 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 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>
<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" />

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

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

Open in new window

Question by:greenerpastures
    LVL 75

    Accepted Solution

    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)

    Assisted Solution

    Actually you have a good point. I was able to come up with the solution on the server-side. Thanks.

    Author Closing Comment

    I used preg_replace() and header() to redirect after form submission

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
    Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now