|
-
Jun 19th, 2003, 04:32 PM
#1
Thread Starter
Lively Member
Changing the ACTION value in an HTML form
I have a form in HTML and want to change the ACTION based on which email the user selects.....
Code:
<SCRIPT LANGUAGE="JavaScript">
function click()
{
var number=eval("document.myform.contact.selectedIndex")
document.myform.action="mailto:"+document.myform.contact[number].value
}
</script>
<FORM NAME="myform" METHOD="POST" ACTION="mailto:[email protected]">
<SELECT NAME="contact" SIZE="1" onChange="click">
<OPTION Value="[email protected]" SELECTED>[email protected]</Option>
<OPTION Value="[email protected]">[email protected]</Option>
</SELECT>
<INPUT TYPE="submit" Value="Submit Inquiry" onClick="click">
<INPUT TYPE="reset" Value="Reset Form" onClick="document.myform.reset()">
</Form>
It seems like it should work, although it doesn't .... THanks for any help
-
Jun 20th, 2003, 12:43 PM
#2
Several problems:
1) Javascript is case sensitive. Also, when calling a method, whether or not it returns anything, you must use parentheses - it's viewed as a property otherwise.
2) function click() isn't particularly user friendly, rather use a decriptive name 
3) No need to use eval.
4) Maybe a little pedantic, but work out a standard for your HTML - while the changing case doesn't affect anything, it's unsightly & will become hard to read after a couple of hundred lines.
5) You only need to call the setMailTo() method once - the onchange event.
Anyway, to answer your question:
Code:
<html>
<body>
<script language="JavaScript">
function setMailTo() {
document.myForm.action = document.myForm.contact[document.myForm.contact.selectedIndex].value;
}
</script>
<form name="myform" id="myForm" method="POST" action="mailto:[email protected]">
<table>
<tr>
<td> Mail To:
<select name="contact" id="contact" onchange="javascript:setMailTo();">
<option value="[email protected]" selected>[email protected]</option>
<option value="[email protected]">[email protected]</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit Enquiry">
<input type="reset" value="Reset Form">
</td>
</tr>
</table>
</form>
</body>
</html>
-
Jun 22nd, 2003, 04:59 AM
#3
Registered User
hello brother
try this
document.myForm.action = document.myForm.contact[document.myForm.contact.selectedIndex].value;
-
Jun 22nd, 2003, 01:35 PM
#4
Originally posted by rangeela
try this
document.myForm.action = document.myForm.contact[document.myForm.contact.selectedIndex].value;
Reading the previous reply might have saved you all that typing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|