CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2001
    Posts
    27

    JavaScript String Variable Question

    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?

  2. #2
    Join Date
    Aug 2002
    Location
    Reykjavik, Iceland
    Posts
    201
    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.

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

Featured