/    Sign up×
Community /Pin to ProfileBookmark

syntax help needed

In my html I have 2 radio buttons: subscribe and unsubscribe.
Depending on which is selected, I need a variable created with one of 2 email addresses. ie: select subscribe and set the variable “toAddress” = someaddress1 .. if select unsubscribe, select same variable “toAddress” = anotheraddress2.

I was attepting to use onFocus but my syntax or something is wrong:
<INPUT type=radio value=”SUBSCRIBE blablabla” onFocus=”toAddress=[email protected]‘” name=mailing_list>

Anyway, I don’t think the variable is being created, or if it is, then maybe I’m calling it wrong here:
<INPUT type=hidden value=”toAddress” name=submit_to> }

More than likely I’m wrong in both places. Maybe even my methodology is wrong. I do know that the “submit_to” INOUT line works if given a good email address.

I’m somewhat of a newbie so any help is appreciated.

bigMike

to post a comment
HTML

10 Comments(s)

Copy linkTweet thisAlerts:
@PhillMcMar 03.2004 — replace 'onFocus' w/ 'onClick' I am not sure 'onFocus' is a valid event. ?
Copy linkTweet thisAlerts:
@bigmikeauthorMar 03.2004 — Hi -

Boy, taht was fast - thanks.

Yeah, onFocus is valid.

Am I creating the variable "toAddress" properly?

What is the syntax for using the contents of a variable. ie: if toAddress="abc123" hiw do I obtain the "abc123" to use it?

Thanks

bigMike
Copy linkTweet thisAlerts:
@PhillMcMar 03.2004 — If you declare a var in JS it's going to be local and not global. Local values are purged when the method body ends.

Use the input method. Set the 'onClick' of your radiobutton to "document.NameOfYourInput.value="What your want it to equal"

That should work. My JS is rusty, I dont use it much, I mostly do Server Side Scripting. Hope that helps ?
Copy linkTweet thisAlerts:
@bigmikeauthorMar 03.2004 — Hi Phil -

Let me see if I understand: for eith of my radio buttons I

do this....

<INPUT type=radio value="SUBSCRIBE" onClick="document.toAddress.value='[email protected]'"

name=mailing_list>

Then when I want to use the "value" I do this??

<INPUT type=hidden value="document.toAddress.value" name=submit_to> }

Looks good - I just want to make sure I understand it...

Thanks,

bigMike
Copy linkTweet thisAlerts:
@bigmikeauthorMar 03.2004 — Me again -

Phil, it doesn't seem to work. I have tried several diff. combo's of parenthesis or not but to no avail. See below.

I'm sure it's my syntax - somebody can straighten this out??

I'm sure this would be the fastest and easiest way to do it:

<INPUT type=radio value="SUBSCRIBE" onClick="document.toAddress.value='[email protected]'" name=mailing_list>


<INPUT type=hidden value=document.toAddress.value name=submit_to> }

<INPUT type=submit value=Submit>

bigMike
Copy linkTweet thisAlerts:
@PhillMcMar 03.2004 — Ok, how are you doing this? Are you planning to route the user to a new address when the click the radio button, or after they click the radio button and then click a submit button? This is what I would do.

code for subscribe
<i>
</i>&lt;input type="radio" value="Subscribe" onClick="document.nameOfYourHidden.value='theSiteYouArePointngTo'"&gt;

do the same for unsubscribe

Then, on click of a submit button, I would do this
<i>
</i>&lt;input type="submit" value="Go" onClick="window.open(doument.nameOfYourHidden.value)"&gt;

That should work. Like I said, I am rusty on my JS, I may not have the documetn heirarchy right, but that is the jist. ?
Copy linkTweet thisAlerts:
@bigmikeauthorMar 03.2004 — Hi Phil - That solution might work as you have it but unfortunately I'm sending this to a cgi file. The reason I'm doing that is that the first line of the email has to read a certain way and using the gci file works. I actually had this thing working - until my boss said depending on "submit' or 'unsubmit' they have to go to separate email addresses.

So, to answer your question: After the submit button is pressed it goes to the cgi file with, among other info, an email address to send the email to. That is why it would be easier for me to set the correct email address in the html file. The cgi file is rather complex and large (BigNoseBird's version - lot's of validating).

With this in mind, the input lines for subscribe and unsubscribe I have as you have advised.

It's this line...

<INPUT type=hidden value=document.toAddress.value name=submit_to> }

.. that needs to contain the correct email address for the cgi file.

I hope that is clearer.

bigMike
Copy linkTweet thisAlerts:
@PhillMcMar 03.2004 — It's this line...

<INPUT type=hidden value=document.toAddress.value name=submit_to> }
[/QUOTE]


You dont need that line. If you have the onClicks for the radios set as I have described, then the hidden inputs value is already set.

As for the CGI, I'm clueless, never have touched it. So, Ireally wouldn't know where to point you ?

edit:

you do need to declare the hidden, but you do not have to set it's value, the radio's do that for you.
Copy linkTweet thisAlerts:
@bigmikeauthorMar 03.2004 — Hi Phil -

The cgi file requires the variable "submit_to" in that line you said I don't need. I understand what you were trying to do, which was at the time the submit button is pressed I would be opening a window, etc.

All the data going to the cgi file is a name, an email address and a district code. The cgi file checks for all kinds of errors and validates the data - then it sends that data in an email addressed to the address in the "submit_to" variable. But the email's first line in the body will read "SUBSCRIBE (or UNSUBSCRIBE) bla bla bla bla, CRLF, then the rest of the data. Why he asks ;-) Because we have a daemon that shoould be spelled "demon" which is very picky. It looks for that first line to be worded just so - then it will do whatever it is supposed to do, including sending a return email.

So, all I need is to get the email address data into that INPUT line for "submit_to".

And I forgot to ask yoou, since as I understand it, document.whatever syntax is script, yes? Shouldn't there be a <script></script> setup here somehow? I'm kinda new at all this as you can tell so forgive me if I'm asking really dumb questions.

bigMike
Copy linkTweet thisAlerts:
@PhillMcMar 04.2004 — Ok, let me explain a little further.

You are doing this to set the hidden (submitTo) value:

<input type=hidden name=submitTO value=toaddress.value>

You dont have to do that. The radio's set that value when one is clicked, like this:

<input type=hidden name=submitTo> <-- This is where you declare it, DO NOT SET IT's Value here.

<input type=radio name=subscribe value=subscribe [B]onClick="document.submitTo.value='TheAddress ToGoTo'"[/b]>

That is where you set the Hidden 'SubmitTo's value.^ ^ ^ ^ ^ ^ ^ Do the same for the unsubscribe with the address for unsubscribe. Doing so the way you attempted will overwrite the values and will not work.

Then, on click of the button, send the value of SubmitTo (that was set by clicking one of the radio buttons) to the CGI file with whatever else is needed.

Let me explain "document.submitTo.value"

That is JavaScript. Document means THIS PAGE, submitTo is the name of the hidden input, and value is it's value.

The cgi file requires the variable "submit_to" in that line you said I don't need. I understand what you were trying to do, which was at the time the submit button is pressed I would be opening a window, etc. [/QUOTE]

Yes, you need the variable, but no, you do not need to set it's value when you declare it. As mentioned above, the variables value is set when one of the radio's is clicked.
×

Success!

Help @bigmike spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...