Results 1 to 5 of 5

Thread: Client side JS and HTML

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Question Client side JS and HTML

    I have tried to make my GUI dependent on a variable, is this possible with JS? I have used this often in ASP.
    Code:
    <script language="JavaScript">
    var test = 2;
    if (test==1) {
    </script>
    <table>
    <tr>					
       <td><input type=text name=t1 value=Component size=8></td>
    </tr>
    </table>
    <script language="javascript">
    }
    </script>

  2. #2
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    I think you want something more like this:

    Code:
    <script language="JavaScript">
    var test = 2;
    if (test==1) {
    document.writeln('<table>');
    document.writeln('<tr>');
    document.writeln('   <td><input type=text name=t1 value=Component size=8></td>');
    document.writeln('</tr>');
    document.writeln('</table>');
    }
    </script>

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    Great thanks!
    Do you know how I make 20 equal lines using FOR with text fields with generated names?
    I wish the code below genrated:
    Code:
    <input type=text name=t1 value=100>
    <input type=text name=t2 value=100>
    <input type=text name=t3 value=100>
    <input type=text name=t4 value=100>
    <input type=text name=t5 value=100>
    <input type=text name=t6 value=100>
    <input type=text name=t7 value=100>
    <input type=text name=t8 value=100>
    <input type=text name=t9 value=100>
    <input type=text name=t10 value=100>
    Can I do this using FOR with JS?
    Something like:
    Code:
    <script language="JavaScript">
    for (i=1;i<11;i++){
    document.write('   <td><input type=text name=t+i value=100></td>');
    	}
    </script>

  4. #4
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Code:
    <script language="JavaScript"><!--
    for (i=1;i<11;i++){
    document.write('   <td><input type=text name=t' + i + 'value=100></td>');
    	}
    //--></script>
    That's should work. But you should note that not everyone has JavaScript, or they don't have it enabled so they will see nothing. You should try to use JS only for purely non-essential things and use a method that will work for everyone when possible. But it's your choice, so have fun

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    GREAT THANKS, Mr Smart (myself!) forgot <!-- .... -->
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width