Avatar of daimo1
daimo1

asked on 

Auto select Radio group from function

Hi
Use a selection of buttons to autofil a form with different values depending on the button pressed.
Works no problem with text and checkbox fields but can't get it to work on a radio group.

Here's one of the functions which works fine apart from the MenuImage field which is a radio group.

function CheckDefault()
{
form1.MenuSize_Width.value = 241;      //Text Field
form1.MenuColor_Normal.value = '#efefef'     //Text Field
form1.MenuImage.checked = 'CMSMenu/images/img1.gif'       // Radio Group. This is the problem one!
form1.ShowAll.checked = true     //Checkbox
}

Any ideas?
JavaScriptScripting Languages

Avatar of undefined
Last Comment
Dennis Maeder
Avatar of Dennis Maeder
Dennis Maeder
Flag of United States of America image

Please give your html source for the radio buttons.
They behave as an array, so the name or id attributes are critical.
D
Avatar of daimo1
daimo1

ASKER

<input type="radio" name="MenuImage" value="'CMSMenu/images/img1.gif">
<input type="radio" name="MenuImage" value="'CMSMenu/images/img2.gif">
<input type="radio" name="MenuImage" value="'CMSMenu/images/img3.gif">
Avatar of daimo1
daimo1

ASKER

Anybody??
ASKER CERTIFIED SOLUTION
Avatar of daimo1
daimo1

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
That's the array form I mentioned.
All you want is to check the first element of an array?
OK. Use

<button onclick='rtoggle(0)'>change radio</button>

<script>
function rtoggle(i){
form1.MenuImage[i].checked = true;
}
</script>

or similar to semi-automate the process. It may be more interesting to make the button cycle through the array.
D
thats fair.
D
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo