View Full Version : Javascript

11-10-2012, 08:38 PM
Got it working

Old Pedant
11-10-2012, 09:16 PM
It doen't work because the method document.write( ) does *NOT* return any value.

SO when you do

var randomNumber = document.write(Math.floor((Math.random()*5)+4));

indeed that writes the number to the screen, but then it assigns the result of calling document.write( ) to your variable. But, as I said, that result is non-existent, so you are assigning null to your variable.

It is also true that you shouldn't depend on being able to set the .value of a <select>.

11-10-2012, 09:17 PM
var randomNumber = Math.floor((Math.random()*5)+4);

var runme = function(){
document.getElementById('selectBox').value = randomNumber;


and add id="selectBox" to the <select>

Old Pedant
11-10-2012, 09:28 PM

His code says

<select id='selectBox' name='selectBox'>

11-10-2012, 09:31 PM
the id is already there, still not sure whats wrong with my code :(

11-10-2012, 09:34 PM
i got it to work thanks