...

View Full Version : How to refer to a radio button?



JAVAEOC
10-26-2003, 05:04 PM
I can refer to a check box using its name, but i can not do this with a radio button cause they all have the same name :(

So how can i refer to a radio button?? :confused:

liorean
10-26-2003, 05:14 PM
Either use if's reference number in the form, or use an id.


document.forms[formName].elements[radioButtonCollection][numberOfRadioButton]
// or
document.getElementById(idOfRadioButton)

Willy Duitt
10-26-2003, 05:21 PM
Here's another way:

<script type="text/javascript">
<!--

function whichradio(){ // check for a selected radio button
formfield=document.form1.radio1 // formname and input names to be checked
for(i=0;i<formfield.length;i++)
if (formfield[i].checked==true){ // identify selected radio button
itext.innerText=("You have chosen radio button "+formfield[i].value) // show result
itext.style.color="black"
itext.style.fontWeight="bold"
}
}

// -->
</script>


<form name=form1>
<P>
<input type=radio name=radio1 value=one onclick="whichradio()">one
<input type=radio name=radio1 value=two onclick="whichradio()">two
<input type=radio name=radio1 value=three onclick="whichradio()">three

<P id=itext>Which one will you choose?

formfield[i].value is what you would use to pass
which radio button was checked to your script.


....Willy

JAVAEOC
10-26-2003, 05:23 PM
<html>
<body>
<script>
function test22(){alert(document.getElementById('idOfRadioButton'))}
</script>
<input type=radio name=test id="one">
<input type=radio name=test id="two">
<input type=button value="get id" onClick="test22()">
</body>

:confused:

liorean
10-26-2003, 05:26 PM
Because you have no radio button with an id of "idOfRadioButton". That string should be replaced with a string to an id that you actually use.

JAVAEOC
10-26-2003, 05:30 PM
Willy your way works fine for me:thumbsup:
but why:confused:


<script type="text/javascript">

function whichradio(){
formfield=document.form1.radio1
for(i=0;i<formfield.length;i++)
if (formfield[i].checked==true){
alert("You have chosen radio button "+formfield[i].value)
}
}

</script>
<form name=form1>
<input type=radio name=radio1 value=help>
<input type=radio name=radio1 value=ahh>
<input type=button onClick=whichradio()>
</form>


thats what i ahve and it works:thumbsup:
but what is formfield.length
and what is formfield anyways
and why do u need the i
and what is formfield.lenght[i]

JAVAEOC
10-26-2003, 05:33 PM
so liorean if i put in my id form a radio button it tells me in the alert window [object]

Now why is that and how would i have to mdife my script to have it working

thank for ur help

thanks for urs (willy) too

:D

JAVAEOC
10-26-2003, 05:44 PM
<html>
<body>
<script>
function test22(){alert(document.getElementById("one").value)}
</script>
<form name=form1>
<input type=radio name=test id="one" value=ahh>
<input type=radio name=test id="two" value=grrff>
<input type=button value="get id" onClick="test22()">
<form>
</body>


I have tryed this again but it only gives me ahh no matter which one i select

why:confused:

JAVAEOC
10-26-2003, 05:58 PM
It works thanks to all fo you thank u very much :thumbsup:

Here is what i did

<html>
<body>
<script>
function test22(){
if(document.form1.test[0].checked==true){
alert(document.form1.test[0].value)};
if(document.form1.test[1].checked==true){
alert(document.form1.test[1].value)};
if(document.form1.test[0].checked!=true && document.form1.test[1].checked!=true){alert("please select one")};};
</script>
<form name=form1>
<input type=radio name=test id="one" value=ahh>
<input type=radio name=test id="two" value=grrff>
<input type=button value="get id" onClick="test22()">
<form>
</body>

:D :D

JAVAEOC
10-26-2003, 06:09 PM
IGNOR THIS I AM JUST SO HAPPY I AHVE TO POST A SMILY

:D :thumbsup: :D :thumbsup: :D :thumbsup: :D :thumbsup:

JAVAEOC
10-26-2003, 06:09 PM
THANKS EVERYONE

MY SCRIPT FINALLY WORKS

JAVAEOC
10-26-2003, 06:10 PM
HERES WHAT U HELP ME TO DO

SO ITS HALF UR SCRIPT :D
<HTML>
<BODY>
<script>

function Reset2(){
div.innerHTML="";
};

function Music(){
if(document.FORM1.RADIO[0].checked==true){div.innerHTML+="<EMBED SRC=A.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[1].checked==true){div.innerHTML+="<EMBED SRC=B.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[2].checked==true){div.innerHTML+="<EMBED SRC=C.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[3].checked==true){div.innerHTML+="<EMBED SRC=D.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[4].checked==true){div.innerHTML+="<EMBED SRC=E.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[5].checked==true){div.innerHTML+="<EMBED SRC=F.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[6].checked==true){div.innerHTML+="<EMBED SRC=G.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[7].checked==true){div.innerHTML+="<EMBED SRC=H.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[8].checked==true){div.innerHTML+="<EMBED SRC=I.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[9].checked==true){div.innerHTML+="<EMBED SRC=J.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[10].checked==true){div.innerHTML+="<EMBED SRC=K.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[11].checked==true){div.innerHTML+="<EMBED SRC=L.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[12].checked==true){div.innerHTML+="<EMBED SRC=M.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[13].checked==true){div.innerHTML+="<EMBED SRC=N.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[14].checked==true){div.innerHTML+="<EMBED SRC=O.wma hidden=true loop=true>"};
if(document.FORM1.RADIO[15].checked==true){div.innerHTML+="<EMBED SRC=P.wma hidden=true loop=true>"};
};

function Reset(){
i=0;
};

function All(){
Reset2();
Music();
Reset();
};

</script>
<FORM NAME=FORM1>
<INPUT TYPE=RADIO NAME=RADIO>Chic 'n' Stu<BR>
<INPUT TYPE=RADIO NAME=RADIO>Innervision<BR>
<INPUT TYPE=RADIO NAME=RADIO>Bubbles<BR>
<INPUT TYPE=RADIO NAME=RADIO>Boom!<BR>
<INPUT TYPE=RADIO NAME=RADIO>Nüguns<BR>
<INPUT TYPE=RADIO NAME=RADIO>A.D.D.<BR>
<INPUT TYPE=RADIO NAME=RADIO>Mr. Jack<BR>
<INPUT TYPE=RADIO NAME=RADIO>I-E-A-I-A-I-O<BR>
<INPUT TYPE=RADIO NAME=RADIO>36<BR>
<INPUT TYPE=RADIO NAME=RADIO>Pictures<BR>
<INPUT TYPE=RADIO NAME=RADIO>Highway Song<BR>
<INPUT TYPE=RADIO NAME=RADIO>F**k the System<BR>
<INPUT TYPE=RADIO NAME=RADIO>Ego Brain<BR>
<INPUT TYPE=RADIO NAME=RADIO>Thetawaves<BR>
<INPUT TYPE=RADIO NAME=RADIO>Roulette<BR>
<INPUT TYPE=RADIO NAME=RADIO>Streamline<BR>
</FORM>
<INPUT TYPE='button' VALUE='get music' onClick=All()>
<DIV ID="div"></DIV>
</BODY>
</HTML>

JAVAEOC
10-26-2003, 06:11 PM
WORKS PERFECLY THANKS AGAIN IT MADE ME HAPPY NOW I AM HYPER AND MY MUM IS GOING INSANE :D :D :D

Willy Duitt
10-26-2003, 07:04 PM
Well I'm glad you got it working. :)

But, If you used this short snippet of code:
formfield=document.form1.radio
for(i=0;i<formfield.length;i++)
if (formfield[i].checked==true)

It would loop thru all of your radio buttons and choose which
one was selected. You would not need to continually make:

if(document.FORM1.RADIO[0].checked==true){div.innerHTML+="<EMBED SRC=A.wma hidden=true loop=true>"};

statements..... :D

You also should not name your radio buttons RADIO
This may confuse the browser. NAME=RADIO1 would be better.

<FORM NAME=FORM1>
<INPUT TYPE=RADIO NAME=RADIO>Chic 'n' Stu<BR>

....Willy

Willy Duitt
10-26-2003, 07:22 PM
but what is formfield.length
and what is formfield anyways
and why do u need the i
and what is formfield.lenght[i]

formfield is the name of your form and radio button array
formfield=document.form1.radio

formfield.lenght is the number of radio buttons.
In your case formfield.length=16

i is your counter. You intially set the counter at 0
for(i=0;i<formfield.length;i++)

And, if i is less than < the formfield.length (16)
it loops thru the radio button array and increments
by one each time i++ until it reaches the formfield.length.

i is the number of the radio button which was checked.
if (formfield[i].checked==true)

That's the best I can explain it. :p
Do a google search on Javascript Loops
if you need a more in depth explanation.

....Willy

Willy Duitt
10-26-2003, 08:27 PM
I probably confused you. :eek:

Here is an example of your script using the loop.
Notice how the Music() function is considerably shorter.
I looped thru your button array and added VALUE=?.wma
to your radio buttons in order to pass their values to the script.

<HTML>
<BODY>
<script>

function Reset2(){
div.innerHTML="";
};

function Music(){
formfield=document.FORM1.RADIO1
for(i=0;i<formfield.length;i++)
if (formfield[i].checked==true){
div.innerHTML='<EMBED SRC="'+formfield[i].value+'" hidden=true loop=true>';
}
}

function Reset(){
i=0;
};

function All(){
Reset2();
Music();
Reset();
};

</script>
<FORM NAME=FORM1>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=A.wma>Chic 'n' Stu<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=B.wma>Innervision<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=C.wma>Bubbles<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=D.wma>Boom!<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=E.wma>Nüguns<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=F.wma>A.D.D.<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=G.wma>Mr. Jack<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=H.wma>I-E-A-I-A-I-O<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=I.wma>36<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=J.wma>Pictures<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=K.wma>Highway Song<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=L.wma>F**k the System<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=M.wma>Ego Brain<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=N.wma>Thetawaves<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=O.wma>Roulette<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=P.wma>Streamline<BR>
</FORM>
<INPUT TYPE='button' VALUE='get music' onClick=All()>
<DIV ID="div"></DIV>
</BODY>
</HTML>

....Willy

JAVAEOC
10-27-2003, 06:13 PM
Thanks for ur help willy

but it kinda sucks :mad:

i typed all those lines and now u tell me i can use a loop

mhh thanks :thumbsup:

JAVAEOC
10-27-2003, 06:15 PM
I am back but this time i am siting at an stupid old school computer.

:( :(

It tells me div is not defind

whats wrong :confused:

it worked on a new computer

Willy Duitt
10-27-2003, 06:24 PM
JAVAEOC;

You did good for your first script! :thumbsup:

The next one will get easier, the one after that, easier yet.....
Especially if you continue to learn various coding techniques.

I do advise reading up on loops.
You'll find that you will use it often.

Again, You did good;
.....Willy

Willy Duitt
10-27-2003, 06:28 PM
Originally posted by JAVAEOC
I am back but this time i am siting at an stupid old school computer.

:( :(

It tells me div is not defind

whats wrong :confused:

it worked on a new computer

Gheesh;

I really don't know which browsers do not support innerHTML.
Hopefully someone will come by who can answer that.
Do you know what browser version it is running?

.....Willy

JAVAEOC
10-27-2003, 06:35 PM
You showed me this nice LITTLE loop, instead of my
big old copy and paste method. really like that but i thik it wont work!!!!!! :confused:

You never opend your for loop fuction

u said for(i=0; i<formfiled.lenght; i++)

the u need { to open the funtion and u allso need }} to colse the if and the loop dont u????

:confused:

JAVAEOC
10-27-2003, 06:36 PM
NVM i just noticed u closed all of them but u never opend ur for loop

do u know what i mean?

JAVAEOC
10-27-2003, 06:38 PM
thought u arent online but u are oh well the shoold computers runs netscape 4.79

JAVAEOC
10-27-2003, 06:51 PM
i just found out that IE 3 does not support innerHTML

netscape 4. what ever doesnt support it either

Willy Duitt
10-27-2003, 06:57 PM
Originally posted by JAVAEOC
You showed me this nice LITTLE loop, instead of my
big old copy and paste method. really like that but i thik it wont work!!!!!! :confused:

You never opend your for loop fuction

u said for(i=0; i<formfiled.lenght; i++)

the u need { to open the funtion and u allso need }} to colse the if and the loop dont u????

:confused:

It's not a function.
It's a conditional statement.
Here (http://www.pageresource.com/jscript/jifelse.htm) are some easy to understand tutes.

....Willy

BTW: The code works as posted. Try it......
In fact you do not need all those resets you placed in the code.
I understand why you did. It was because you incorrectly added
the + operator to your statement.

This adds to whatever is already in the division your writing to:
div.innerHTML+="<EMBED SRC=N.wma hidden=true loop=true>"


This replaces what is in the division with your new values:
div.innerHTML="<EMBED SRC=N.wma hidden=true loop=true>"

Read that page I posted. :)

JAVAEOC
10-27-2003, 10:25 PM
havent tried ur loop yet


but it still doesnt make sense :confused:

your tell the pc the condition but u do not tell him what to do while this condition is true?????
or did u????
:confused:


even the site u poseted sais for(jade jade){}

JAVAEOC
10-27-2003, 10:29 PM
tryed ur srcipt it doesnt work

formfield.lenght is undifined :confused: :confused: :(

liorean
10-27-2003, 10:34 PM
Hmm, back to basic... errm.

for(initial expression; condition; loop expression) statement;

A statement can, in any instance, be replaced with a block, which is a set of multiple statements wrapped in curly braces, thus:

{statement1;...;statementn}

Which means you can put them together like this:

for(;;)statement;

or

for(;;){statement1;...;statementn}


Thus, the statement or block that follows the loop call is the set of command or set of commands looped over.

JAVAEOC
10-27-2003, 10:37 PM
basically i can do the {} thing but i dont always have to right?

JAVAEOC
10-27-2003, 10:40 PM
You said
Hmm, back to basic... errm.

sounds nice but i wich it would be ectually BACK.
In my case it is in basics i started 2 weaks ago with my java :o

liorean
10-27-2003, 10:41 PM
Basically, yes. You only need the curly braces if you want to execute more than one command in the loop. Same goes for if..else if..else, while, do..while, for..in. I believe you can not drop the curly braces from the switch statement, however, but I'm not sure of that.

JAVAEOC
10-27-2003, 10:45 PM
Any idiea whats wrong with ur loop willy

or is it me who messed up :confused:

Willy Duitt
10-28-2003, 02:15 AM
I can take a quess what is wrong.

Instead of taking the entire code from my post
you only took the Music() function and placed it
on your page without changing:

<INPUT TYPE=RADIO NAME=RADIO1 VALUE=A.wma>

If that is not it. I don't know what you did wrong.
You will need to either start posting your codes,
attach a .txt file or provide an online URL.
Otherwise we can only quess.

I CC&P'ed these working codes from my previous post.
Please note that I removed the unneeded Reset()'s

<HEAD>
<script type="text/javascript">
function Music(){
formfield=document.FORM1.RADIO1
for(i=0;i<formfield.length;i++)
if (formfield[i].checked==true){
div.innerHTML='<EMBED SRC="'+formfield[i].value+'" hidden=true loop=true>';
alert(formfield[i].value)
}
}
</script>
</HEAD>

<BODY>
<FORM NAME=FORM1>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=A.wma>Chic 'n' Stu<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=B.wma>Innervision<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=C.wma>Bubbles<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=D.wma>Boom!<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=E.wma>Nüguns<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=F.wma>A.D.D.<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=G.wma>Mr. Jack<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=H.wma>I-E-A-I-A-I-O<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=I.wma>36<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=J.wma>Pictures<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=K.wma>Highway Song<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=L.wma>F**k the System<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=M.wma>Ego Brain<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=N.wma>Thetawaves<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=O.wma>Roulette<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=P.wma>Streamline<BR>
</FORM>
<INPUT TYPE='button' VALUE='get music' onClick=Music()>
<DIV ID="div"></DIV>

.....Willy

Willy Duitt
10-28-2003, 02:42 AM
Alerts are your friend :thumbsup:

Learn to use them to debug your scripts.
If used properly they can indicate if a value is
being passed, or where the script stops working.

<HEAD>
<script type="text/javascript">
function Music(){
formfield=document.FORM1.RADIO1
for(i=0;i<formfield.length;i++)
if (formfield[i].checked==true){
which = '<EMBED SRC="'+formfield[i].value+'" hidden=true loop=true>';
div.innerHTML = (which);
alert('This looped ' +i+ ' times!')
alert('Div.innerHTML = \n'+which)
}
}
</script>
</HEAD>

<BODY>
<FORM NAME=FORM1>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=A.wma>Chic 'n' Stu<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=B.wma>Innervision<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=C.wma>Bubbles<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=D.wma>Boom!<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=E.wma>Nüguns<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=F.wma>A.D.D.<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=G.wma>Mr. Jack<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=H.wma>I-E-A-I-A-I-O<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=I.wma>36<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=J.wma>Pictures<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=K.wma>Highway Song<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=L.wma>F**k the System<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=M.wma>Ego Brain<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=N.wma>Thetawaves<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=O.wma>Roulette<BR>
<INPUT TYPE=RADIO NAME=RADIO1 VALUE=P.wma>Streamline<BR>
</FORM>
<INPUT TYPE='button' VALUE='get music' onClick=Music()>
<DIV ID="div"></DIV>


....Willy

Willy Duitt
10-28-2003, 07:47 AM
Originally posted by JAVAEOC
havent tried ur loop yet


but it still doesnt make sense :confused:

your tell the pc the condition but u do not tell him what to do while this condition is true?????
or did u????
:confused:


even the site u poseted sais for(jade jade){}

Whenever the Music() function is fired:
for(i=0;i<formfield.length;i++)
Starts to count until it finds
which button was checked.

Once found, I tell him what to do here.
Note the curly braces you are worried about. :p
if formfield[i].checked==true{
div.innerHTML='<EMBED SRC="'+formfield[i].value+'" hidden=true loop=true>';
alert(formfield[i].value)
}

......Willy

JAVAEOC
10-28-2003, 10:09 PM
ok before i understand this loop thing i need to know why the script doesnt work on one computer but it does on a different one.

both pcs are windows xp

what wrong :confused: :confused: :confused: :confused:

JAVAEOC
10-28-2003, 10:40 PM
I KNOW WAT I DID WRONG I FORGOT TO PUT THE VALUE

I DID PUT THE VALUE BUT I ONLY HAD VALU=A

I AM SURE IT WORKS WITH VALUE=A.wma

BUT STILL THE SCRIPT WORKS ON MY COMPUTER BUT NOT ON MY DADS(WHICH IS SUPPOSED TO BE BETTER)

JAVAEOC
10-28-2003, 10:55 PM
<HTML>
<HEAD>
<script type="text/javascript">

function Music(){
for(i=0;i<document.FORM1.RADIO.length;i++){
if (document.FORM1.RADIO[i].checked==true){
div.innerHTML='<EMBED SRC="'+document.FORM1.RADIO[i].value+'" hidden=true loop=true>';};};};

</script>
</HEAD>

<BODY>
<FORM NAME=FORM1>
<INPUT TYPE=RADIO NAME=RADIO VALUE=A.wma>Chic 'n' Stu<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=B.wma>Innervision<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=C.wma>Bubbles<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=D.wma>Boom!<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=E.wma>Nüguns<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=F.wma>A.D.D.<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=G.wma>Mr. Jack<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=H.wma>I-E-A-I-A-I-O<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=I.wma>36<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=J.wma>Pictures<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=K.wma>Highway Song<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=L.wma>F**k the System<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=M.wma>Ego Brain<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=N.wma>Thetawaves<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=O.wma>Roulette<BR>
<INPUT TYPE=RADIO NAME=RADIO VALUE=P.wma>Streamline<BR>
</FORM>

<INPUT TYPE='button' VALUE='get music' onClick=Music()>
<DIV ID="div"></DIV>

</BODY>
</HTML>


it works :thumbsup:

modified it a litle bit so it is easy to read for me in notepad :rolleyes:


but i do not undersant this line

div.innerHTML='<EMBED SRC="'+document.FORM1.RADIO[i].value+'" hidden=true loop=true>'

what are the ' for and the ''' ??????


:confused:

JAVAEOC
10-28-2003, 10:56 PM
still why wont it work on my dads pc?????????:confused:

JAVAEOC
10-28-2003, 10:58 PM
please try this script at ur pc so i know other ppl can use my file

thanks.

i attached some of the music files

:thumbsup:

nope i did not attache some music files they are to big :(

JAVAEOC
10-28-2003, 11:02 PM
since i did not understand nor like the .lenght tag i cut it out and just said 15 :)

for(i=0;i<=15;i++)

thanks for ualls help :thumbsup:

still i cant fix my dads pc :confused:

JAVAEOC
10-29-2003, 12:13 AM
check it out on the web

www.aiat.has.it

not all of them work cause the files were to big to upload :(

Willy Duitt
10-29-2003, 02:00 AM
Originally posted by JAVAEOC
modified it a litle bit so it is easy to read for me in notepad

Why did you have to modify it?
I've told you numerous times it works as is!
All you needed to do was use the code as posted.
Did you even try the codes prior to modifying the script?

What's this in red?

function Music(){
for(i=0;i<document.FORM1.RADIO.length;i++){
if (document.FORM1.RADIO[i].checked==true){
div.innerHTML='<EMBED SRC="'+document.FORM1.RADIO[i].value+'" hidden=true loop=true>';} ;} ;};

I was really hoping I could help you understand loops.
Maybe someone else can do a better job of explaining it,
or, perhaps one day you'll wake up and say Duh! now I get it!

L8'er;
.....Willy

JAVAEOC
10-29-2003, 02:45 AM
i told u why i modifed it

i tryed ur loop and it worked but i didnt like the lenght so i cut it out
and i did not like the design of the code so i rewrote it
and i added those {}; because it is how i feel better witht he script.

and i understand loops i also understand THIS loop otherwise i would be able to modify it. :mad:

JAVAEOC
10-29-2003, 02:49 AM
function Music(){
for(i=0;i<document.FORM1.RADIO.length;i++){
if (document.FORM1.RADIO[i].checked==true){
div.innerHTML='<EMBED SRC="'+document.FORM1.RADIO[i].value+'" hidden=true loop=true>';} ;} ;};


i did the first one because i like to tell the pc when the for condition ends. and i did all of ";" these because you are supposed to put one after everyline. And it just is a habit for me.

So thanks again for helping me but please dont give me a script and tell me i may not modifiy it. (then i would never understand it so what the point.)

However it works great thanks :thumbsup:

JAVAEOC
10-29-2003, 02:50 AM
the only thing that didnt work is on the other coputer so i was wondering if u could try it and see if it works for u

thanks :eek:

Willy Duitt
10-29-2003, 02:52 AM
Ok;

Now I understand that you understand.

Now that you do,
I suppose you can modify what you wish.

No need to be :mad:

I was only trying to help. :p

....Willy

JAVAEOC
10-29-2003, 02:53 AM
here is the link again

www.aiat.has.it

thanks :thumbsup:

JAVAEOC
10-29-2003, 09:55 PM
i am not angry at u i am only really agree at my dads computer because it will not play the music

it doesnt like me :mad: or something

GeoffreyB
09-09-2006, 04:37 AM
Here's another way:

<script type="text/javascript">
<!--

function whichradio(){ // check for a selected radio button
formfield=document.form1.radio1 // formname and input names to be checked
for(i=0;i<formfield.length;i++)
if (formfield[i].checked==true){ // identify selected radio button
itext.innerText=("You have chosen radio button "+formfield[i].value) // show result
itext.style.color="black"
itext.style.fontWeight="bold"
}
}

// -->
</script>


<form name=form1>
<P>
<input type=radio name=radio1 value=one onclick="whichradio()">one
<input type=radio name=radio1 value=two onclick="whichradio()">two
<input type=radio name=radio1 value=three onclick="whichradio()">three

<P id=itext>Which one will you choose?

formfield[i].value is what you would use to pass
which radio button was checked to your script.


....Willy

:confused:
I am using a similar script to test for 'Checked' however my radio buttons are created dynamically dependant on how many rows are retrieved from a database.
My problem arises when there is only one radio button 'formfield.length' does not return a value.

Does someone have a solution on how to test for one radio button, please ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum