1) You could write instructions like
intElemTemp =3D form1.elements["q"+i].length;
instead of
intElemTemp =3D eval("form1.q"+i+".length");
This is easier to read, esp. if you have syntax highlighting because
you
don't just have string everywhere.
2) I don't know if you could address to your <div> like this:
eval("q"+i+"Layer.style.font-weight=3D'bold';");
I would rather do like this:
document.getElementById("q"+i+"Layer").style.fontWeight=3D'bold'
NB: there's also the problem of misspelling as pointed out by another
users.
You could find a list of scriptable style here :
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html#CSS-CS
S2Pr
operties
and scroll down a bit to the table of "IDL Definition"
3) You don't need to write "javascript:" for event-handler (this could
get
inside the FAQ!)
> -----Message d'origine-----
> De : Jeremy.Riedell@p... [mailto:Jeremy.Riedell@p...]
> Envoy=C3=A9 : lundi 9 d=C3=A9cembre 2002 23:44
> =C3=80 : javascript
> Objet : [javascript] All questions answered before submition
>
>
> I am working on a form. When someone answered the questions
> and submits
> it, it checks to make sure they have answered all the
> quesiton. For the
> questions they forgot to answer, i want it to bold those
> qestions to make
> them more visible to the person filling it out. Any suggestions on
> getting this to work
>
> Thanks!
>
> sample code below:
> -----------------------------------------------
>
> <html>
> <head>
> <title>Investing Survey</title>
> <meta http-equiv=3D"Content-Type" content=3D"text/html;
> charset=3Diso-8859-1">
> <script ID=3D"clientEventHandlers" LANGUAGE=3D"javascript" >
> <!--
>
> function checkQ() {
> qAllFlg =3D 0;
> for(i=3D1;i<=3D6;i++){
> intElemTemp =3D eval("form1.q"+i+".length");
> qFlag =3D 0;
> for(j=3D0;j<=3DintElemTemp-1;j++){
> if (eval("form1.q"+i+"("+j+").checked")){
> qFlag =3D 1;
> qAllFlg =3D 1;
> break;
> }
> }
> if(qFlag =3D=3D 0){
> eval("q"+i+"Layer.style.font-weight=3D'bold';");
> } else {
> eval("q"+i+"Layer.style.font-weight=3D'normal';");
> }
> }
> if (qAllFlg =3D=3D 1) {
> alert("Please answer the questions that are bold.");
> } else {
> document.form1.method =3D "POST";
> document.form1.target =3D "_self";
> document.form1.action =3D "survey.asp";
> document.form1.submit();
> }
> }
>
> -->
>
> </script>
>
> <STYLE TYPE=3D"text/css">
> div { position : absolute; width : 100%; height : 100%;
> z-index : 1; font-
> weight : normal; }
> --</STYLE>
>
> </head>
>
> <body>
> <form name=3D"form1" method=3D"post" action=3D"">
>
> <table width=3D"600" border=3D"0" cellspacing=3D"6"
cellpadding=3D"10">
> <tr>
> <td bgcolor=3D"#CCCCCC">Please fill out all of the 10
> questions in
> the following survey. </td>
> </tr>
> <tr>
> <td bgcolor=3D"#EEEEEE"> <p>
>
> <p>
> <div id=3D"q1Layer">1. At what age did you first
> learn to save
> and invest?</div>
> <blockquote>
> <p>
> =09
> <br>
> <br>
> =09
> <input type=3D"radio" name=3D"q1" value=3D"1">
> Under12<br>
> =09
> <input type=3D"radio" name=3D"q1" value=3D"2">
> 12-18<br>
> =09
> <input type=3D"radio" name=3D"q1" value=3D"3">
> 19<br>
> =09
> <input type=3D"radio" name=3D"q1" value=3D"4">
> 24<br>
> =09
> <input type=3D"radio" name=3D"q1" value=3D"5">
> 25<br>
> =09
> <input type=3D"radio" name=3D"q1" value=3D"6">
> 50<br>
> =09
> <input type=3D"radio" name=3D"q1" value=3D"7">
> over 50<br>
> =09
> </p>
> </blockquote>
>
> <p><div id=3D"q2Layer">2. Do you consider yourself an
> active investor in the stock markets?</div>
> <blockquote>
> <p>
> =09
> <br>
> <br>
> =09
> <input type=3D"radio" name=3D"q2" value=3D"1">
> Yes<br>
> =09
> <input type=3D"radio" name=3D"q2" value=3D"2">
> No, never<br>
> =09
> <input type=3D"radio" name=3D"q2" value=3D"3">
> Not right now<br>
> =09
> <input type=3D"radio" name=3D"q2" value=3D"4">
> Would like to<br>
> =09
> </p>
> </blockquote>
>
> <p><div id=3D"q3Layer">3. How did you first learn to
> invest in the stock market?</div>
> <blockquote>
> <p>
> =09
> <br>
> <br>
> =09
> <input type=3D"radio" name=3D"q3" value=3D"1">
> My parents<br>
> =09
> <input type=3D"radio" name=3D"q3" value=3D"2">
> My spouse or friend<br>
> =09
> <input type=3D"radio" name=3D"q3" value=3D"3">
> Joined an investment club<br>
> =09
> <input type=3D"radio" name=3D"q3" value=3D"4">
> I just decided to teach myself<br>
> =09
> <input type=3D"radio" name=3D"q3" value=3D"5">
> My broker or financial advisor<br>
> =09
> </p>
> </blockquote>
>
> <p><div id=3D"q4Layer">4. Why did you learn about the
> stock market?</div>
> <blockquote>
> <p>
> =09
> <br>
> <br>
> =09
> <input type=3D"radio" name=3D"q4" value=3D"1">
> I felt more control would reap better returns<br>
> =09
> <input type=3D"radio" name=3D"q4" value=3D"2">
> I didn't like feeling ignorant about it<br>
> =09
> <input type=3D"radio" name=3D"q4" value=3D"3">
> It was a new challenge<br>
> =09
> <input type=3D"radio" name=3D"q4" value=3D"4">
> Everyone else was, and I didn't want to miss out<br>
> =09
> <input type=3D"radio" name=3D"q4" value=3D"5">
> I don't know<br>
> =09
> </p>
> </blockquote>
>
> <p><div id=3D"q5Layer">5. At what age did you
> purchase
> your first stock?</div>
> <blockquote>
> <p>
> =09
> <br>
> <br>
> =09
> <input type=3D"radio" name=3D"q5" value=3D"1">
> Under 12<br>
> =09
> <input type=3D"radio" name=3D"q5" value=3D"2">
> 12-19<br>
> =09
> <input type=3D"radio" name=3D"q5" value=3D"3">
> 20-25<br>
> =09
> <input type=3D"radio" name=3D"q5" value=3D"4">
> 26-50<br>
> =09
> <input type=3D"radio" name=3D"q5" value=3D"5">
> over 50<br>
> =09
> </p>
> </blockquote>
>
> <p><div id=3D"q6Layer">6. Have you been in an
> investment
> club?</div>
> <blockquote>
> <p>
> =09
> <br>
> <br>
> =09
> <input type=3D"radio" name=3D"q6" value=3D"1">
> Less than 2 years<br>
> =09
> <input type=3D"radio" name=3D"q6" value=3D"2">
> 2-10 years<br>
> =09
> <input type=3D"radio" name=3D"q6" value=3D"3">
> More than 10 years<br>
> =09
> <input type=3D"radio" name=3D"q6" value=3D"4">
> Was in one, but not now<br>
> =09
> <input type=3D"radio" name=3D"q6" value=3D"5">
> Never in one<br>
> =09
> </p>
> </blockquote>
>
> <p>
> <blockquote>
> <p> </p>
> </blockquote>
> </td>
> </tr>
> <tr>
> <td>
> <input name=3D"Button" type=3D"button"
> value=3D"Submit Survey"
> onClick=3D"javascript:checkQ()">
> </td>
> </tr>
> </table>
> </form>
> </body>
> </html>