Jump to content

need some type of assistance


Monkuar

Recommended Posts

Long story short, this is my code:

 

<input type=radio id='s1' value='1' onclick='showPreview(1)' name='star' $value><label for='s1'><img src='style_images/1/icons/1.png'></label>
			<br>
			<input type=radio id='s2' value='2' onclick='showPreview(2)' name='star' $value><label for='s2'><img src='style_images/1/icons/2.png'></label>
			<br>
			<input type=radio id='s3' value='3' onclick='showPreview(3)' name='star' $value><label for='s3'><img src='style_images/1/icons/3.png'></label>
			<br>
			<input type=radio id='s4' value='4' onclick='showPreview(4)' name='star' $value><label for='s4'><img src='style_images/1/icons/4.png'></label>
			<br>
			<input type=radio id='s5' value='5' onclick='showPreview(5)' name='star' $value><label for='s5'><img src='style_images/1/icons/5.png'></label>

 

 

Somehow I need to try to get my $value to equal 'checked' based upon my "star" variable:

 

 

So I choose #5, which is

<input type=radio id='s5' value='5' onclick='showPreview(5)' name='star' $value>

 

and now my "star" value is set to 5, (I updated it through my db) how do I make $value become 'checked'  when I have 4 others input type=radio's that it will check also? I only need the #5 one checked as that is one that I chose.  The problem is, I have 70 of these input type Radio's and if I use $value on every one it will not show them all checked instead of just the 1 i chose

 

 

Link to comment
Share on other sites

Here is a update: I got it to work but using a long and exctrucinating method, I would love if anyone could help simmer down my code a bit, using foreach or something?  because I will have to do this for all 70, can't it be done using a array 1-70 or something alot easier?

 

 

 

 

HTML:

<input type=radio id='s1' value='1' onclick='showPreview(1)' name='star' $checked1><label for='s1'><img src='style_images/1/icons/1.png'></label>
			<br>
			<input type=radio id='s2' value='2' onclick='showPreview(2)' name='star' $checked2><label for='s2'><img src='style_images/1/icons/2.png'></label>
			<br>
			<input type=radio id='s3' value='3' onclick='showPreview(3)' name='star' $checked3><label for='s3'><img src='style_images/1/icons/3.png'></label>
			<br>
			<input type=radio id='s4' value='4' onclick='showPreview(4)' name='star' $checked4><label for='s4'><img src='style_images/1/icons/4.png'></label>
			<br>
			<input type=radio id='s5' value='5' onclick='showPreview(5)' name='star' $checked5><label for='s5'><img src='style_images/1/icons/5.png'></label>
			<br>
			<input type=radio id='s6' value='6' onclick='showPreview(6)' name='star' $checked6><label for='s6'><img src='style_images/1/icons/6.png'></label>
			<br>
			<input type=radio id='s7' value='7' onclick='showPreview(7)' name='star' $checked7><label for='s7'><img src='style_images/1/icons/7.png'></label>
			<br>
			<input type=radio id='s8' value='8' onclick='showPreview(' name='star' $checked8><label for='s8'><img src='style_images/1/icons/8.png'></label>
			<br>
			<input type=radio id='s9' value='9' onclick='showPreview(9)' name='star' $checked9><label for='s9'><img src='style_images/1/icons/9.png'></label>
			<br>
			<input type=radio id='s10' value='10' onclick='showPreview(10)' name='star' $checked10><label for='s10'><img src='style_images/1/icons/10.png'></label>

 

 

 

 

PHP:

 

switch ($ibforums->member['star']){
case '1';
$checked1 = 'checked';
break;
case '2';
$checked2 = 'checked';
break;
case '3';
$checked3 = 'checked';
break;
case '4';
$checked4 = 'checked';
break;
case '5';
$checked5 = 'checked';
break;
case '6';
$checked6 = 'checked';
break;
case '7';
$checked7 = 'checked';
break;
case '8';
$checked8 = 'checked';
break;
case '9';
$checked9 = 'checked';
break;
case '10';
$checked10 = 'checked';
break;
}

Link to comment
Share on other sites

this is how it can be done.

<?php 

$stars = range(1,70);
foreach ($stars as $star)
{
if($ibforums->member['star'] == $star)
{
	$checked = ' checked';
}
else 
{
	$checked = '';
}
?>
<input type=radio id="s<?=$star?>" value="<?=$star?>" onclick="showPreview(<?=$star?>);" name="star"<?=$checked?> />
<label for="s<?=$star?>">
	<img src="style_images/1/icons/<?=$star?>.png">
</label>
<?php 
}
?>

Hope this helps

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.