user485783
user485783

Reputation: 1685

display the new field doesn't appear

I wondering if some one could help me, in my code below can not display the new field, if anyone can help or guidance I would be grateful

<!-- // another fields here //-->  
<div id="new_field"--></div>
<script type="text/javascript">
var inputs = {
    fields: 0,
    target: "new_field",
    addInput: function() {
        if (this.fields != 5) {
            this.fields++;
            var newElement = document.createElement('div');
            newElement.id = this.target + this.fields;
            newElement.innerHTML = "<?php if ($emails) { foreach ($emails as $result) { ?><b><?php echo $entry_emails; ?></b><br /><input type='text' name='emails[]' value='<?php echo $result; ?>' size='auto' maxlength='100%' /><?php } } ?>";
            document.getElementById(this.target).appendChild(newElement);
        } else {
            alert("Only 5 fields allowed.");
        }
    },
};</script>

perhaps it does not appear because the php code

newElement.innerHTML = "<?php if ($emails) { foreach ($emails as $result) { ?><b><?php echo $entry_emails; ?></b><br /><input type='text' name='emails[]' value='<?php echo $result; ?' size='auto' maxlength='100%' /><?php } } ?>";

then when previously I was using this code work fine

          <table id="add_friends">
<!-- // another fields here //-->
            <tr>
              <td><b><?php echo $entry_email; ?></b></td>
              <td>
              </td>
            </tr>
   <?php if ($emails) { foreach ($emails as $result) { ?>
            <tr>
              <td><b><?php echo $entry_emails; ?></b></td>
              <td><input type="text" name="emails[]" value="<?php echo $result; ?>" /></td>
            </tr>
   <?php } } ?>
          </table>

<script type="text/javascript">
function addFriend() {
 var tbl = document.getElementById('add_friends');
 var iteration = tbl.tBodies[0].rows.length;
 newRow = tbl.tBodies[0].insertRow(-1);
 var newCell = newRow.insertCell(0);
 newCell.innerHTML = 'Entry Your friend email';
 var newCell1 = newRow.insertCell(1);
 var el = document.createElement('input');
 el.type = 'text';
 el.name = 'emails[]';
 el.size = 30;
 el.maxlength = 45;
 newCell1.appendChild(el);
}</script>

or is there possible to change code on top to the underlying code? or is there another better opinion?

Upvotes: 0

Views: 89

Answers (1)

Anonymous
Anonymous

Reputation:

The only reason your code isn't working is because of the PHP code. PHP is not processed on the client side by the client, it is processed on the server side by the server.

Upvotes: 1

Related Questions