I have a code that includes a click on a button, and either you are logged in and you go to the next page, or you are logged out and you get a warning. I never liked onClick inside HTML, so I would like to do this by clicking on id and getting jQuery my magic.
I understand the jQuery click function, but I donβt know how to put do_bid(".$val["id"]."); down with the rest of javascript. If I did not give enough information or if there is an official resource for this, let me know.
<li class='btn bid' onclick='do_bid(".$val["id"].");'> Bid </li> <script> //Some other Javascript above this function do_bid(aid) { var loged_in = "<?= $_SESSION["BPLowbidAuction_LOGGED_IN"] ?>"; if(loged_in=="") { alert('You must log in to bid!'); } else { document.location.href="item.php?id="+aid; } } </script>
UPDATE:. This is all Javascript code. I think none of the answers have worked so far because the answers do not match the rest of my Javascript. Hope this helps
<script language="JavaScript"> $(document).ready(function(){ function calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString(); if (LeadingZero && s.length < 2) s = "0" + s; return "" + s + ""; } function CountBack() { <? for($i=0; $i<$total_elements; $i++){ echo "myTimeArray[".$i."] = myTimeArray[".$i."] + CountStepper;"; } for($i=0; $i<$total_elements; $i++){ echo "secs = myTimeArray[".$i."];"; echo "DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,1000000));"; echo "DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));"; echo "DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));"; echo "DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));"; echo "if(secs < 0){ if(document.getElementById('el_type_".$i."').value == '1'){ document.getElementById('el_".$i."').innerHTML = FinishMessage1; }else{ document.getElementById('el_".$i."').innerHTML = FinishMessage2;"; echo " }"; echo "}else{"; echo " document.getElementById('el_".$i."').innerHTML = DisplayStr;"; echo "}"; } ?> if (CountActive) setTimeout("CountBack()", SetTimeOutPeriod); } function putspan(backcolor, forecolor, id) { document.write("<span id='"+ id +"' style='background-color:" + backcolor + "; color:" + forecolor + "'></span>"); } if (typeof(BackColor)=="undefined") BackColor = "white"; if (typeof(ForeColor)=="undefined") ForeColor= "black"; if (typeof(TargetDate)=="undefined") TargetDate = "12/31/2020 5:00 AM"; if (typeof(DisplayFormat)=="undefined") DisplayFormat = "%%D%%d, %%H%%h, %%M%%m, %%S%%s."; if (typeof(CountActive)=="undefined") CountActive = true; if (typeof(FinishMessage)=="undefined") FinishMessage = ""; if (typeof(CountStepper)!="number") CountStepper = -1; if (typeof(LeadingZero)=="undefined") LeadingZero = true; CountStepper = Math.ceil(CountStepper); if (CountStepper == 0) CountActive = false; var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990; var myTimeArray = new Array(); <? for($i=0; $i<$total_elements; $i++){?> ddiff=document.getElementById('el_sec_'+<?=$i;?>).value; myTimeArray[<?=$i;?>]=Number(ddiff); <? } ?> CountBack(); function do_bid(aid) { var loged_in = "<?= $_SESSION["BPLowbidAuction_LOGGED_IN"] ?>"; if(loged_in=="") { alert('You must log in to bid!'); } else { document.location.href="item.php?id="+aid; } } }</script>
source share