Evertjan.
9/7/2014 7:57:00 AM
bobspero@gmail.com wrote on 07 sep 2014 in comp.lang.javascript:
> I have an external js file in my php project, RCC is a dropdown. I want
> to get the value of RCC from an external java script file, can someone
> assist with what I am missing?
It is a Javascript script, I hope,
not a [non-existing] Java script?
Your Q has nothing to do with php,
as it is about clientside js and the DOM.
Dropdown? I stipulate you mean an html <select>?
What browser do you use, Netscape?
> var x = document.forms["index"]["RCC"].value;
Stipulating that:
"index" is the name of the <form>, not the id
"RCC" is the name of rhe <select>, not the id
This works fine:
<script type='text/javascript'>
function a() {
var mySelect = document.forms.index.RCC;
var selVal = mySelect.value;
alert(selVal);
};
</script>
<button onclick='a();'>x</button>
[
Antique browsers need additional scripting:
var selVal = mySelect.options[mySelect.selectedIndex].value;
]
==========================
You could also have the value prepared onchange:
<script type='text/javascript'>
var selVal = 'notyet selected, suspect "0"'; // global
</script>
<select onchange='selVal = this.value;'>
<option value='0'>-- Select --</option>
<option value='x1'>text 1</option>
<option value='x2'>text 2</option>
<option value='x3'>text 3</option>
</select>
<button onclick='alert(selVal);'>What value?</button>
============================
Try as a joke:
<button onclick='this.innerHTML=selVal;'>What value?</button>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)