JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2058
Number of posts: 5158

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Radio Name Maker Posted by CrazzyWarrior on 15 Jan 2004 at 6:09 AM
Ok Im wanting a script or how to make the script so that it will have like 3 options and you select one then you select from a list or 3 other options and then it will show the name at the bottom
for example

first part
()Car
()Lar
()Nar

last part
()Ley
()Gor
()Her

so if

first part
(X)Car
()Lar
()Nar

last part
(X)Ley
()Gor
()Her

then under it, it would show

Carley

but if you change Ley to Her then it would be

Carher

so i know it has to do with variables and storage and writing but i dont know how to get the radio button things or how to set them up to do what I want. Also the text on the button wont nessarely mean that is the part to be output but make it so something else like if Car where selected it would output Frog or something else.

Thanks for any help you give me.

C:\Dos
C:\Dos Run
Run Dos Run

Report
Re: Radio Name Maker Posted by lillu on 15 Jan 2004 at 7:25 AM
A quick example:

<html>
<head>
</head>
<body>

<form name=form1>

<input type=radio name=r1 value="Car" checked="checked">Car
<input type=radio name=r2 value="Ley" checked="checked">Ley<br />

<input type=radio name=r1 value="Lar">Lar
<input type=radio name=r2 value="Gor">Gor<br />

<input type=radio name=r1 value="Nar">Nar
<input type=radio name=r2 value="Her">Her<br />

<br />

<input type=button value="Show selected name" onclick="getSelectedRadio()">
</form>
<script>
function getSelectedRadio()
{
var f = document.form1;
var n = ""; //name string
var o= null; //selected radio object

o=f.r1;
for(var i=0;i<o.length;i++)
if(o[i].checked)
n+=o[i].value;

o=f.r2;
for(var i=0;i<o.length;i++)
if(o[i].checked)
n+=o[i].value;

alert(n);
}
</script>

</body>
</html>

HTH,



: Ok Im wanting a script or how to make the script so that it will have like 3 options and you select one then you select from a list or 3 other options and then it will show the name at the bottom
: for example
:
: first part
: ()Car
: ()Lar
: ()Nar
:
: last part
: ()Ley
: ()Gor
: ()Her
:
: so if
:
: first part
: (X)Car
: ()Lar
: ()Nar
:
: last part
: (X)Ley
: ()Gor
: ()Her
:
: then under it, it would show
:
: Carley
:
: but if you change Ley to Her then it would be
:
: Carher
:
: so i know it has to do with variables and storage and writing but i dont know how to get the radio button things or how to set them up to do what I want. Also the text on the button wont nessarely mean that is the part to be output but make it so something else like if Car where selected it would output Frog or something else.
:
: Thanks for any help you give me.
:
: C:\Dos
: C:\Dos Run
: Run Dos Run
:
:


To err is human, but to really foul things up requires a computer. (Farmers Almanac)

Report
Re: Radio Name Maker Posted by Weirdofreak on 15 Jan 2004 at 1:05 PM
To get it to write the output to the page, the easiest way would probably be to have two <span>s and innerHTML them with whatever you want.
Report
Re: Radio Name Maker Posted by CrazzyWarrior on 16 Jan 2004 at 6:12 PM
Uh, How do i go about that? I dont Know Java Script much so how could i do that? (Also I want it to be desplayed below or above the actual area where you choose the name parts from. And i want it to be updated or changed as they change the names, so they dont have to click a button or anything.

Another thing i would like, if possiable is to be shown how to get it so you click to parts and click a button and then it will desplay the result at the end of the text box, so it would have carley then you select larley and it would put ", Larley" or something so thats there commas between the names.

Also so i could understand it a little better could you explane a little about the different parts so I might get to understand them when needed.

Thanks for your help.

: To get it to write the output to the page, the easiest way would probably be to have two <span>s and innerHTML them with whatever you want.
:

C:\Dos
C:\Dos Run
Run Dos Run


Report
Re: Radio Name Maker Posted by Weirdofreak on 17 Jan 2004 at 7:10 AM
<html>
<head>
</head>
<body>

<form name=form1>

<input type=radio name=r1 value="Car" checked="checked">Car
<input type=radio name=r2 value="Ley" checked="checked">Ley<br />

<input type=radio name=r1 value="Lar">Lar
<input type=radio name=r2 value="Gor">Gor<br />

<input type=radio name=r1 value="Nar">Nar
<input type=radio name=r2 value="Her">Her<br />

<br />

<input type=button value="Show selected name" onclick="getSelectedRadio(); return false;">
</form>

<span name="names"></span>
<script>
function getSelectedRadio()
{
var f = document.form1;
var n = ""; //name string
var o= null; //selected radio object

o=f.r1; // o now = the first radio group
for(var i=0;i<o.length;i++) // runs through the group
if(o[i].checked) // if it's selected...
n+=o[i].value; // ... add the contents to n

o=f.r2;
for(var i=0;i<o.length;i++)
if(o[i].checked)
n+=o[i].value; // do the same for the second group

n += ', '; // adds a comma and space to the end

document.names.innerHTML += n; // puts it into the span
}
</script>

</body>
</html>

That should work.
Report
Re: Radio Name Maker Posted by CrazzyWarrior on 17 Jan 2004 at 2:11 PM
This message was edited by CrazzyWarrior at 2004-1-17 14:11:55

Nope it doesent gets an error when you press the button(which i dident want in the first place) on line 42 char 1, something about 'document.names' is null or not an object. Code 0

ALSO ATENTION

+-----------------------------------------------------------+
!I DONT WANT IT TO BE AN ALLERT OR ANYTHING LIKE THAT I WANT!
!IT TO BE TEXT RIGHT UNDER THE AREA WHERE THE OPTIONS ARE...!
!AND HAVE IT BE REFRESED KINDA THING ONCLICK OR A NEW OPTION!
!SO IT WILL DESPLAY IT AND YOU COULD HIGHLIGHT IT OR SOME-..!
!THING LIKE THAT...................................THANK YOU!
+-----------------------------------------------------------+



: <html>
: <head>
: </head>
: <body>
:
: <form name=form1>
:
: <input type=radio name=r1 value="Car" checked="checked">Car
: <input type=radio name=r2 value="Ley" checked="checked">Ley<br />
:
: <input type=radio name=r1 value="Lar">Lar
: <input type=radio name=r2 value="Gor">Gor<br />
:
: <input type=radio name=r1 value="Nar">Nar
: <input type=radio name=r2 value="Her">Her<br />
:
: <br />
:
: <input type=button value="Show selected name" onclick="getSelectedRadio(); return false;">
: </form>
:
: <span name="names"></span>
: <script>
: function getSelectedRadio()
: {
: var f = document.form1;
: var n = ""; //name string
: var o= null; //selected radio object
:
: o=f.r1; // o now = the first radio group
: for(var i=0;i<o.length;i++) // runs through the group
: if(o[i].checked) // if it's selected...
: n+=o[i].value; // ... add the contents to n
:
: o=f.r2;
: for(var i=0;i<o.length;i++)
: if(o[i].checked)
: n+=o[i].value; // do the same for the second group
:
: n += ', '; // adds a comma and space to the end
:
: document.names.innerHTML += n; // puts it into the span
: }
: </script>
:
: </body>
: </html>
:
: That should work.
:

C:\Dos
C:\Dos Run
Run Dos Run




Report
Re: Radio Name Maker Posted by Weirdofreak on 18 Jan 2004 at 3:55 AM
Y'know, I'm trying to help here. You could have just asked nicely instead of shouting.

<html>
<head>
</head>
<body>

<form name=form1>

<input type=radio name=r1 value="Car" checked="checked">Car
<input type=radio name=r2 value="Ley" checked="checked">Ley<br />

<input type=radio name=r1 value="Lar" onClick="getSelectedRadio();">Lar
<input type=radio name=r2 value="Gor" onClick="getSelectedRadio();">Gor
<br />

<input type=radio name=r1 value="Nar" onClick="getSelectedRadio();">Nar
<input type=radio name=r2 value="Her" onClick="getSelectedRadio();">Her
<br />

</form>

<span name="names"></span>
<script>
function getSelectedRadio()
{
var f = document.form1;
var n = ""; //name string
var o= null; //selected radio object

o=f.r1; // o now = the first radio group
for(var i=0;i<o.length;i++) // runs through the group
if(o[i].checked) // if it's selected...
n+=o[i].value; // ... add the contents to n

o=f.r2;
for(var i=0;i<o.length;i++)
if(o[i].checked)
n+=o[i].value; // do the same for the second group

n += ', '; // adds a comma and space to the end

document.getElementsByTagName('span')[0].innerHTML += n; // puts it into the span
}
</script>

</body>
</html>

That ought to do it, but it'll go to the wrong place if you have other spans in the page before that one.
Report
Re: Radio Name Maker Posted by CrazzyWarrior on 18 Jan 2004 at 8:49 AM
Sorry I was just trying to get it noticed dident mean for it to be taken as yelling. And also Thanls for that, it works perfectly, Thanks for your Help.

: Y'know, I'm trying to help here. You could have just asked nicely instead of shouting.
:
: <html>
: <head>
: </head>
: <body>
:
: <form name=form1>
:
: <input type=radio name=r1 value="Car" checked="checked">Car
: <input type=radio name=r2 value="Ley" checked="checked">Ley<br />
:
: <input type=radio name=r1 value="Lar" onClick="getSelectedRadio();">Lar
: <input type=radio name=r2 value="Gor" onClick="getSelectedRadio();">Gor
: <br />
:
: <input type=radio name=r1 value="Nar" onClick="getSelectedRadio();">Nar
: <input type=radio name=r2 value="Her" onClick="getSelectedRadio();">Her
: <br />
:
: </form>
:
: <span name="names"></span>
: <script>
: function getSelectedRadio()
: {
: var f = document.form1;
: var n = ""; //name string
: var o= null; //selected radio object
:
: o=f.r1; // o now = the first radio group
: for(var i=0;i<o.length;i++) // runs through the group
: if(o[i].checked) // if it's selected...
: n+=o[i].value; // ... add the contents to n
:
: o=f.r2;
: for(var i=0;i<o.length;i++)
: if(o[i].checked)
: n+=o[i].value; // do the same for the second group
:
: n += ', '; // adds a comma and space to the end
:
: document.getElementsByTagName('span')[0].innerHTML += n; // puts it into the span
: }
: </script>
:
: </body>
: </html>
:
: That ought to do it, but it'll go to the wrong place if you have other spans in the page before that one.
:

C:\Dos
C:\Dos Run
Run Dos Run





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.