Forum Moderators: open

Message Too Old, No Replies

Changing an email address on a form

         

pmcshane

7:37 pm on Nov 22, 2004 (gmt 0)

10+ Year Member



Hi

Would anyone know where I could get a script to do the following:

I'm setting up a mailing list and the user can either select subscribe or unsubscribe using a radio button. If they select subscribe then I need to fire off a mail to subscribe@******.com and if they choose unsubscribe the mail is sent to unsubscribe@*****.com

If anyone knows a script that can do this or a good tutorial I could check out I would be grateful for the advice.

Thanks in advance.

kaled

2:47 am on Nov 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



function adjustAction(mb)
{ document.forms[0].action="mailto:" + mb + '@domain.com';
}

<input type="radio" value="subscribe" name="sub" onclick="adjustAction(this.value)>
<input type="radio" value="unsubscribe" name="sub" onclick="adjustAction(this.value)>

Typos aside, etc. (I'm about to go to bed) the code above should be adaptable to your needs.

Kaled.

whoisgregg

6:55 am on Nov 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



onclick="adjustAction(this.value)> should be

onclick="adjustAction(this.value);">

That's all I see for typos. But then again, I'm pretty tired too. :)

kaled

11:35 am on Nov 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's an improved version (that will work when there are multiple forms on the page).

function adjustAction(rb)
{ rb.form.action="mailto:" + rb.value + '@domain.com';
}

<input type="radio" value="subscribe" name="sub" onclick="adjustAction(this);">
<input type="radio" value="unsubscribe" name="sub" onclick="adjustAction(this);">

Incidentally, you should wrap the radio buttons in <label> tags. This way, clicking the label activates the control.

e.g.

<label><input type="radio" .....>subscribe</label>

Kaled.

pmcshane

2:48 pm on Nov 23, 2004 (gmt 0)

10+ Year Member



Hi

Thanks for all the help. I've had to sit back and look at it and probably didn't describe very well what I wanted to do. I should have said that I'll be using formail to process the form using the following:

<form action="/cgi-bin/formmail.pl" method=post>
<input type=hidden name="recipient" value="subscribe@thisdomain.com">

So what I need to do is change the value of the "recipient" depending on the radio button (subscribe or unsubscribe) selected by the user.

My javascript is not strong so I'm not sure if I have made it easier or more difficult.

Thanks Again.

whoisgregg

4:32 pm on Nov 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



function adjustAction(rb)
{ rb.form.recipient.value= rb.value + '@domain.com';
}

Use the same input tags tags provided already for the radio buttons. :)

kaled

4:40 pm on Nov 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



function adjustRecip(rb)
{
var recip = document.getElementById('recip');
if (recip) recip.value = rb.value + '@domain.com';
}

<input type=hidden name="recipient" id="recip" value="subscribe@thisdomain.com">

That should do it. (Don't forget to adjust the onclick values to reflect the change of function name).

Kaled.