Web Analytics Made Easy -
StatCounter Execute javascript function based on selected dropdown list value - CodingForum

Announcement

Collapse
No announcement yet.

Execute javascript function based on selected dropdown list value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Execute javascript function based on selected dropdown list value

    I would like to use a dropdown list that would execute a different javascript funtion based on the value the user selected.

    My first goal is if 1,2,3,4,or 5 is chosen the second field(named "Eway") appears. If 0 is chosen the field disappears.

    My second goal is if the 2nd field is visable it needs to be required, when it is not visible it should NOT be required.

    Here is what I've got so far...

    <SCRIPT>
    function yes() {
    MMDiv.style.visibility='visible';
    mainform.MakeModel.focus();
    }</SCRIPT>
    <SCRIPT>
    function no() {
    MMDiv.style.visibility='hidden';
    mainform.MakeModel.focus();
    }</SCRIPT>

    <table width="292" align=center cellpadding=0 cellspacing=1 bgcolor=A4C0DD border=1><tr><td colspan="8">
    <table border="0" align="center"><tr>

    <td height=10 width="50"><B>Card 1</td>

    <td>Qty
    <select class=d type=text name=qty1 size=1 onchange="yes()">
    <option selected value="0"></option>
    <option onchange=yes() value="1">1 box of 250</option>
    <option value="2">2 boxes of 250</option>
    <option value="3">3 boxes of 250</option>
    <option value="4">4 boxes of 250</option>
    <option value="5">5 boxes of 250</option>
    </td>

    <td>
    <DIV ID="MMDiv" style="visibility:hidden">
    <LABEL FOR="MakeModel">Eway # <INPUT TYPE="TEXT" class="d" ID="MakeModel" name="requiredeway1" size="6">
    </LABEL>
    </DIV>
    </td>

    </tr></table>
    </td></tr></table>

  • #2
    Please see if the following helps you out

    <HTML>
    <HEAD>
    <TITLE>Document Title</TITLE>

    <SCRIPT>
    <!--
    function hmm(n){
    (n==0?document.getElementById("MMDiv").style.visibility="hidden":document.getElementById("MMDiv").st yle.visibility="visible")

    switch (n){
    case 1 :
    alert("1 box of 250")
    break

    case 2 :
    alert("2 box of 250")
    break;

    case 3 :
    alert("3 box of 250")
    break;

    case 4 :
    alert("4 box of 250")
    break;

    case 5 :
    alert("5 box of 250")
    break;

    default :
    alert("Oops")
    }

    }

    // -->
    </SCRIPT>

    </HEAD>
    <BODY>
    <form name="my_form">
    <table width="292" align=center cellpadding=0 cellspacing=1 bgcolor=A4C0DD border=1><tr><td colspan="8">
    <table border="0" align="center"><tr>

    <td height=10 width="50"><B>Card 1</td>

    <td>Qty

    <select class=d name=qty1 size=1 onChange="hmm(this.form.qty1.selectedIndex)">
    <option selected value="0"></option>
    <option value="1">1 box of 250</option>
    <option value="2">2 boxes of 250</option>
    <option value="3">3 boxes of 250</option>
    <option value="4">4 boxes of 250</option>
    <option value="5">5 boxes of 250</option>
    </select>

    </td>

    <td>
    <DIV ID="MMDiv" style="visibility:hidden">
    <LABEL FOR="MakeModel">Eway #
    <INPUT TYPE="TEXT" class="d" ID="MakeModel" name="requiredeway1" size="6">
    </LABEL>
    </DIV>
    </td>

    </tr></table>
    </td></tr></table>

    </form>

    </BODY>
    </HTML>
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

    Comment

    Working...
    X