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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.