Want to grab Page Title and include in form when submitted

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johnbob2010
    New Member
    • Jan 2010
    • 2

    Want to grab Page Title and include in form when submitted

    Is it possible to grab something off a given web page (like page title) and send that along with the form when they click submit? I guess the question is - can I variablize the page title and then pull that variable into the form when submitting? I am using bnbform.cgi on my web host.
  • larztheloser
    New Member
    • Jan 2010
    • 86

    #2
    The page title can be accessed with a simple reference to "document.title ". Then you would set the value of a hidden form field to the value of this variable.

    Comment

    • johny10151981
      Top Contributor
      • Jan 2010
      • 1059

      #3
      you can try this

      Code:
      <form action="whatever" method="get"  name="myform" onsubmit="this.action = replace_space('whatever?pagetitle=' + document.title)">
      
      function remove_space() \\will replace space will replace all space in the created string with  + 
      { //it will return the string where all spaces is replaced by +
       ...
       ...
      } //dont know the code for rpaceing
      but you I am not sure whether it would work or not if title hold different character like Japanese or Chinese font

      regards,
      johny

      Comment

      • larztheloser
        New Member
        • Jan 2010
        • 86

        #4
        My method would look like this:

        Code:
        <form onsubmit="addTitle();">
        <input type="hidden" name="title">
        <input type="text" name="otherInfo" value="type something here...">
        <input type="submit" value="submit">
        </form>
        <script type="text/javascript">
        function addTitle()
        {
        document.forms[0].title.value = document.title;
        }
        </script>
        I don't actually think you need to format spaces as they'll be converted to unicode by the browser so will look like this: %20

        Comment

        Working...