Solved

<option in <select statement needs to use onChange event to change action

Posted on 2011-03-08
2
280 Views
Last Modified: 2012-05-11
I have the following form where the options will in some cases dictate a change in action.  This is not working, how do I get this form to work?  I cannot put the onChange on the select statement because I need it to change based on the <option selected.

<form style="margin:0px;" action="/lee-county/residential?frame=RESI" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
    <tr>
      <td><div style="padding-bottom:4px;">City: <select name="search_city">
        <option value="Alva">Alva</option>
        <option value="Bonita Springs" onChange="this.form.action='?frame=RESI&base=frames-collier';" >Bonita Springs</option>  
        <option value="Another" onChange="this.form.action='?frame=LOTL&base=frames-sanibel';" >Another</option>  
      </select></div>                   
<input type="image" id="WADbSearch1" name="WADbSearch1" src="/images/search.png" value="Submit">
		</form>                                                            
                        </td>
    </tr>
  </table>	
</form>

Open in new window

0
Comment
Question by:pda4me
2 Comments
 
LVL 15

Accepted Solution

by:
ncoo earned 500 total points
Comment Utility
Add the following javascript to your page:

 
<script>
function dosomething() {
	var search_city = document.getElementById('search_city');
	var form = document.getElementById('form');
	if (search_city.value=='Bonita Springs') {
		form.action='?frame=RESI&base=frames-collier';
	} else if (search_city.value=='Another') {
		form.action='?frame=LOTL&base=frames-collier';
	}
	//comment out line, for testing only
	alert(form.action);
}
</script>

Open in new window


Update the html as follows:  

<form style="margin:0px;" action="/lee-county/residential?frame=RESI" method="post" id="form">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
    <tr>
      <td><div style="padding-bottom:4px;">City: <select id="search_city" name="search_city" onchange="dosomething()">
        <option value="Alva">Alva</option>
        <option value="Bonita Springs">Bonita Springs</option>
        <option value="Another">Another</option>
      </select></div>
<input type="image" id="WADbSearch1" name="WADbSearch1" src="/images/search.png" value="Submit">
		</form>
                        </td>
    </tr>
  </table>
</form>

Open in new window


The onchange is on the select but we're checking the value each time.

Comment out the alert, it's only there for testing.
0
 

Author Closing Comment

by:pda4me
Comment Utility
U R A ROCKSTAR!!!!!  THANKS SO MUCH!!!
0

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 will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

772 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

10 Experts available now in Live!

Get 1:1 Help Now