Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't change a post form variable at run time

Status
Not open for further replies.

aspro

Programmer
Jan 22, 2003
69
AU
Hi,
I am setting up a mailing list and it all very new to me. I was given some code for adding people to the list however no removing. what i have is 2 radio buttons (subsribe and unsubscribe) which u choose before submitting the email address. when the unsubscribe button is chosen i wanted the variable "action" to change from "add" to "remove" and vise-versa. Below is my code, if someone could have a look and spot any problems it would help because nothing seems to be happening as far as i know.

This is my script
<script Language=&quot;JavaScript&quot;><!--
function subscribe(BMS)
{
if (BMS.RG[0].checked == true)
{
action.value=&quot;add&quot;;
}
if (BMS.RG[1].checked == true)
{
action.value=&quot;remove&quot;;
}
};

function validate(busmailsubscribe)
{
if (busmailsubscribe.email.value == &quot;&quot;)
{
alert(&quot;Please enter an email address&quot;);
busmailsubscribe.email.focus();
return (false);
}
if (busmailsubscribe.email.value.length < 2)
{
alert(&quot;Not a valid email address&quot;);
busmailsubscribe.email.focus();
return (false);
}
subscribe(busmailsubscribe);
return (true);
};
//--></script>

and my form
<form action=&quot; method=&quot;POST&quot; name=&quot;busmailsubscribe&quot; id=&quot;busmailsubscribe&quot; onsubmit=&quot;return validate(this)&quot;>
<p>
<input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;add&quot;>
<input type=&quot;hidden&quot; name=&quot;mailinglist&quot; value=&quot;BusMail@dions.com.au&quot;>
<input type=&quot;hidden&quot; name=&quot;redirect&quot; value=&quot; <input type=&quot;hidden&quot; name=&quot;nowait&quot; value=&quot;1&quot;>
<br>
<label>
<input name=&quot;RG&quot; type=&quot;radio&quot; value=&quot;subscribe&quot; checked>
Subscribe</label>
<label>
<input type=&quot;radio&quot; name=&quot;RG&quot; value=&quot;unsubscribe&quot;>
Unsubscribe</label>
<br>
<br>
Email Address
<input name=&quot;email&quot; type=&quot;text&quot; size=&quot;20&quot; maxlength=&quot;50&quot;>
<br>
<br>
<input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;Submit&quot;>
</p>
</form>
 
the hidden form field named &quot;action&quot; is going to conflict with the form's &quot;action&quot; attribute when you try to change its value. you might not be able to do it this way. i would suggest removing the hidden field &quot;action&quot; and renaming your radio buttons to &quot;action&quot;

<label>
<input name=&quot;action&quot; type=&quot;radio&quot; value=&quot;add&quot; checked>
Subscribe</label>
<label>
<input name=&quot;action&quot; type=&quot;radio&quot; value=&quot;remove&quot;>
Unsubscribe</label>


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
i was wondering about the jave script? I will change
if (BMS.RG[0].checked == true)
{
action.value=&quot;add&quot;;
}
to
if (BMS.action[0].checked == true)
{
action.value=&quot;add&quot;;
}
Will that still work?
 
this way you wouldn't have to use javascript...the user is going to set the &quot;action&quot; by clicking the radio button.


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top