iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old November 2nd, 2007, 08:04 PM   #1
New Member
 

Join Date: Nov 2007
Location: Norway
Age: 24
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Pugger is on a distinguished road
[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:

Code:
$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; November 3rd, 2007 at 08:54 AM.. Reason: Please use BBC tags when pasting code ([php][/php])
Pugger is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 3rd, 2007, 08:56 AM   #2
Highly Reputable Member
SuperMember
 
Rakuli's Avatar
 

Join Date: Sep 2007
Location: Australia
Age: 25
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold
Re: Selected radio button value

Code:
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:
function selectValue(thisisthevalue)
{
//do stuff
}
then on your radio buttons, onclick="this.checked?selectValue(this.value):''"

Hope that helps,

Cheers
__________________
Luke Dingle . com
Rakuli is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 3rd, 2007, 09:10 AM   #3
New Member
 

Join Date: Nov 2007
Location: Norway
Age: 24
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Pugger is on a distinguished road
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.
Pugger is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 3rd, 2007, 09:13 AM   #4
Highly Reputable Member
SuperMember
 
Rakuli's Avatar
 

Join Date: Sep 2007
Location: Australia
Age: 25
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold
Re: Selected radio button value

Yes, it will display the assigned value.
__________________
Luke Dingle . com
Rakuli is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 3rd, 2007, 09:39 AM   #5
New Member
 

Join Date: Nov 2007
Location: Norway
Age: 24
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Pugger is on a distinguished road
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:



Code:
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:

Code:
<?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; November 3rd, 2007 at 09:44 AM..
Pugger is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 3rd, 2007, 09:44 AM   #6
Highly Reputable Member
SuperMember
 
Rakuli's Avatar
 

Join Date: Sep 2007
Location: Australia
Age: 25
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold
Re: Selected radio button value

with your onclick="",

surround the onclic with double quotes " not single quotes '
__________________
Luke Dingle . com
Rakuli is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 3rd, 2007, 09:48 AM   #7
New Member
 

Join Date: Nov 2007
Location: Norway
Age: 24
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Pugger is on a distinguished road
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?

Code:
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++;

Pugger is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 3rd, 2007, 10:13 AM   #8
New Member
 

Join Date: Nov 2007
Location: Norway
Age: 24
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Pugger is on a distinguished road
Re: Selected radio button value

I used
Code:
onclick='alert(this.name)' 
and that works fine .. anyway thx for pointing me in the right direction
Pugger is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 3rd, 2007, 10:16 AM   #9
Highly Reputable Member
SuperMember
 
Rakuli's Avatar
 

Join Date: Sep 2007
Location: Australia
Age: 25
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold
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.
__________________
Luke Dingle . com
Rakuli is offline  
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

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 8 November 8th, 2007 10:55 PM
[SOLVED] Radio Button Response! :( jahphill PHP 33 October 25th, 2007 07:15 PM
[SOLVED] large radio button form submit chriscant JavaScript 7 October 25th, 2007 06:03 AM
Any way to use an image for a radio button? masonbarge HTML, XHTML and CSS 23 January 6th, 2007 06:06 AM
automatic pop-up when click on a radio button joshcxa JavaScript 2 August 1st, 2006 03:06 AM


Search Engine Optimization by vBSEO 3.2.0 RC8