+ 1
Same variable for html and js?!
How can I write a variable in Js which is also in HTML ?! e.g. <html> <head> </head> <body> <form> <input type="text" id="age" placeholder="write your age here" name="age"> </form> <script> document.write("age") // or : alert("age") </script> </body> </html> what's wrong in this code?! how can i use the same attribute in both HTML and JS?!
5 Respostas
+ 2
maybe you forgot to put ; in it
0
use name. you used id. replace this
0
@jack sully. I used them both but none of them worked
0
i actually did not really catch what is you mean.
but if you try to show the person age which is in the input, you need to get the element value first. here's the code :
var ages = document.getElementById("age");
document.write(ages.value);
0
You shouldn't use the same value for different attributes in the same tag