I am going around the bend trying to get a return value from a dropdown so that I can use else where on an asp page, it gives the alert ok, however I cannot seem to do anything else useful with it. Any help would be extremely appreciated!!! ...Ian

<code>
<html>
<head>
<title>page</title>
<script language="javascript" >

function alertselected()
{
alert(document.test.prodquantity.selectedIndex)
nbrQty = (document.test.prodquantity.selectedIndex)
}

document.write("<form name='test'>")
document.write("<select name='prodquantity' onChange='alertselected()'>")
document.write("<OPTION value='1' SELECTED>1")
document.write("<OPTION value='2'>2")
document.write("<OPTION value='3'>3")
document.write("<OPTION value='4'>4")
document.write("<OPTION value='5'>5")
document.write("<OPTION value='6'>6")
document.write("</SELECT></form>")

document.write("<p>" + nbrQty)

</script>
</body>
</html>
</code>

If your trying to do it with asp you have to send it back to the server before you can get the value. But if you want to use it on this page do it in the alertselected area.


function alertselected()
{
alert(document.test.prodquantity.selectedIndex)
nbrQty = (document.test.prodquantity.selectedIndex)
document.writeline()
}

Hi Jess, thanks for your input! I have changed the code and removed the actual alert part as it was only to see that the values were actually there. However with the alert gone it no longer displays ... (all I need is the value to be passed to a variable - why does it have to be so difficult?!) If you can assist it would be appreciated! ... Ian

<code>
<html>
<head>
<title>page</title>
<script language="javascript">

function alertselected()
{
var nbrQty = (document.test.prodquantity.selectedIndex)document.writeline();
}

document.write("<form name='test'>")
document.write("<select name='prodquantity' onChange='alertselected()'>")
document.write("<OPTION value='1' SELECTED>1")
document.write("<OPTION value='2'>2")
document.write("<OPTION value='3'>3")
document.write("<OPTION value='4'>4")
document.write("<OPTION value='5'>5")
document.write("<OPTION value='6'>6")
document.write("</SELECT></form>")
document.write("<p>" + nbrQty)
</script>
</body>
</html>
</code>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.