why this won't appear? need help please..

Discussion in 'JavaScript' started by s.jns, Jan 23, 2011.

  1. #1
    Hi,
    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>
    
    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.");
            }
        },
    };
    Code (markup):
    perhaps it does not appear because the php code
    but when previously I was using this code work fine
              <table id="add_friends">
                <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>
    
    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);
    }
    Code (markup):
    or is there possible to change code on top to the underlying code? or is there another better opinion? thanks in advance
     
    s.jns, Jan 23, 2011 IP
  2. domainwink

    domainwink Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Install firebug on your firefox and see what happens. Or you may also try <?php print_r($emails); ?> to make sure the $emails variable has contents into it.
     
    domainwink, Jan 23, 2011 IP
  3. hdewantara

    hdewantara Well-Known Member

    Messages:
    538
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #3
    Perhaps...

    Your 2nd script (the original) let your server to interpret PHP codes first into a HTTP response (a jumble of HTML, javascript, CSS codes) and be sent to a client's browser.

    The 1st script on the other hand, creates PHP codes (on-the-fly, using javascript) after the HTTP response has been created and sent to a browser. No browser understands PHP.
     
    hdewantara, Jan 24, 2011 IP
  4. s.jns

    s.jns Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    @ hdewantara,
    nice comment, then do you have an idea to make my 1st work with a samples please? I appreciate it and thanks.
     
    s.jns, Jan 26, 2011 IP
  5. hdewantara

    hdewantara Well-Known Member

    Messages:
    538
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #5
    Sorry, it's too vague for me.
    Let us know more details, or a link...

    But I suspect your new addInput() couldn't detect #new_input div,
    i.e. you've called this function too early before DOM ?
     
    Last edited: Jan 26, 2011
    hdewantara, Jan 26, 2011 IP