/    Sign up×
Community /Pin to ProfileBookmark

dropdown question

i got 2 questions to ask

  • 1.

    i ‘m trying to change the background color in the input field after i select color from the dropdown list. but it’s just give me the name of the color in the input field instead of the color changing. so what did i do wrong in the getcolor fuction?

  • 2.

    i ‘m trying to load pic from the drop down list. but i don’t know what’s wrong with the showflag function.

  • please give me an example with ur explanation. thanks!

    <HTML>
    <HEAD><TITLE> ASSIGNMENT4 </TITLE>
    <script type=”text/javascript”>
    function getcolor()
    {
    txt=document.forms[0].color.options[document.forms[0].color.selectedIndex].text
    document.forms[0].SOURCEBOX.value=txt
    }
    </script>
    <script>
    function getfont()
    {
    txt=document.forms[0].font.options[document.forms[0].font.selectedIndex].text
    document.forms[0].SOURCEBOX.value=txt
    }
    </script>
    <script>
    function changeFlag()
    {
    var FlagFile = new Array (“blank.gif”, “US.gif”, “Canada.gif”);
    var FlagText = new Array (“”, “US Flag”, “Canada Flag”);
    var selection = document.ShowFlag.Flag.selectedIndex;
    var theChoice = document.ShowFlag.Flag.options[selection].value;
    document.pic.src = FlagFile[theChoice];
    document.all.picWords.innerText = FlagText[theChoice];
    }
    </script>

    <form method = “post”>
    Name:<br> <input type=”text” name=”name” size=”29″><br>
    Age:<br> <input type=”text” name=”age” size=”29″><br>
    Please Complete: <br><TEXTAREA NAME= “SOURCEBOX” ROWS=”10″ COLS=”30″WRAP=”HARD”></TEXTAREA><br>
    <BR>
    <BR>

    <form>
    <select name=”color” onchange=”getcolor()”>
    <option value=”color choices”>Color Choices
    <option value=”pink” style=”color:pink”>Pink
    <option value=”tan” style=”color:tan”>Tan
    <option value=”cyan” style=”color:cyan”>Cyan
    </select>

    <select name=”font”onchange=”getfont()”>
    <option value=”FontSize Choices”>FontSize Choices
    <option value=”Regular”>Regular
    <option value=”Medium”>Medium
    <option value=”Large”>Large
    </select>
    </form>
    <form NAME=”ShowFlag”>
    <select name=”Flag” onChange=”changeFlag()”>
    <option value=”Choose a Flag “>Choose a Flag
    <option value=”US.GIF”>US
    <option value=”Canada.GIF”>Canada
    <option value=”None”>None
    </select>
    </form>

    <IMG SRC=”blank.gif” NAME=”pic” BORDER=”0″>
    <SPAN ID=”picWords” NAME=”picWords”></SPAN>
    <P><INPUT TYPE=”SUBMIT” VALUE=”Send”>
    </HTML>

    to post a comment
    JavaScript

    4 Comments(s)

    Copy linkTweet thisAlerts:
    @Khalid_AliSep 29.2004 — try reading stickies on the top of the forums.They are there to guide you post right question in right forum.

    Moving this post to JavaScript forums.
    Copy linkTweet thisAlerts:
    @javaNoobieSep 29.2004 — 1) Your function is only getting value from the dropdownlist and nothing else. To change the style of an element, you would need to change the style or the class. document.forms[0].elements['&lt;elementNameHere&gt;'].style.&lt;css attribute&gt; = '&lt;whatever value&gt;'
    OR
    document.forms[0].elements['&lt;elementNameHere&gt;'].className = &lt;css class&gt;


    2)Your dropdown list values are currently in text not numbers. Therefore, var theChoice will return a string value. When used with the array, it will probably look like this: FlagFile['US.GIF']
    Copy linkTweet thisAlerts:
    @Warren86Sep 29.2004 — FG5:

    Try it this way.

    <HTML>

    <HEAD><TITLE> ASSIGNMENT4 </TITLE>

    <script type="text/javascript">

    function getcolor()

    {

    txt=document.forms[0].isColor.options[document.forms[0].isColor.selectedIndex].value

    document.forms[0].SOURCEBOX.style.backgroundColor = txt;

    }

    </script>

    <script>

    function getfont()

    {

    txt=document.forms[0].isFont.options[document.forms[0].isFont.selectedIndex].value

    document.forms[0].SOURCEBOX.style.fontSize = txt;

    }

    </script>

    <script>

    function changeFlag()

    {

    var FlagFile = new Array ("blank.gif", "US.gif", "Canada.gif");

    var FlagText = new Array ("", "US Flag", "Canada Flag");

    var selection = document.ShowFlag.Flag.selectedIndex;

    var theChoice = document.ShowFlag.Flag.options[selection].value;

    document.pic.src = FlagFile[theChoice];

    document.all.picWords.innerText = FlagText[theChoice];

    }

    </script>

    <form method = "post">

    Name:<br> <input type="text" name="name" size="29"><br>

    Age:<br> <input type="text" name="age" size="29"><br>

    Please Complete: <br><TEXTAREA NAME= "SOURCEBOX" ROWS="10" COLS="30"WRAP="HARD" style=background-color='white'></TEXTAREA><br>

    <BR>

    <BR>

    <form>

    <select name="isColor" onchange="getcolor()">

    <option value="color choices">Color Choices

    <option value="pink" style="colorink">Pink

    <option value="tan" style="color:tan">Tan

    <option value="cyan" style="color:cyan">Cyan

    </select>

    <select name="isFont"onchange="getfont()">

    <option value="FontSize Choices">FontSize Choices

    <option value="9pt">Regular

    <option value="11pt">Medium

    <option value="13pt">Large

    </select>

    </form>

    <form NAME="ShowFlag">

    <select name="Flag" onChange="changeFlag()">

    <option value="Choose a Flag ">Choose a Flag

    <option value="US.GIF">US

    <option value="Canada.GIF">Canada

    <option value="None">None

    </select>

    </form>

    <IMG SRC="blank.gif" NAME="pic" BORDER="0">

    <SPAN ID="picWords" NAME="picWords"></SPAN>

    <P><INPUT TYPE="SUBMIT" VALUE="Send">

    </HTML>
    Copy linkTweet thisAlerts:
    @fg5authorSep 29.2004 — thanks warren86 please check ur PM
    ×

    Success!

    Help @fg5 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...