简体   繁体   中英

JavaScript, onclick-event not responding

I hope to get a simple and straight answer as this is driving me crazy. I know this isn't the best way of doing this but I just can't figure out, why these two lines behave differently:

First line, working fine:

<img id="hellig_del42736" src="../images/kryds.png" title="Slet helligdagen den 01-01-2017..." alt="Slet helligdagen den 01-01-2017..." onclick="if(confirm('Vil du slette helligdagen den 01-01-2017?')){document.getElementById('helligid42736').style.textDecoration='line-through';hasChanged=false;window.location.href='/admin/admin.asp?vacfrom='+(25569+(new Date(document.getElementById('feriefra').value).getTime()/1000/86400))+'&delbankhd=42736&page=2&sid=feriefra'}" onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor=''">

Second line, not responding - sometimes resulting in "member not found-error" - sometimes works if debugging (F12) is open:

<img id="blockedip_del8" src="../images/kryds.png" title="Fjern blokeringen af IP# 5.6.7.8 (mail@mail.dk)..." onclick="if(confirm('Vil du fjerne blokeringen af IP# 5.6.7.8 (mail@mail.dk)?')){document.getElementById('blockid8').style.textDecoration='line-through';hasChanged=false;window.location.href='/admin/admin.asp?delblockedip={93F17D3B-7FA1-48F1-8792-K52E30273818}&page=5&sid=deadlinetime'}" onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor=''">

I have tried several thing inside the comfirm()-statement (second line):

  • Removed paranthesis with no difference
  • Removed hashtag with no difference
  • Ensured that there are no conflicting id's

These lines are to my best knowledge codewise identical yet they behave differently.

I know I can put all the statements in a function and that "I really shouldn't..." but if this is how I want it, how can I fix it?

Thanks,

I'm an idiot!

For some idiotic reason I had used id="confirm" on a form element within the same form and changing that reserved word to id="confirmation" solved everything.

I thought I checked everything but I hadn't. Only removing elements one by one and testing led to the error.

Thanks "idmean" for pointing me to the surrounding code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM