/    Sign up×
Community /Pin to ProfileBookmark

Multiple variables from one radio button

My problem is;

I want to store multiple variables from one radio button together with a predefined variable for use in area shapes in maps.
For example,
I have 3 radio buttons.
I want R1 to return two values, site1 and opt1, R2 to return site2 and opt2 and R3 to return site3 and opt3.
Along with a predefined variable (pre1) I want to use all the results in a href along with my map in the same document.
The goal is to go to diferent sites depends on witch radio button is selected after I click on my map. ([url]http://site1/opt1?q=pre1[/url]) with R1 selected.

Any Ideas anyone?
JanB

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterOct 16.2005 — Put both variables within the value of the radio seperated by a comma for instance.
<i>
</i>&lt;form action="site1/redirect.php" method="get"&gt;
&lt;p&gt;
&lt;input type="radio" name="whatever" value="site1,opt1"&gt;
&lt;input type="radio" name="whatever" value="site2,opt2"&gt;
&lt;input type="radio" name="whatever" value="site3,opt3"&gt;
&lt;br&gt;
&lt;input type="submit" value="go"&gt;
&lt;/p&gt;
&lt;/form&gt;

Then use PHP to get the value of the checked radio and split at the comma and redirect to proper place. If you want, you can add an onsubmit event handler to the form for users with JavaScript enabled to do the spliting and redirecting client-side.
Copy linkTweet thisAlerts:
@janbauthorOct 16.2005 — Thank you for the answer, but the problem is that the map resides on the same page as the radio buttons. Instead of a submit button, I want to use the map areas to "submit" the href code.

JanB
Copy linkTweet thisAlerts:
@UltimaterOct 16.2005 — This want you are looking for?
<i>
</i>&lt;form action="#" onsubmit="return getRadioMap(this)"&gt;

<i>
</i>&lt;script type="text/javascript"&gt;
function getRadioMap(f){
var a=f.whatever.value.split(",");
alert(a[0]);
alert(a[1]);
return false;
}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@janbauthorOct 16.2005 — Hmm, the code didn't work as I Expected, or maybe I did it all wrong?

I am a newbie at this area (javascripts), and please be a little patient.

Well, how will the whole code look like?

I am specially curious about how I shell write the html map codes with the variables..

<area shape=rect HREF="javascript:;" onClick etc etc..

JanB
×

Success!

Help @janb 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...