SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need to dynamically change the form action depending on radio button selected

    I need to change the form action depending on which radio button is selected. The catch here is that the form action is using mailto: with an encoding type. I can successfully change the action, but it does not retain the enctype, therefore it does not post the form to the email client. Really all I want to change is the subject part of the mailto line.

    So I have 3 different options for the action line, depending on which is selected for the radio button, that is the one that will submit and create a customized subject line:

    <form method="post" action="mailto:mail@mail.com?subject=Subject1" enctype="text/plain" name="Subject1">

    <form method="post" action="mailto:mail@mail.com?subject=Subject2" enctype="text/plain" name="Subject2">

    <form method="post" action="mailto:mail@mail.com?subject=Subject3" enctype="text/plain" name="Subject3">

    Best way to handle this with javascript?

  2. #2
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does a form even work with action mailto:mail@mail.com?subject=Subject ?
    I don't think it would, but here's how to proceed with what you're doing.

    Code JavaScript:
    function changeAction(radio) {
        radio.form.setAttribute('action', radio.value);
    }

    Code HTML4Strict:
    <input type="radio" onchange="changeAction(this);" value="mailto:mail@mail.com?subject=Subject1"/> Subject 1
    <input type="radio" onchange="changeAction(this);" value="mailto:mail@mail.com?subject=Subject2"/> Subject 2
    <input type="radio" onchange="changeAction(this);" value="mailto:mail@mail.com?subject=Subject3"/> Subject 3
    FOR SALE: 1 set of morals, never used, will sell cheap


Bookmarks

Posting Permissions

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