/    Sign up×
Community /Pin to ProfileBookmark

radio validation

I am trying to find the selected radio button and return the string. See comment in code.

[code=php]
function findSelected(question, myForm)
{
for(g=0; g<4; g++)
{
theQuest=getObject(“quest” + question);
alert(theQuest.value);
alert(theQuest[1].value);
if(theQuest[g].checked==true)
theOutput=theQuest[g].value;
}
return theOutput;
}

function getObject(id)
{
if (ns4dom) ref=”document.”+id;
else if (iedom) ref=id;
else if (w3cdom) ref=”document.getElementById(‘”+id+”‘)”;
var object=eval(ref); //quest7 is undefined????????
return object;
}
[/code]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@PittimannJun 10.2004 — Hi!

The solution is in the code I posted to your previous thread.

Cheers - Pit
Copy linkTweet thisAlerts:
@rex64authorJun 10.2004 — I do not see the answer in the previous thread. It has the same problem I think.
Copy linkTweet thisAlerts:
@PittimannJun 10.2004 — Hi!

Seems you didn't test the code I posted there ?

Example taken from the function gradeTest():

if(x!=7){

writeToWin(theQuest.value + "<br><br>");

}

if(x==7){

for (var i=0;i<4;i++){

if (theQuest[i].checked==true){

questVal=theQuest[i].value;

}

}

writeToWin(questVal + "<br><br>");

}

}

}



Cheers - Pit
Copy linkTweet thisAlerts:
@rex64authorJun 10.2004 — I think mine is the same. I dont see my problem.

[code=php]
function findSelected(question, myForm)
{
for(g=0; g<4; g++)
{
theQuest=getObj("quest" + question);
alert(theQuest.value);
alert(theQuest[1].value);
if(theQuest[g].checked==true) //thequest.1.value is null or not an object?????
theOutput=theQuest[g].value;
}
return theOutput;
}
[/code]
Copy linkTweet thisAlerts:
@PittimannJun 10.2004 — Hi!

Have you ever (maybe just for fun) tried my entire code?

If you had done it, you would have noticed that I only fixed things disturbing functionality (and that it works for the browsers I mentioned, including radio button validation).

The way you are referencing your objects needs a couple of thoughts. Actually I was wondering about the way you approached the whole script.

If I was you, I would start from scratch with at least one eye directed to Mozilla not only having a variable w3cdom defined; I fixed the most essential things without changing your "concept" too much. That's one of the reasons I called my stuff "ugly" (another one is: my code is always ugly).

Good luck - Pit
Copy linkTweet thisAlerts:
@PittimannJun 10.2004 — Hi!

I should have mentioned a couple of things in my previous post as well.

As I already pointed out, your references ar not ok. I had fixed that in your function 'getObjFromForm' which you originally used to refer to your fields:

function getObjFromForm(name, form){

if (document.getElementById){

return document.myForm[name];

...

else if (document.all){

this.obj = document.all[name];

this.style = document.all[name].style;

}

In this (new) thread you call the function 'getObject()' instead; this one says (for IE):

else if (iedom) ref=id;

Do you see a difference?

Cheers - Pit
×

Success!

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