-
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>
-
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>
-
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>
-
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 :D
-
GREAT THANKS, Mr Smart (myself!) forgot <!-- .... -->
Have a nice day! :cool: