javascript - "onclick" of a button in a popup works only once -
i have html/php webpage (the file called searchresults.php) imports jquery mobile. when enter page, url
www.domain.com/searchresults.php?&sort="off"&max="5"
in example sorting off , 5 items displayed. on page button opens popup want user able change these settings. use built-in jquery mobile popup. on popup can toggle "sort" on/off , can enter new maximum. on popup "ok" button confirm new settings. looks this:
<a href="" id="okbutton" data-role="button" onclick="sortagain();">ok</a>
the sortagain(); function in javascript looks this:
function sortagain(); { //some code necessary variables// ... //change href of button reload page document.getelementbyid("okbutton").href = "searchresults.php" + "?keyword=" + var1 + "&sort=" + var2 + "&max=" + var3 }
so, basically, right before "ok" button navigates page, set href of page should navigate too.
this scheme works, , searchresults.php file fetched again server , re-interpreted (with new variables in url).
however, if try change settings again after changing once, popup nothing! in other words, href of ok button on popup stays empty , javascript function sortagain() not called. don't understand why calls onclick method fine first time, refuses call again?
i assume has fact popup html code integral part of searchresult.php file, , hrefing same page gives problems? popup pure html, no php involved in popup code. , again, works fine first time.
you should check out how attach events via javascript. see here: javascript attaching events
Comments
Post a Comment