/    Sign up×
Community /Pin to ProfileBookmark

These two scripts dont wanna go…

I am trying to combine two scripts on the same menu:

This one to combine two radio buttons as a menu

[CODE]<!– Begin
site=”http://javascript.internet.com”;
function combineMenus(frm, menu1, menu2) {
with (frm) {
for (var i = 0; i < document.menufrm.menu1.length; i++) {
if (document.menufrm.menu1[i].checked) {
str = document.menufrm.menu1[i].value;
break;
}
}
for (var i = 0; i < document.menufrm.menu2.length; i++) {
if (document.menufrm.menu2[i].checked) {
str += document.menufrm.menu2[i].value;
break;
}
}
url = site + “/” + str + “.html”;
window.location.href = url;
}
}
// End –>
[/CODE]

And this one to validate the radio buttons

[CODE]<!– Begin
function checkRadios() {
var el = document.forms[0].elements;
for(var i = 0 ; i < el.length ; ++i) {
if(el[i].type == “radio”) {
var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
var itemchecked = false;
for(var j = 0 ; j < radiogroup.length ; ++j) {
if(radiogroup[j].checked) {
itemchecked = true;
break;
}
}
if(!itemchecked) {
alert(“Please choose an answer for “+el[i].name+”.”);
if(el[i].focus)
el[i].focus();
return false;
}
}
}
return true;
}
// End –>[/CODE]

Well these two don’t work together, as script 2 does not stop script 1 so script 1 reports javascript errors.

Is there anyway I can get these two scripts to work, without having to use any php or asp in my form (cos I don’t have a clue what I am doing there).

Thanks

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@chazzyDec 27.2005 — it should work if you change script 1 to look through all elements not 0, so for (var i = 1; i &lt; document.menufrm.menu1.length; i++) { and change it in all of the other loops as well.
×

Success!

Help @foolishtiger 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,
)...