Click to See Complete Forum and Search --> : dynamically change form action attribute
BananaQuaalude
05-09-2003, 10:46 AM
Is there a way to use a client-side function to change the the action attribute of my form?
Why won't this work:
function Reload() {
document.frmRequest.txtRefresh.value = "Refresh"
}
function formSubmit() {
if (document.frmRequest.txtRefresh.value = "Refresh") {
return "RFS-Edit.asp" [reload this page]
} else {
return "RFS-Update.asp" [another page]
}
}
<form name="frmRequest" method="post" action="formSubmit()">
<select name="cboRequest" onChange="Reload()">
Obviously this isn't all the code, but the browser tries to load a page called formSubmit() instead of what should be returned from the function.
Anyone? Anyone?
khalidali63
05-09-2003, 10:50 AM
function formSubmit() {
if (document.frmRequest.txtRefresh.value = "Refresh") {
document.frmRequest.action= "RFS-Edit.asp";
} else {
document.frmRequest.action= "RFS-Update.asp"
}
}
The above should do it.
BananaQuaalude
05-09-2003, 12:11 PM
Okay, that works when I'm refreshing the page (I call the function in the onSubmit attribute), but not when I want to actually submit the form. Here's what I have:
function Reload() {
document.frmRequest.txtRefresh.value = "Refresh"
document.frmRequest.submit()
}
function ResetBox() {
document.frmRequest.txtRefresh.value = ""
document.frmRequest.submit()
}
function formSubmit() {
if (document.frmRequest.txtRefresh.value = "Refresh") {
document.frmRequest.action = "RFS-Edit.asp"
} else {
document.frmRequest.action = "RFS-Update.asp"
}
}
<form name="frmRequest" method="post" onSubmit="formSubmit()" action="">
<input name="btnTest" type="button" onClick="ResetBox()" value="Test"></td>
In a nutshell, what I'm doing is if a select box is changed the page reloads, populating a number of fields by the option value. When the page is submitted, I'm sending those values and a number of other fields to another page. I want to do this on one form, hence the need to change the action attribute. But when I submit, it just reloads the page, ignoring the else portion of that logic.
Thanks!
khalidali63
05-09-2003, 01:38 PM
if (document.frmRequest.txtRefresh.value = "Refresh") {
the line above is a wrong syntax for comparison,
the above is actually assigning a value to the field for comparison u need to use ==
if (document.frmRequest.txtRefresh.value == "Refresh") {
Make sense..:p
BananaQuaalude
05-09-2003, 02:51 PM
Yes- thank you. I'm switching back and forth between JavaScript and VBScript and keep making syntax errors such as that.
Thanks for your help- it's working the way I want it to now.