www.webdeveloper.com
Results 1 to 3 of 3

Thread: is it possible to fill in the form action=" " with javascript?

  1. #1
    Join Date
    Mar 2007
    Posts
    3

    is it possible to fill in the form action=" " with javascript?

    I'm trying to adapt a 'spam proof' javascript email link to be used with a mailto: form.

    The javascript function is this:

    <script language="JavaScript">
    <!--
    function mail()
    {
    var name="name";
    var domain="domain.com";

    document.write("'mailto:' + name + '@' + domain'");

    }
    -->
    </script>


    and the form begins:

    <form method="post" action="javascript:mail()" >

    This just returns 'mailto:' + name + '@' + domain' in the browser window, and doesn't mail anything.

    I know mailto isn't the best way to do this, but the specification given is that it has to be a mailto form, and use the code to spam proof the email address.

    If anyone could give me some suggestions on how to accomplish this I'd really appreciate it. I believe document.write isn't the correct thing to be using, but I am unsure what to replace it with.

    Thanks very much for any help.

  2. #2
    Join Date
    Sep 2006
    Location
    Bucharest, RO
    Posts
    940
    1. Give your form an ID, like <form id="myForm">
    2. After your form, add this:
    Code:
    <script type="text/javascript">
    document.getElementById('myForm').action = "mailto:" name + "@" + domain;
    </script>
    If that doesn't work, try:
    Code:
    <script type="text/javascript">
    document.getElementById('myForm').setAttribute("action", "mailto:" + name + "@" + domain);
    </script>
    Hope that helps .

  3. #3
    Join Date
    Mar 2007
    Posts
    3
    Thanks very much for the reply, that seems to have worked perfectly.

    Can't tell you how much I appreciate the help
    Last edited by wolfestone; 03-25-2007 at 04:00 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles