Results 1 to 4 of 4

Thread: Changing the ACTION value in an HTML form

  1. #1

    Thread Starter
    Lively Member Daniel McCool's Avatar
    Join Date
    Oct 2002
    Posts
    127

    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

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    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>

  3. #3
    Registered User
    Join Date
    Oct 2001
    Location
    mysore
    Posts
    60

    hello brother

    try this
    document.myForm.action = document.myForm.contact[document.myForm.contact.selectedIndex].value;

  4. #4
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    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
  •  



Click Here to Expand Forum to Full Width