PDA

View Full Version : Form action condition


florida
02-03-2003, 10:44 AM
Please advise how on my select choices if someone chooses webPage1 it will do form action using webPage1 and if they choose webPage2 it will use form action webPage2 etc..

I need to make this change on my form action part so when a specific selection is made it will go to a specific web
page, but not sure if I am doing it right??


<script>
function check()
{ if(document.myform.myvalue.options[myform.myvalue.selectedIndex].value == "None")
{
alert("Please select a webpage value")
return false
}
}


if(document.myform.myvalue.options[myform.myvalue.selectedIndex].value == "webpage1")
{
<cfform name="myform" action="webpage1.cfm" onSubmit="return check();">
}
else if(document.myform.myvalue.options[myform.myvalue.selectedIndex].value == "webpage2")
{
<cfform name="myform" action="webpage2.cfm" onSubmit="return check();">
}
else if(document.myform.myvalue.options[myform.myvalue.selectedIndex].value == "webpage3")
{
<cfform name="myform" action="webpage3.cfm" onSubmit="return check();">
}
<script>

<select name="myvalue" size="1">
<option value="None" selected>Select Value</option>
<option value="webPage1">webPage1</option>
<option value="webPage2">webPage2</option>
<option value="webPage3">webPage3</option>
</select>

glenngv
02-03-2003, 11:53 AM
<html>
<head>
<script language="javascript">
function check(f){
if (f.myvalue.selectedIndex==0){
alert("Please select a webpage value");
return false;
}
return true;
}
</script>
</head>
<body>
<form name="myform" onsubmit="return check(this)">
<select name="myvalue" size="1" onchange="this.form.action=this.options[this.selectedIndex].value">
<option value="" selected>Select Value</option>
<option value="webpage1.cfm">webPage1</option>
<option value="webpage2.cfm">webPage2</option>
<option value="webpage3.cfm">webPage3</option>
</select>
<input type="submit" value="submit">
</form>
</body>
</html>

florida
02-03-2003, 02:26 PM
Thanks!

Can you please advise what the "this" part does?
What does "this" represent??

GoHF
02-03-2003, 03:54 PM
this refers to the object that is calling the function.

<form name="myform" onsubmit="return check(this)">

In this case, "this" is the form. If it was

<a href="#" onclick="alert(this.tagName)">Click to know my tagName</a>

"this" would refer to the A tag, to the link.