homepage Welcome to WebmasterWorld Guest from 54.242.126.9
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
dynamic dropdown
leo gatmaytan



 
Msg#: 4198119 posted 1:46 am on Sep 8, 2010 (gmt 0)

Hi,

I need to know how to create a dynamic dropdown. I already created a simple dynamic dropdown menu but I have a problem.

When the drop down is inside a form, it doesn't work but if it's not, it does work.

here is the code wherein the dropdown and textbox is inside a form:

try to remove the:



<form method="POST" action="--WEBBOT-SELF--">
<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->


and the


</form>


at the end. It will work once you remove it.










<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<script>
function valyusdesc(velvel){
if (velvel == 0)
{return ""}

if (velvel == 1)
{return "1"}
if (velvel == 2)
{return "2"}
if (velvel == 3)
{return "3"}
}

function D1_onchange() {
T1.value = valyusdesc(D1.value)

}
function D2_onchange() {
T2.value = valyusdesc(D2.value)

}
function D3_onchange() {
T3.value = valyusdesc(D3.value)

}

</script>

</head>

<body>

<form method="POST" action="--WEBBOT-SELF--">
<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p><select
onChange="return D1_onchange()" size="1" name="D1" id="D1" >
<option selected value="0">click here</option>
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</select><input type="text" name="T1" id="T1" size="20"><input type="submit" value="Submit" name="B1"></p>
<p><select
onChange="return D2_onchange()" size="1" name="D2" id="D2">
<option value="0" selected>click here</option>
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</select><input type="text" name="T2" id="T2" size="20"></p>
<p><select
onChange="return D3_onchange()" size="1" name="D3" id="D3">
<option selected value="0">click here</option>
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</select><input type="text" name="T3" id="T3" size="20"></p>
</form>

</body>

</html>

 

alias

10+ Year Member



 
Msg#: 4198119 posted 9:54 am on Sep 8, 2010 (gmt 0)

Right now the simplest solution in your case is to name your form and use values like FormName.D1.value to get the values.

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4198119 posted 1:25 pm on Sep 8, 2010 (gmt 0)

In your handlers, you are doing things like this:

T1.value = valyusdesc(D1.value)

But you have not defined what T1 is. You should be doing something like this:

var T1 = document.getElementById('T1');
T1.value = valyusdesc(D1.value);


Then it should work.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved