php - firefox having "#;" in the addressbar -
why firefox(haven't tested in browser) has problems loading form values when #;
in addressbar? if have <input type='radio' checked="checked">
, presence of element in addressbar may lead input not getting checked(as expected)
how can avoid behavior?
example code:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" style="min-height:100%;"> <head> <title>stuff2test</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <body class="popup" > <form action="" id="frm"> <a href="#;" onclick="alert('added');">add #; addressbar, , refresh</a> <?php $rnd = mt_rand(1, 4); ?> <label for="r_v1"> <input id="r_v1" type="radio" value="v1" <?php if($rnd==1){ echo 'checked="checked"';}?> name="r"></input> checked?</label> <label for="r_v2"> <input id="r_v2" type="radio" value="v2" <?php if($rnd==2){ echo 'checked="checked"';}?> name="r"></input> checked?</label> <label for="r_v3"> <input id="r_v3" type="radio" value="v3" <?php if($rnd==3){ echo 'checked="checked"';}?> name="r"></input> checked?</label> </form> <button onclick="getelementbyid('frm').submit();" type="button">submit</button> <br/> rnd: <?php echo $rnd;?> <?php if($rnd>0 && $rnd<=3){ echo "checkbox {$rnd} should checked"; } ?> <br/> <?php var_dump($_get); ?> </body> </html>
edit2: cleaned code little, added echo
from reading comments on question, answer seems clear.
the problem firefox tries remember state of form when reload page, includes checkboxes checked , aren't. though vary default values in html on reload, firefox sees same form , ignores defaults set in html in favor of has saved before reload.
i've heard can disable behavior supplying http header cache-control: no-store
, or specifying autocomplete="off"
on form elements. have not tested either solution personally. or use javascript reset form on page load (either form object's reset()
or explicitly setting each field's value).
Comments
Post a Comment