Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changeAction is not defined 1

Status
Not open for further replies.

AGus01

Technical User
Sep 6, 2005
54
GB
Hi Long time since I had to look at any javascript I get the error changeAction is not defined please advise?

I basically want to redirect the user to different pages based on the selection of a radiobutton.

javascript:
Code:
<script language="javascript">

function changeAction(eventid) {
                if (document.form1.veg1.value == "cabbage") {
                    window.location = "[URL unfurl="true"]http://www.google.com/";[/URL]  
                }
                if (document.form1.veg1.value == "carrot") {
                    window.location = "[URL unfurl="true"]http://www.sbs.ox.ac.uk/";[/URL]
                }
</script>

html:
Code:
  			<form name="form1">
               cabbage:
            <input checked="checked" name="veg1" type="radio" value="cabbage" />

            carrot:
            <input name="veg1" type="radio" value="carrot" />
            <input onclick="javascript:changeAction('a0UQ00000007PwCMAU')" type="button" value="Submit" />
           </form>
 
Hi

Because indeed there is no changeAction defined. It would be defined if it would be complete. And it would be complete if the closing brace ( } ) would exist at the end of the [tt]function[/tt] declaration.

Beside that
[ul]
[li]do not use [tt]javascript:[/tt] pseudo-protocol when specifying code in the [tt]onclick[/tt] or other event-related attributes[/li]
[li]when you have more than one [tt]form[/tt] element with the same [tt]name[/tt], referencing them by [tt]name[/tt] will get an array of those element[/li]
[/ul]


Feherke.
 
Hi thanks for your help got there in the end:

Code:
<script language="javascript">

function changeAction(eventid) {
                if (document.form1.veg1[0].value == "cabbage" && document.form1.veg1[0].checked) {
                    window.location = "[URL unfurl="true"]http://www.google.com/";[/URL]  
                }
                if (document.form1.veg1[1].value == "carrot" && document.form1.veg1[1].checked) {
                    window.location = "[URL unfurl="true"]http://www.sbs.ox.ac.uk/";[/URL]
                }
	}

</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top