www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 07-31-2006, 11:03 AM
    ChiPhiZD ChiPhiZD is offline
    Registered User
     
    Join Date: Jul 2006
    Posts: 7
    resolved [RESOLVED] JavaScript Button Option

    Hello all 1st Post, hopefully someone can shed some light on this one.
    I have a form that I would, for a few sections, to have a button that will prompt the user to how many "policy #'s" they are going to need to add to this form. I believe I need JavaScript for this form. So all this code below would be hidden until the user clicks on the button and answers how many needed to add. Also I would need to appened a _1, _2, _3 etc to the end of the names once they choose the amounts....

    If there is an easier lang to do it in please let me know as well...thanks in advance


    The following code is what I am working with:

    HTML Code:
    <div class="section">Section 4: Client Group or Policy Number Access</div>
    <br>
    
    <table border="1" width=100%>
    <th>Platform</th>
    <th>Policy Number or DIV/Group</th>
    <th>Customer Number / Master Group</th>
    <tr>
    <td><center><select name="policy_type1"><option Value=""selected>Select Policy Platform<option Value="ces">CES<option Value="prime">PRIME<option Value="cosmos">COSMOS</select></center></td>
    <td><center>Policy Numer or DIV/Group<input type="text" name="policy1"></center></td>
    <td><center>Customer Number / Master Group<input type="text" name="customer1"></center></td>
    </tr>
    </table>
    Reply With Quote
      #2  
    Old 07-31-2006, 11:17 AM
    Kor's Avatar
    Kor Kor is offline
    Red Devil Moderator
     
    Join Date: Dec 2003
    Location: Bucharest, ROMANIA
    Posts: 11,522
    In other words, you need to add dynamically new rows in a table?
    Reply With Quote
      #3  
    Old 07-31-2006, 11:27 AM
    ChiPhiZD ChiPhiZD is offline
    Registered User
     
    Join Date: Jul 2006
    Posts: 7
    I belive so, JScript is not my forte. So basically under that step there will be nothing but a button. Then once the users clicks the button, it will prompt for how many...

    If they choose 4, i want to have 4 copies of the same code i encluded but changing the names to like i said _1 , _2 etc...
    Reply With Quote
      #4  
    Old 07-31-2006, 11:45 AM
    Kor's Avatar
    Kor Kor is offline
    Red Devil Moderator
     
    Join Date: Dec 2003
    Location: Bucharest, ROMANIA
    Posts: 11,522
    I can make this code for you, but, please, give me a Private Message to remaind me to do this tomorrow. I must go home now (it's 19 PM for me, so I must leave the office), and I am not sure I will have enough time tonight. But tomorrow I have, for sure.
    Reply With Quote
      #5  
    Old 07-31-2006, 12:01 PM
    James Gatka James Gatka is offline
    Banned
     
    Join Date: Jan 2006
    Location: I'm in GMT -5
    Posts: 561
    - - - -

    Last edited by James Gatka; 07-31-2006 at 01:41 PM.
    Reply With Quote
      #6  
    Old 07-31-2006, 12:06 PM
    Kor's Avatar
    Kor Kor is offline
    Red Devil Moderator
     
    Join Date: Dec 2003
    Location: Bucharest, ROMANIA
    Posts: 11,522
    better use cloneNode(true) method, James. It will make the code much much shorter.
    Reply With Quote
      #7  
    Old 07-31-2006, 05:15 PM
    Kor's Avatar
    Kor Kor is offline
    Red Devil Moderator
     
    Join Date: Dec 2003
    Location: Bucharest, ROMANIA
    Posts: 11,522
    Quote:
    Originally Posted by James Gatka
    - - - -
    Why did u erased your code, James?... It was good. I just wanted to tell you that you might have use another method.
    Reply With Quote
      #8  
    Old 08-01-2006, 05:10 AM
    Kor's Avatar
    Kor Kor is offline
    Red Devil Moderator
     
    Join Date: Dec 2003
    Location: Bucharest, ROMANIA
    Posts: 11,522
    Here's your code. Is it Ok for you?
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    var clone;
    var tag =['select','input']
    function addRows(){
    var n = prompt('How Many?','input a number');
    var rows = document.getElementById('mytab').getElementsByTagName('tr');
    var root =rows[0].parentNode;
    for(var i=0;i<n;i++){
     for(var j=0;j<tag.length;j++){
     var el=clone.getElementsByTagName(tag[j]);
      for(var k=0;k<el.length;k++){
      el[k].name=el[k].name.replace(/\d/g,'')+rows.length;
    		}
     }
    root.appendChild(clone);
    clone=rows[rows.length-1].cloneNode(true)
    }
    }
    onload = function(){
    clone = document.getElementById('mytab').getElementsByTagName('tr')[1].cloneNode(true);
    }
    </script>
    
    </head>
    <body>
    <form>
    <table id="mytab" border="1" width=100%>
    <th>Platform</th>
    <th>Policy Number or DIV/Group</th>
    <th>Customer Number / Master Group</th>
    <tr>
    <td><center><select name="policy_type1"><option value="" selected>Select Policy Platform<option Value="ces">CES<option Value="prime">PRIME<option Value="cosmos">COSMOS</select></center></td>
    <td><center>Policy Numer or DIV/Group<input type="text" name="policy1"></center></td>
    <td><center>Customer Number / Master Group<input type="text" name="customer1"></center></td>
    </tr>
    </table>
    <br>
    <br>
    <input type="button" value="How many ?" onclick="addRows()">
    </form>
    </body>
    </html>
    Reply With Quote
      #9  
    Old 08-01-2006, 01:12 PM
    ChiPhiZD ChiPhiZD is offline
    Registered User
     
    Join Date: Jul 2006
    Posts: 7
    resolved

    Awesome...
    Thanks...
    U Da Man....

    I can reuse this on other part of the form....

    Was getting so fustrated with my code not working and i see where i goofed...thanks a ton!!!!

    Reply With Quote
      #10  
    Old 08-01-2006, 04:45 PM
    Kor's Avatar
    Kor Kor is offline
    Red Devil Moderator
     
    Join Date: Dec 2003
    Location: Bucharest, ROMANIA
    Posts: 11,522
    Quote:
    Originally Posted by ChiPhiZD
    Awesome...
    Thanks...
    U Da Man....

    I can reuse this on other part of the form....

    Was getting so fustrated with my code not working and i see where i goofed...thanks a ton!!!!

    I guess it was the part whch supposes to re-name the form elements. I agree it's the most important... ok, now, I am glad I was of any help for u
    Reply With Quote
      #11  
    Old 08-01-2006, 07:02 PM
    ChiPhiZD ChiPhiZD is offline
    Registered User
     
    Join Date: Jul 2006
    Posts: 7
    yes tons....running a script on the form now...and everything is working great...you helped a ton...

    THANKS AGAIN!
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    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 Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 02:00 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.