Link to home
Start Free TrialLog in
Avatar of Genesis5150
Genesis5150

asked on

Trying to get input.className to work

I have a table that uses addRow() function. The className I'm trying to use is bootstrap v2.0 'input-small' but nothing shows when I add a row. I can input but I don't see the glowing border or anything for that matter. Also on the last cell I have a select dropdown menu that uses foreach function. When I add a row the dropdown menu is empty. How can I fix these two items?

Thanks

<script>
        function addRow() {
          var tbl = document.getElementById('addbeds');
          var lastRow = tbl.rows.length;
          var row = tbl.insertRow(lastRow);
          
          var cell1 = row.insertCell(0);
          var input = document.createElement('input');
          input.name = 'bedroom' + lastRow;
          input.className = 'input-small';
          input.id = 'bedroom' + lastRow;
          cell1.appendChild(input);
          
          var cell2 = row.insertCell(1);
          input = document.createElement('input');
          input.name = 'comment' + lastRow;
          input.className = 'input-medium';
          input.id = 'comment' + lastRow;
          cell2.appendChild(input);
		  
	  var cell3 = row.insertCell(2);
          input = document.createElement('select');
          input.name = 'bedsize' + lastRow;
	  input.className = 'input-medium' + lastRow;
          input.id = 'bedsize' + lastRow;
          cell3.appendChild(input);
        }
        
        function delRow() {
          var tbl = document.getElementById('addbeds');
          var lastRow = tbl.rows.length;
          if (lastRow > 2) tbl.deleteRow(lastRow - 1);
        }
    </script>

Open in new window


<table class="table" id="addbeds">
   <tbody>
     <tr>
       <td>
         <p align="center">Bedroom</p></td>
       <td>
         <p align="center">Comment</p></td>
       <td></td>
    </tr>
     <tr>
       <td>
        <input type='text' id='bedroom' name='bedroom' title='Please give this bedroom a name. ie Bedroom 1' maxlength='65,535' placeholder="Name this bedroom" class='input-small' value='<?php echo (isset($data['bedroom'])) ? $data['bedroom'] : '' ?>' data-toggle="tooltip" data-placement="right" /> </td>
       <td>
        <input type='text' id='comment' name='comment' title='Comment on this bedroom' maxlength='65,535' placeholder="What to find on this room." class='input-medium' value='<?php echo (isset($data['comment'])) ? $data['comment'] : '' ?>' data-toggle="tooltip" data-placement="right" /></td>
        <td>
          <select name="bedsize" title="bedsize" class="input-medium">
            <?php foreach($bedsize as $key => $value): ?>
            <option value="<?php echo $key ?>"<?php echo (isset($data['bedsize']) && $data['bedsize'] == $key) ? ' selected="selected"' : null ;?>><?php echo $value ?></option>
            <?php endforeach ?>
          </select></td>
    </tr>
  </tbody>
</table>
<table style="WIDTH: 100%; BORDER-COLLAPSE: collapse">
     <tr>
       <td>
       <p align="center">
          <input type="button" value="Add Row" onclick="addRow()" />
          <input type="button" value="Subtract Row" onclick="delRow()" />
       </p>
       </td>
    </tr>
</table>

Open in new window

Avatar of Genesis5150
Genesis5150

ASKER

Does anyone know?
Avatar of James Rodgers
this is what is showing up iun the added row

 <tr>
          <td><input name="bedroom2" class="input-small" id="bedroom2"></td>
          <td><input name="comment2" class="input-medium" id="comment2"></td>
          <td><select name="bedsize2" class="input-medium2" id="bedsize2">
            </select></td>
        </tr>

Open in new window


the only thing i see as an issue is you are appending the row number to the calss, giving you and invalid class name

try cahnging this block

var cell3 = row.insertCell(2);
          input = document.createElement('select');
          input.name = 'bedsize' + lastRow;
	  input.className = 'input-medium' + lastRow;
          input.id = 'bedsize' + lastRow;
          cell3.appendChild(input);

Open in new window

to this
var cell3 = row.insertCell(2);
          input = document.createElement('select');
          input.name = 'bedsize' + lastRow;
	  input.className = 'input-medium';
          input.id = 'bedsize' + lastRow;
          cell3.appendChild(input);

Open in new window



as for the select, give the full HTML from the page source so it can be tested

What browser are you using?
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Jquery worked for me.