Web Analytics Made Easy -
StatCounter Changing href links based on forms - CodingForum

Announcement

Collapse
No announcement yet.

Changing href links based on forms

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Changing href links based on forms

    I thought this would be so easy but I have spent all day looking for the answer.

    http://www.seat9k.com/dropdown.html

    What I would like to do is direct the user to a new page that is indicated by the different options chosen by the user.

    If the user chooses "DOG" and "RED", upon hitting SUBMIT a new window would open:

    http://www.seat9k.com/dogred.html

    I cannot figure out how to do this, and it seems like it should be obvious.

    I fiddled around with javascript - which I have never used before - but am confused and tired!

    Any help greatly appreciated.

  • #2
    specify a value for the option, or use the option.text property.

    when writing an option tag you can specify a value as such:
    Code:
    <option value="red">A Red Color</option>
    the above option will have two properties
    .value == "red"
    .text == "A Red Color"

    You can change your code in two ways to get it to work.

    Option 1 supply the value attribute that you are trying to use.
    Code:
    		<select name=Animal id="option1" size=1>
    			<option value="dog">Dog</option>
    			<option value="cat">Cat</option>
    			<option value="bird">Bird</option>
    		</select></td></tr>
    
    		<tr>
    		<td align=right>Color:</td>
    		<td>
    		<select name=Color id="option2" size=1>
    			<option value="red">Red</option>
    			<option value="green">Green</option>
    			<option value="yellow">Yellow</option>
    		</select></td></tr>
    or use the .text attribute that you have allready specified.
    Code:
    			<input type=button value="Submit" 					onClick="window.open('http://www.seat9k.com/'+Animal.options[Animal.selectedIndex].text+Color.options[Color.selectedIndex].text+'.html')">
    Note: "Animal" is a refrence to the combo box named "Animal".
    to get a refrence to the currently selected option we look up the Animal.selectedIndex index of the Animal.options array.
    Code:
    var currentAnimal = Animal.options[Animal.selectedIndex];
    you can then access the properties of the currently selected option
    Code:
    var selectedAnimalDescription = currentAnimal.text;
    var selectedAnimalValue = currentAnimal.value;

    Comment

    Working...
    X