/    Sign up×
Community /Pin to ProfileBookmark

Radio button verification linked to checkboxes on dynamic PHP form

Hi all,

I am not very savy at Javascript (I am a PHP/MySQL programmer) and my coworker is better than I am, but I will attempt to explain our issue.

We have tried to use some code like gen_validator.js and it works for most of the forms, but when we try to get it to verify that the user has selected a radio button after making a checkbox selection ( in this case, they checked a video they have of ours, and we want them to rate it [with a series of 5 radio buttons]).

We cant seem to figure out how to ‘link’ the radio button verification to the checkboxes (only if they select a video first).

Does this make sense? IE we dont want to ask them to rate a video if they did not check the video box in the first place.

And to complicate matters, the list of videos is dynamice (from our database) so we make it an array (PHP and MySQL).

We have searched the web and found half solutions, to either side, but nothing we can (in our feeble minds) seem to tie together.

Any guidance would be greatly appreciated.

regards,

Don

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@WebnerdFeb 12.2008 — Any code would be helpful
Copy linkTweet thisAlerts:
@dmacmanauthorFeb 13.2008 — Hi Webnerd,

Thanks for helping.

Here is the code

//This is the code I can't seem to write with a dynamic value, IE I end up hard-coding it for each new set of radio buttons.
[CODE]// Java Document
case "checkerratings_FS":

{

var total=""
for(var i=0; i < document.feedback.rating_chk_FS.length; i++){
if(document.feedback.rating_chk_FS[i].checked)
total +=document.feedback.rating_chk_FS[i].value + "n"
}
if(total==""){
alert("Please rate video: Freedoms Sound");
//else
//alert (total)


return false;
} [/CODE]


and the instance in Javascript

[CODE] var frmvalidator = new Validator("feedback");
frmvalidator.addValidation("RatingsFS0","checkerratings_FS"," Please rate video: Freedoms Sound");[/CODE]


I identify the item in my forms with

[code=html]<input type="radio" name="RatingsFS0" id="rating_chk" value="1">[/code]

My challenge is I list the videos from a database, and I build my forms as an array, and I need to keep hard-coding in a new...

case "checkerratings_FS":[/QUOTE]

because I can't figure out how to dynamically change that name in Javascript.

In PHP I would just name that radio button "Ratings[0]" but how do I dynamically do that in Javascript.

Does this all make sense?

Am I even close to doing this the correct way?

I appreciate your help and feedback,

Don
×

Success!

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