Jump to content

Disabling Radio Problem


shreyaskudav

Recommended Posts

This is my radio disabling function.

<script>function disableElement(){var dis = '<?php echo $dis_value; ?>';document.getElementById(dis).disabled=true;}</script>

And I will call it when the page is loaded!

<body onLoad="disableElement()">

And the radio button is displayed through loop..!

echo '<form method="post" action="trainingserver.php">';$i = 1;while($i <= $num_rows){echo '<input type="radio" id="dis"'.$i.'"" name="select" value="'.$i.'" />';echo  $poke[$i]."<br>";echo 'Level:'.$level[$i]."<br>";echo 'Health:'.$health[$i]."<br>";$i++;}echo '<input type="submit" name="submit" value="Select Pokemon!" />';echo '</form>';

So the radio ids would be like: dis1,dis2 ... dis6

 

But its not disabling it...! I think its because of the while loop, I used..! what should I do..?

Link to comment
Share on other sites

Yaa! I worked on it..! and fortunately got solved!

Problem was in id in form:

id="dis'.$i.'"

I have a question now..can I maintain this disabled radio even after reload??

Coz now it gets disabled but after reload again gets enabled..!

I googled it and got something like I have to use localstorage ??!!

Link to comment
Share on other sites

In order for Javascript to remember anything you need to use either cookies (compatible with the widest range of browsers) or local storage.

  • Like 1
Link to comment
Share on other sites

You are creating what seems to be a Php-centric page. When and why do you decide to disable the radio button? If you have already decided to disable it when Php is rendering the page then I don't know why you need to pass the task to Javascript.

Link to comment
Share on other sites

There would be 6 radio...each representing a pokemon...which is to be used! so basically all 6 radios would be enabled!

Once a pokemon is killed, i.e. health <=0 ..... the corresponding radio will be disabled..! Therefore user cannot use it again, as its killed!

 

So I need to store it in the cookie...!And also there are 5 more pokemons... I will also require to store all those in the cookie.

Link to comment
Share on other sites

Ever since this discussion started you have not made a clear delineation between the role of the client and the role of the server. When a "pokemon" is "killed" doesn't the server need to record this?

Link to comment
Share on other sites

Yes! I have already handled the server... the health reduction and other calculations are set..!

<script>function disableElement(){var dis = '<?php echo $dis_value; ?>';document.getElementById(dis).disabled=true;}</script>

You see the variable $dis_value , passed to the javascript variable when the health of the pokemon is <= 0.

This $dis_value will consisting the value, which is also the ID="" of the radio, which is to be disabled!

 

I just want to know the proper format or syntax, that I should use to save the state of disabled radio in cookie so that it maintains it futher...!

Edited by shreyaskudav
Link to comment
Share on other sites

Yeah but why not simply have Php do it?

if ($disabled[$i]){echo '<input type="radio" id="dis"'.$i.'"" name="select" value="'.$i.'" disabled />';}else{echo '<input type="radio" id="dis"'.$i.'"" name="select" value="'.$i.'" />';}
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...