[Javascript] select

David T. Lovering dlovering at gazos.com
Thu Mar 27 08:16:01 CST 2003


I am as confused as Chris, but a good programmer never lets ignorance stand in the way of generating code.

How about something like this --

<html>
<head>
  <title>myTest</title>
  <script language='JavaScript'>
  <!--
    var thisObject;
    function markCell(thisObject) {
      if (!thisObject) { return -1; }
      if (thisObject == '') { return -1; }
      var thisValue = document.myForm.mySelect.options[document.myForm.mySelect.selectedIndex].text;

      for (var i=0; i<document.myForm.mySelect.length; i++) {
        var nthValue = document.myForm.mySelect.options[i].text;
        if (nthValue == thisValue) {
          eval('document.myForm.' + nthValue + '.checked = \'true\'');
        } else {
          eval('document.myForm.' + nthValue + '.checked = \'false\'');
        }
      }
    }
  // -->
  <script>
</head>
  
<body>
<form name='myForm'>
  <select name='mySelect' onClick='markCell(this)'>
    <option>apple
    <option>banana
    <option>cherry
  </select>
  <table name='myTable'>
    <tr><td>apple</td><td><input name='apple' type='checkbox'></td></tr>
    <tr><td>banana</td><td><input name='banana' type='checkbox'></td></tr>
    <tr><td>cherry</td><td><input name='cherry' type='checkbox'></td></tr>
  </table>
</form>
</body>
</html>

In point of actual fact you don't have to pass the object to the 'markCell' routine;
I only did so to illustrate the fact that you can, as it may become necessary to
delineate which of several pulldowns you are dealing with in more sophisticated forms.

-- Dave Lovering

Chris Tifer wrote:
> 
> If I had a clear understanding of what you mean by "create a
> mark one of the cells in the table", I'd be willing to try to help.
> 
> Give us an idea on how a certain selection relates to a particular
> cell in the table and what a mark is.
> 
> Chris Tifer
> http://www.emailajoke.com
> 
> ----- Original Message -----
> From: "Kelly Zhu" <kzhu at tstc.edu>
> To: "[JavaScript List]" <javascript at LaTech.edu>
> Sent: Wednesday, March 26, 2003 5:10 PM
> Subject: [Javascript] select
> 
> > I would like to achieve the effect in javascript:  once I select an item
> in
> > the drop down list, create a mark one of the cells in the table.  Can
> > anybody offer help?  Thanks.
> >
> > Kelly
> >
> >
> > _______________________________________________
> > Javascript mailing list
> > Javascript at LaTech.edu
> > https://lists.LaTech.edu/mailman/listinfo/javascript
> >
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript


More information about the Javascript mailing list