i have simple onchange()
function called select
element, should set hidden element value, based on switch
value. can switch statement working hidden element value doesn't set - obvious here?
the function called ok, alert statement @ end shows correct value, eg, 'one@example/com' - cannot update hidden element 'recipient' new value.
function setemail() { var s = document.getelementbyid('school_institute'); var school = s.options[s.selectedindex].value; var x = document.getelementbyid('recipient'); switch(school) { case 'name 1': x = 'one@example.com'; break; case 'name 2': x = 'two@example.com'; break; default: x = 'three@example.com'; break; } }
would appreciate help.
thanks
use [object htmlinputelement].value
instead of overwriting reference element:
function setemail() { var s = document.getelementbyid('school_institute'); var school = s.options[s.selectedindex].value; var x = document.getelementbyid('recipient'); switch(school) { case 'name 1': x.value = 'one@example.com'; break; case 'name 2': x.value = 'two@example.com'; break; default: x.value = 'three@example.com'; break; } } // x = document.getelementbyid('recipient'); // x = 'hello'; // here overwrite reference node // instead set value using `.value` // x = document.getelementbyid('recipient'); // x.value = 'hello';
Comments
Post a Comment