Jump to content

How input an object word into a variable?


passegua

Recommended Posts

I am trying to make this script working with a prompt that ask the user which object (screen, location, window) property will show.
If I use this code it will works with this:

Propriedades

Propriedad Valor
availWidth = 1280
availHeight = 800
availTop = 0
availLeft = 0
pixelDepth = 24
colorDepth = 24
width = 1280
height = 800

<body>

<h2>Propriedades</h2>

<table id="tabla">

<tr><th> Propriedad </th><th> Valor </th></tr>

</table>



<script type="text/javascript">







var i, tabla = document.getElementById("tabla");

for (i in screen){

    tabla.innerHTML += "<tr><td>"+i+" </td><td> = " +screen[i]+ "</td></tr>";

}

</script>



</body>

But If I ask which name with a prompt, then the output is wrong, why? Please Help me! Thanks.


Propriedades

Propriedad Valor
0 = s
1 = c
2 = r
3 = e
4 = e
5 = n

<body>

<h2>Propriedades</h2>

<table id="tabla">

<tr><th> Propriedad </th><th> Valor </th></tr>

</table>



<script type="text/javascript">



name=prompt("¿Que propriedad quiere?");



var i, tabla = document.getElementById("tabla");

for (i in name){

    tabla.innerHTML += "<tr><td>"+i+" </td><td> = " +name[i]+ "</td></tr>";

}

</script>



</body>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.