Sign in

document.getElementById Cannot get value

ypvpi edited in Thu, 13 Oct 2022
 function diqu(){

                    else if(document.getElementById("hz").checked)
<!DOCTYPE html>
<meta charset="utf-8">
<div class="cnt">
                    <li><span>&nbsp;</span><label><input type="radio" id="sh" value="" />上海</label></li>
                    <li><span>&nbsp;</span><label><input type="radio" id="hz" value="" />杭州 </label></li>
<button onclick="diqu()">试一试</button>


This is a part of the evaluation form, to enable users to choose Hangzhou and Shanghai to jump to different web pages, but after the selection, it always says "you haven't chosen your region yet!" , it seems that no value has been obtained. Do you have a solution? Assessment link address: http://www.xakj365.com/aa/zlc...

I also have an idea. Is this evaluation selected one by one? In the end, the selection status is not saved, so JS thinks there is no selection?

2 Replies
commented on Fri, 14 Oct 2022


This is how to write the HTML structure

<input id="hz" type="radio">
<label for="hz">杭州</label>
<input id="sh" type="radio">
<label for="sh">上海</label>

You are like this now, all are false


If you can't change it, you can also traverse the. Sel of < Li class = "hover sel" >

If it can help you, you can like it and accept a reward
commented on Fri, 14 Oct 2022

Your own radio shows that the real radio is not checked. You can test it by removing the display none of input