Click to See Complete Forum and Search --> : JavaScript String Variable Question


partyman66
December 12th, 2002, 10:41 AM
I'm trying to use a Javascript Form to launch another web page, but the web address that it launches will change based on info on screen with the form. I have the address that I want to go to stored as a String in a variable, but I can't get that variable to be recognized as a String in the "action" part of the form. It just takes the variable name and tries to use that as the address rather than the value stored at that variable.

Example:
<form name="players" method="post" action = theString>

Does anyone know how to make the link go to the theString variable's String value as a Web Address in this situation?

websmith99
December 12th, 2002, 02:45 PM
Here you go:

<html>
<head>
<script language="JavaScript" type="text/javascript">
function changeAction() {
document.players.action = document.players.frmAction.value;
}
</script>
</head>
<body>
<form name="players" method="get" action="http://www.yahoo.com" onsubmit="changeAction()">
Go to this page: <input type="text" name="frmAction">
<input type="submit" value="Go">
</form>
</body>
</html>

Just keep in mind that a lot of sites have disabled post action to their site, so you might have to always use the "get" method. Using the "get" method will work depending on the site. (some sites will not allow this either if you are passing an unrecognized parameter) All of this is due to security concerns.