javascript - How to use same name tag to display innerhtml according to click? -


html

<div name="hhh" class="col-sm-7  new" align="left" >  </div> 

javascript

yes.onclick =function() { var = document.getelementsbyname("hhh");     for(var = 0, max = all.length; < max; i++)          {             all[i].innerhtml="you have clicked yes.";          }  }   no.onclick =function() { var = document.getelementsbyname("hhh");     for(var = 0, max = all.length; < max; i++)          {             all[i].innerhtml="you have clicked no.";          }  } 

here in html 2 buttons there yes , no.if user clicks yes,yes.onclick() execute , if user clicks no,no.onclick() execute. in same division hhh, have display message according click. if write above code,the message displayed before click. considering hhh 1 name. how can edit code, display message according click? right on writing existing message.i dont want on write.i want display previous message also.

u should use getelementsbytagname() or better u should use getelementbyid if have 1 div.

where assign name "yes" , "no" js var? maybe problem that. if there no reason assign function dinamically code can define 1 function

function myerror(e){     var = document.getelementsbytagname("hhh");         for(var = 0, max = all.length; < max; i++)          {             all[i].innerhtml="you have clicked " + e.value;          } } 

then assign function ur button

<input type="button" value="yes/no" onclick="myerror(this)"> 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -