user1975196
user1975196

Reputation: 33

Javascript OnSubmit won't change the form's action

EDIT: Resolved. I didn't add quotations!

I am trying to update a form's action depending on the value inside a select box using JavaScript.

So far I have:

<form name="newStudent" method="POST" onsubmit=newStudent.action = document.newStudent.proceed.value>

and further down in my code:

<select name="proceed">
<option value="newSchedule.php">add student's schedule</option>
<option value="newStudent.php">add another student</option>
<option value="staff.php">staff page</option>;

Nothing happens when the submit button is pressed. What am I doing wrong? The current page is newStudent.php so the form should redirect to newSchedule.php since it is selected.

Upvotes: 0

Views: 1133

Answers (2)

Zhou Lee
Zhou Lee

Reputation: 96

try this:

<form name="newStudent" method="POST" onsubmit="this.action = document.newStudent.proceed.value">

Upvotes: 0

Guffa
Guffa

Reputation: 700342

The attribute value contains spaces, so you need quotation marks around it:

<form name="newStudent" method="POST" onsubmit="newStudent.action = document.newStudent.proceed.value">

Upvotes: 2

Related Questions