I have a function that creates a Select dropdown on the fly:
function makeForm() {
mypara=document.getElementById(“paraID”);
myform=document.createElement(“form”);
myselect = document.createElement(“select”);
theOption=document.createElement(“OPTION”);
theText=document.createTextNode(“Revenue”);
theOption.appendChild(theText);
myselect.appendChild(theOption);
myform.appendChild(myselect);
mypara.appendChild(myform);
myselect.onchange=TitleOnChange;
mybreak=document.createElement(“p”);
myform.appendChild(mybreak);
}
function makeForm() {
mypara=document.getElementById(“paraID”);
myform=document.createElement(“form”);
myselect = document.createElement(“select”);
theOption=document.createElement(“OPTION”);
theText=document.createTextNode(“Revenue”);
theOption.appendChild(theText);
myselect.appendChild(theOption);
myform.appendChild(myselect);
mypara.appendChild(myform);
myselect.onchange=TitleOnChange;
mybreak=document.createElement(“p”);
myform.appendChild(mybreak);
}
I would guess that I have to add something like: theOption.setAttribute(“value”,“1”);
I want to be able to call the following function and execute a code base on the selection of the Select Dropdown:
<script type=‘text/javascript’>
function TitleOnChange()
{
if (document.form.select.value == “1”)
{
alert(“Value selected on the Select dropdonw is 1”);
}
}
</script>
<script type=‘text/javascript’>
function TitleOnChange()
{
if (document.form.select.value == “1”)
{
alert(“Value selected on the Select dropdonw is 1”);
}
}
</script>
I don’t know why is not working. I assigned the value 1 to the select dropdown theOption.setAttribute(“value”,“1”);
I call the TitleOnChange function myselect.onchange=TitleOnChange;
And Finally I indicate that if the value is equal to 1 do…
view plaincopy to clipboardprint?
if (document.form.select.value == “1”)
{
alert(“Value selected on the Select dropdonw is 1”);
}
if (document.form.select.value == “1”)
{
alert(“Value selected on the Select dropdonw is 1”);
}
Does anyone knows why this doesn’t work and how could I fix it?
Any helpt would be highly appreciate.
Thanks