Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
how ti limit the additions field?
Old 10-30-2010, 12:37 PM how ti limit the additions field?
Average Talker

Posts: 24
Trades: 0
Hi,

If someone here is willing to help me I would really appreciate
how to limit the addition of columns in the following html code, let say only up to 5 only?
PHP Code:
      <form action="<?php echo $action?>" method="post" enctype="multipart/form-data" id="friends"
          <table width="100%" cellpadding="10" cellspacing="0" id="my_friends">
            <tr>
              <th colspan="2" style="text-align: center;"><?php echo $text_enter_friend?></th>
            </tr>
            <tr>
              <td class="left" width="30%"><span class="required">*</span> <?php echo $entry_friend?></td>
              <td class="left"><input type="text" name="friend" value="<?php echo $friend?>" size="30" maxlength="45" />
                <?php if ($error_friend) { ?>
                <span class="error"><?php echo $error_friend?></span>
                <?php ?></td>
            </tr>
            <?php if ($friends) { ?>
            <?php foreach ($friends as $result) { ?>
            <tr>
              <td style="vertical-align: top;"><?php echo $entry_friend?></td>
              <td style="vertical-align: top;"><input type="text" name="friends[]" value="<?php echo $result?>" size="30" maxlength="45" /></td>
            </tr>
            <?php ?>
            <?php ?>
          </table>
          <table width="100%" cellpadding="10" cellspacing="0">
            <tr>
              <td></td>
              <td class="right"><a onclick="addFriend();" class="button"><span><?php echo $button_add_friend?></span></a><a onclick="removeFriend();" class="button"><span><?php echo $button_remove?></span></a></td>
            </tr>
            <tr>
              <td colspan="2" class="center">
                <p><?php echo $text_message?></p>
                <p><a onclick="$('#friends').submit();" class="button"><span><?php echo $button_submit?></span></a></p>
                <p><?php echo $text_addresses?></p>
              </td>
            </tr>
          </table>
        </div>
      </form>
Code:
<script type="text/javascript"><!--
function addFriend() {
	var tbl = document.getElementById('my_friends');
	var iteration = tbl.tBodies[0].rows.length;
	newRow = tbl.tBodies[0].insertRow(-1);
	var newCell = newRow.insertCell(0);
	newCell.innerHTML = '<?php echo $entry_friend; ?>';
	var newCell1 = newRow.insertCell(1);
	var el = document.createElement('input');
	el.type = 'text';
	el.name = 'friends[]';
	el.size = 30;
	el.maxlength = 45;
	newCell1.appendChild(el);
//	if (newCell > 2) tbl.addCell(newCell + 1);
}

function removeFriend() {
	var tbl = document.getElementById('my_friends');
	var lastRow = tbl.rows.length;
	if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}
//--></script>
Thanks in advance
jones is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to how ti limit the additions field?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11791 seconds with 12 queries