jsp - Set parameter of font color from javascript -


i need show text <reg id:> in red color if reg id null or empty. current implementation on alert, color not changed.

<html> <head> <script type="text/javascript">     function validateform() {         var stu_regid = document.forms["detail"]["regid"].value;          if ((null == stu_regid) || (stu_regid == "")) {             alert("reg should not left blank");                         // here change color red             document.getelementsbyname("font_regid").innerhtml = "red";             return false;         }     } </script> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>insert title here</title>  </head> <body> <%!string font_regid = new string();%>     <form name="detail" action="reportgenerator" method="get"         onsubmit="return validateform()">          <font color=<%=font_regid%>>reg id:</font>          <input type="text" name="regid"><br>          // code here           <input type="submit" value="submit">     </form>  </body> </html> 

after little more research came 1 simple solution.

i used

span

tag id , receive id in javascript. way worked me. changed font span, thing following

    <span id="id_01120">reg id:</span>      <input type="text" name="regid"><br> 

and receive following

if ((null == label_id) || (label_id == "")) {         showerror(label_id, document.getelementbyid("id_01120"));         return false;     } 

and change color following

    function showerror(errorfield, errorfont) {     alert(errorfield.concat("should not left blank"));     errorfont.style.color = "red"; } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -