Forum Moderators: open

Message Too Old, No Replies

set form name, and input name through function

         

drooh

9:14 pm on Apr 13, 2011 (gmt 0)

10+ Year Member



Any ideas how to achieve this? Trying to set the form name and input name to get value of select box in a form.

<script>
function resize(inputname,formname){
value = document.formname.inputname.options[document.formname.inputname.selectedIndex].value;
alert(value);
}
</script>

Fotiman

10:28 pm on Apr 13, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You would need to use the array notation:

var el = document[formname][inputname];
var value = el.options[el.selectedIndex].value;

drooh

12:33 am on Apr 14, 2011 (gmt 0)

10+ Year Member



thanks! do u know of any resource that covers this more in detail?

I found this works too (for the sake of other viewers...looks like the original post)

<script>
function resize(formname,inputname){
var input_tfs = document[formname][inputname].options[document[formname][inputname].selectedIndex].value;
alert(input_tfs);
}
</script>