Concatenation In Javascript

Guru Ji
Guru Ji used Ask the Experts™
on

I have a Function below

function see(sel,sel2)
{
      //alert(sel[sel.selectedIndex].text);
      alert(sel);
      alert(sel2);
      if (cell.selectedIndex > 0 )
      {      
            sel.originalcolor=sel.style.backgroundColor; sel.style.backgroundColor='#CCFFCC'
            sel2.originalcolor=sel2.style.backgroundColor; sel2.style.backgroundColor='#CCFFCC'
      }
      if (cell.selectedIndex == 0 )
      {      
            sel.originalcolor=sel.style.backgroundColor; sel.style.backgroundColor='#ECE9D8'
            sel2.originalcolor=sel2.style.backgroundColor; sel2.style.backgroundColor='#ECE9D8'

      }      
}

sel And sel2 are the id's of the table cell

I am calling this Function like this below

onchange="see('source','source2')"

How I make it To work To it accept source And source1 And use it instead of sel And sel2. I don't want to create more functions as I want to use one and pass different id's when calling the function
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
where is the onchange called? Can you put the complete code atleast the flow

Author

Commented:
<select onchange="see('source','source1')" size="1" class="style16" style="width: 197px" type="text" / size="20" name="num">
                  <option value="Please Choose">Please Choose</option>
              <option>1</option>
              <option>2</option>
              <option>3</option>
              <option>4</option>
              <option>5</option>
              <option>6</option>
            </select>

Author

Commented:
actually here is the full code with id's too

        <td id="source" style="width: 89px; height: 26px"><strong><span class="style8">Source:</span></strong></td>
        <td id="source1" style="width: 197px; height: 26px">
        <select onchange="see('source','source1')" size="1" class="style16" style="width: 197px" type="text" / size="20" name="num">
                  <option value="Please Choose">Please Choose</option>
              <option>1</option>
              <option>2</option>
              <option>3</option>
              <option>4</option>
              <option>5</option>
              <option>6</option>
            </select>
Commented:
Hope you are trying to do this. Try this code:

<html>
      <head>
            <title>Script Demo Gops</title>
            <script language="javascript">
                  function see(sel,sel2){
                        //alert(sel[sel.selectedIndex].text);
                        alert(sel);
                        alert(sel2);
                        var cell=document.forms['temp'].elements['num'];
                        alert(cell.selectedIndex);
                        if (cell.selectedIndex > 0 ){
                              document.getElementById(sel).style.backgroundColor='#CCFFCC'
                              document.getElementById(sel2).style.backgroundColor='#CCFFCC'
                        }
                        if (cell.selectedIndex == 0 ){
                              document.getElementById(sel).style.backgroundColor='#ECE9D8'
                              document.getElementById(sel2).style.backgroundColor='#ECE9D8'
                        }
                  }
            </script>
      </head>
<body>
<table>
      <form name="temp">
      <tr>
            <td id="source" style="width: 89px; height: 26px"><strong><span class="style8">Source:</span></strong></td>
            <td id="source1" style="width: 197px; height: 26px">
            <select id="select" onchange="see('source','source1')" size="1" class="style16" style="width: 197px" name="num">
            <option value="Please Choose">Please Choose</option>
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
            <option>6</option>
            </select>
            </td>
      </tr>
      </form>
</table>
</body>
</html>

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial