[SOLVED] Selected radio button value

This is a discussion on "[SOLVED] Selected radio button value" within the JavaScript Forum section. This forum, and the thread "[SOLVED] Selected radio button value are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Nov 2nd, 2007, 22:04
Junior Member
Join Date: Nov 2007
Location: Norway
Age: 23
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Selected radio button value

Hi!

I have some radio buttons that are generated from a mysql database. I've given all the radiobuttons values. How can i retrieve radiobutton value when a radio button is selected? As I understand it i need to use javascript? Here is my code:

PHP: Select all

$result $Choo->query("SELECT * FROM `$valg` WHERE maskin_id=$maskin_id ORDER BY pris");


            if(
mysql_num_rows($result)) {
                echo (
"<table width='420' cellspacing='0' cellpadding='0' align='center'>");
                
$i 0;
                
$valgt 0;
                while(
$row mysql_fetch_row($result))    {
                    if (
$i == 0){
                        echo(
"<tr><td ><input name='$valg' type='radio' onClick='javascript:' checked value='$valgt'></td><td>$row[1]</td><td align='right' style='font-weight: bold;' colspan='2'>$row[4] ,-</td></tr>");
$i 1;


                    } else 
                    
                    
                    echo(
"<tr><td width=10><input name='$valg' type='radio' onClick='' value='$valgt'></td><td width=500>$row[1]</td><td width='60' align='right' style='color: green;' colspan='2'>+$row[4] ,-</td></tr>");
            
$valgt++;
} echo(
"</table>");
            } else echo(
"ingen data i db: $valg ");
        } 

Last edited by Rakuli; Nov 3rd, 2007 at 10:54. Reason: Please use BBC tags when pasting code ([php][/php])
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Nov 3rd, 2007, 10:56
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Selected radio button value

Code: Select all
onclick="this.checked?alert(this.value):'';"
This will alert the value to the screen when clicked..

For more detail you could set up a function.. eg
Code: Select all
function selectValue(thisisthevalue)
{
//do stuff
}
then on your radio buttons, onclick="this.checked?selectValue(this.value):''"

Hope that helps,

Cheers
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Nov 3rd, 2007, 11:10
Junior Member
Join Date: Nov 2007
Location: Norway
Age: 23
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Selected radio button value

Quote:
onclick="this.checked?alert(this.value):'';"
Will this display value of the button checked? Thx for helping so far.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Nov 3rd, 2007, 11:13
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Selected radio button value

Yes, it will display the assigned value.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Nov 3rd, 2007, 11:39
Junior Member
Join Date: Nov 2007
Location: Norway
Age: 23
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Selected radio button value

I tried but nothing happens when i select a button(page loads fine). For some reason i get syntax code on line 137(marked it/ctrl+f). I guess i messed something up. I just pasted in ur code like this:



PHP: Select all

while($row mysql_fetch_row($result)) {
     if (
$i == 0){
      echo(
"<tr><td><input name='$valg' type='radio' onClick='this.checked?alert(this.value):'';' checked value='$valgt'></td><td>$row[1]</td><td align='right' style='font-weight: bold;' colspan='2'>$row[4] ,-</td></tr>");
$i 1;

     } else 
     
     
     echo(
"<tr><td width=10><input name='$valg' type='radio' onClick='this.checked?alert(this.value):'';' value='$valgt'></td><td width=500>$row[1]</td><td width='60' align='right' style='color: green;' colspan='2'>+$row[4] ,-</td></tr>");
   
$valgt++;




Complete code:

PHP: Select all

<?php
require_once("funksjoner.php");
if(
$_GET['maskin_id'])$maskin_id $_GET['maskin_id'];
else 
header('Location: index.php');
$Choo = new mysql();
$Choo->connect();
$result $Choo->query("SELECT * FROM `maskin` WHERE maskin_id=$maskin_id");
$row mysql_fetch_row$result );
$text str_replace(chr(13).chr(10),"<br />\n",$row[6]);
 
 
function 
listDBvalg($valg) {
if(
$_GET['maskin_id'])$maskin_id $_GET['maskin_id'];
$Choo = new mysql();
$Choo->connect();
 
$result $Choo->query("SELECT * FROM `$valg` WHERE maskin_id=$maskin_id ORDER BY pris");
if(
mysql_num_rows($result)) {
echo (
"<table width='420' cellspacing='0' cellpadding='0' align='center'>");
$i 0;
$valgt 0;
 
while(
$row mysql_fetch_row($result)) {
if (
$i == 0){
echo(
"<tr><td><input name='$valg' type='radio' onClick='this.checked?alert(this.value):'';' checked value='$valgt'></td><td>$row[1]</td><td align='right' style='font-weight: bold;' colspan='2'>$row[4] ,-</td></tr>");
$i 1;
 
} else 
 
 
echo(
"<tr><td width=10><input name='$valg' type='radio' onClick='this.checked?alert(this.value):'';' value='$valgt'></td><td width=500>$row[1]</td><td width='60' align='right' style='color: green;' colspan='2'>+$row[4] ,-</td></tr>");
$valgt++;
} echo(
"</table>");
} else echo(
"ingen data i db: $valg ");
}
function 
komponent($valg){
if(
$_GET['maskin_id'])$maskin_id $_GET['maskin_id'];
$Choo = new mysql();
$Choo->connect();
$result $Choo->query("SELECT * FROM `$valg` WHERE maskin_id=$maskin_id ORDER BY pris");
if(
mysql_num_rows($result)){
$row mysql_fetch_row$result );
echo(
$row[1]);

}
$totalpris total($maskin_id);
$mva $totalpris 0.23;
$umva $totalpris $mva;
topp();
echo(
"
<script language='JavaScript' type='text/javascript'>
function toggleLayer( whichLayer ){ 
layersOff();
if (document.getElementById( whichLayer ).style.display == 'block')
document.getElementById( whichLayer ).style.display = 'none';
else document.getElementById( whichLayer ).style.display = 'block';
}
function layersOff(){
document.getElementById('cpu').style.display = 'none';
document.getElementById('os').style.display = 'none';
document.getElementById('harddisk').style.display = 'none';
document.getElementById('ram').style.display = 'none';
document.getElementById('skjermkort').style.displa y = 'none';
 
 
}
function konfig(){
document.getElementById('konfigellersalg').style.d isplay = 'none';
document.getElementById('knapper').style.display = 'block';
document.getElementById('vinduer').style.display = 'block';
layersOff();
}
</script>
"
);
topp_meny();
echo(
"<form name='form1'>
<table width='100%' height='100%' cellpadding='0' cellspacing='0' border='0' bgcolor='white' style='border: 1px solid black; font-size: small;'>
<tr>
<td align='center'>&nbsp;</td>
<td align='left'><b style='font-size: xx-large;'>$row[1]</b></td>
<td align='center'>&nbsp;</td>
</tr>
<tr>
<td width='30%'>&nbsp;</td>
<td width='50%'><p align='left'>$text</p></td>
<td widht='20%'><img src='$row[5]'></td>
</tr>
<tr>
<td width='30%' align='right'>Hovedkort:&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("hovedkort"); echo("</td>
</tr>
<tr>
<td width='30%' align='right'>Prosessor/CPU:&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("cpu"); echo("</td>
</tr>
 
<tr>
<td width='30%' align='right'>Optisk enhet:&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("optisk"); echo("</td>
</tr>
<tr>
<td width='30%' align='right'>Harddisk:&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("harddisk"); echo("</td>
</tr>
<tr>
<td width='30%' align='right'>Ram:&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("ram"); echo("</td>
</tr>
<tr>
<td width='30%' align='right'>Skjermkort:&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("skjermkort"); echo("</td>
</tr>
<tr>
<td width='30%' align='right'>Tvkort:&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("tvkort"); echo("</td>
</tr>
<tr>
<td width='30%' align='right'>Kabinett:&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("kabinett"); echo("</td>
</tr>
<tr>
<td width='30%' align='right'>Operativsystem:&nbsp;&nbsp;&nbsp;&nb sp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("os"); echo("</td>
</tr>
<tr>
<td width='30%' align='right'>Strømforsyning:&nbsp;&nbsp;&nbsp;&nb sp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("strømforsyning"); echo("</td>
</tr>
<tr> line 137
<td width='30%' align='right'>Høyttaler:&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("hoyttaler"); echo("</td>
</tr>
<tr>
<td width='30%' align='right'>Tastatur og mus:&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("tastaturogmus"); echo("</td>
</tr>
<tr>
<td width='30%' align='right'>Skjerm:&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("skjerm"); echo("</td>
</tr>
<tr>
<td width='30%' align='right'>Kortleser:&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width='50%' colspan='2' align='left'>"
);komponent("kortleser"); echo("</td>
</tr>
 
 
<tr>
<td colspan='3'>
<div id='komponentwrapper'>
<div id='konfigellersalg'>
<div id='konfig'><a href='#' onclick='javascript: konfig();'>[Konfigurer]</a></div><div id='salg'><a href='kjøp.php'>[Kjøp]</a></div>
</div>
<div id='knapper' style='display: none'>
<div id='knapp_os'><img src='http://www.cfm-guadalajara.net/dotclear/images/Logiciels_Microsoft/VistaLogo.jpg' onClick='javascript:toggleLayer(\"os\");'></div>
<div id='knapp_cpu'><img src='http://www.cyberzone-net.jp/images/cpu.gif' onClick='javascript:toggleLayer(\"cpu\");'></div>
<div id='knapp_harddisk'><img src='img/disk.jpg' onClick='javascript:toggleLayer(\"harddisk\");'></div>
<div id='knapp_ram'><img src='img/ram.jpg' onClick='javascript:toggleLayer(\"ram\");'></div>
<div id='knapp_skjermkort'><img src='img/skjermkort.jpg' onClick='javascript:toggleLayer(\"skjermkort\");'> </div>
</div>
 
 
 
<div id='vinduer' style='display: none'>
<div id='os'> "
); 
listDBvalg("os");
echo(
"</div><div id='cpu'>");
listDBvalg("cpu");
echo(
"</div><div id='harddisk'>");
listDBvalg("harddisk");
echo(
"</div><div id='ram'>");
listDBvalg("ram");
echo(
"</div><div id='skjermkort'>");
listDBvalg("skjermkort");
 
echo(
"</div>
</div>
</td>
</tr>
<tr valign='bottom' align='center' colspan='1'>
<td></td>
<td></td>
<td><b style='color: black; font-size: x-medium'>U/Mva : $umva ,-</b></td>
</tr>
<tr valign='bottom' align='center' colspan='1'>
<td></td>
<td></td>
<td><b style='color: black; font-size: x-medium'>Mva : $mva ,-</b></td>
</tr>
<tr valign='bottom' align='center' colspan='1'>
<td></td>
<td></td>
<td><b style='color: green; font-size: x-medium'>Totalpris : $totalpris ,-</b></td>
</tr>
</table>
</form>
"
);
bunn();
?>

Last edited by Pugger; Nov 3rd, 2007 at 11:44.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Nov 3rd, 2007, 11:44
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Selected radio button value

with your onclick="",

surround the onclic with double quotes " not single quotes '
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Nov 3rd, 2007, 11:48
Junior Member
Join Date: Nov 2007
Location: Norway
Age: 23
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Selected radio button value

Used double quote now the page wont load ..Thx for ur patience btw. Could it be because I use single quotes in rest of the code?

PHP: Select all

while($row mysql_fetch_row($result)) {
     if (
$i == 0){
      echo(
"<tr><td><input name='$valg' type='radio' onclick="this.checked?alert(this.value):'';" checked value='$valgt'></td><td>$row[1]</td><td align='right' style='font-weight: bold;' colspan='2'>$row[4] ,-</td></tr>");
$i 1;
 
     } else 
 
 
     echo(
"<tr><td width=10><input name='$valg' type='radio' onclick="this.checked?alert(this.value):'';" value='$valgt'></td><td width=500>$row[1]</td><td width='60' align='right' style='color: green;' colspan='2'>+$row[4] ,-</td></tr>");
   
$valgt++;

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Nov 3rd, 2007, 12:13
Junior Member
Join Date: Nov 2007
Location: Norway
Age: 23
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Selected radio button value

I used
PHP: Select all

onclick='alert(this.name)' 

and that works fine .. anyway thx for pointing me in the right direction
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Nov 3rd, 2007, 12:16
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Selected radio button value

I can't see why you would want access to the name over the value but glad you got it sorted anyway.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Automatic Checkbox/Radio Button Checking Stuart JavaScript Forum 8 Nov 9th, 2007 01:55
[SOLVED] Radio Button Response! :( jahphill PHP Forum 33 Oct 25th, 2007 22:15
[SOLVED] large radio button form submit chriscant JavaScript Forum 7 Oct 25th, 2007 09:03
Any way to use an image for a radio button? masonbarge Web Page Design 23 Jan 6th, 2007 09:06
automatic pop-up when click on a radio button joshcxa JavaScript Forum 2 Aug 1st, 2006 06:06


All times are GMT. The time now is 01:28.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42