+ 3
How to change bg color of list if its value is xyz onclick
I have 5 variables $xyz ,$a ,$b, $c, $d. and echo $a , $b, $c, $d for Selection . now one of them is = $xyz . so how to change bgcolor of that variable on selection if selected variable is = $xyz. also so how to implement it in HTML below is the link of my code https://code.sololearn.com/w9wf4viYsLhT/#php
31 odpowiedzi
+ 6
@Harish, look at this, it's not great, but I guess it would give you an idea, I haven't been coding web for long, so bear me if it's ugly : )
https://code.sololearn.com/WsC5550LZSUg/?ref=app
+ 7
Link your code with the question if you want people to help, it's hard to imagine what you're trying to accomplish just by reading the question : )
+ 6
We need to get a reference to the label for the selected radio button to change its background color, I don't know how to do it, the label is not linked with the radio button, what do you think? got any ideas?
+ 6
@Harish check the code again, I made some changes...
+ 6
Well, you can try to use buttons if you want to, it's your choice...
+ 6
The reason of the submit button is to allow the visitor to change their choice before processing if they changed their mind. You can choose to directly submit the choice when visitor click on one of the choices, without submit button, but it means visitors need to be careful in choosing, because they can't change the choice once the choice is submitted.
If you want button in place of radio button you can use multiple submit buttons, once either one is clicked the form is submitted. That's just my idea...
+ 5
@Harish, multiple choice in the lesson appears to be using radio buttons (cmiiw), the thing that worries me is that if we use JavaScript to change the choices appearance than the visitor can view the source, and can figure out the right answer by checking which choice will change the background color when clicked.
I guess this is also the reason why SoloLearn only allows game in the app.
+ 5
I'd suggest you create a function in php or JS and store it in a diff file and then call it whenever needed.
+ 5
Yes, just edit CSS for radio buttons' label
.rlabel{
display:block;
border:#c0c0c0 thin solid;
background-color:#abcdef;
}
I guess it's possible, but it means the visitor cannot change their choice, with the button visitor can still change their choice before submitting if they weren't sure of their choice.
+ 5
I tried to change background color for the radio button in the JS, but it doesn't work:
sel.style.backgroundColor="green";
We need to get a reference to the label for the selected radio button, I'm searching how to do that...
+ 5
What do you mean every time of true ans? I am not understanding you...?
+ 3
if $x == $xyz {
echo ' <body style="background-color:green">'
}
This should work
+ 3
implement my whole ans in HTML, its the same, the echo should do the job there
+ 3
do you want a button?
+ 3
sorry I don't have a solid answer to that right now
+ 2
here is my code an at the end of code read comment for description @Ipang
+ 2
should I have to do it using radio or select option?
+ 2
thanks bro@Ipang
+ 2
I mean after select the option color should change as per right or wrong
like if ans is write bgcolor is green and if ans is wrong bgcolor is red
+ 2
thanks again for helping me