Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    add fields with click of button..input disappearing

    I have a form I am using to take a list of band members. It includes the member name and the instrument they play.


    my problem is I can enter the first set of info, and once I click the add another member button..the information I entered is removed, but, the new fields are added. I want to keep the information typed and also add a field.


    Code:
    <script language="Javascript" type="text/javascript"> 
    
    <?php
    
    //this script is to make sure that the session data is put back into the 
    //member fields if they are updated
    
    $memnum = 1;
    
    while ($_SESSION['member'.$memnum] != ""){
    	$memnum++;
    }
    if ($memnum >= 2){
    echo "var membernumber = " . $memnum;
    }
    else {
    	echo "var membernumber = 2;";
    }
    
    ?>
    
    function generateRow() {
    
    var d=document.getElementById("members_area");
    d.innerHTML+="<li>Name: <input name=member"+membernumber+" type='text' id=member"+membernumber+"> Instrument: <input name=instrument"+membernumber+" type='text' id=instrument"+membernumber+"></li>";
    
    }
    
    
    </script>


    html

    Code:
    <ol id ="members_area">
    
    <?php
    
    if ($_SESSION[member1] != ""){
    
    $i = 1;
    
    	while ($_SESSION['member'.$i] != ""){
    		echo "<li>Name: <input name=\"member" . $i . "\" type=\"text\" id=\"member" . $i . "\" value=\"" . $_SESSION['member'.$i] . "\" /> Instrument: <input name =\"instrument" . $i . "\" type=\"test\" id=\"instrument" . $i . "\" value=\"" . $_SESSION['instrument'.$i] . "\" ></li><br /> ";
    	$i++;
    	}
    }
    
    else {
    	echo "<li>Name: <input name=\"member1\" type=\"text\" id=\"member1\" /> Instrument: <input name=\"instrument1\" type=\"text\" id=\"instrument1\"></li>";
    }
    
    ?>
    
    	
    </ol>
    
    <div id="div"></div>
    <p><input type="button" value="Add Another Member" onclick="generateRow()"/></p>
    
    <br />
    <br />
    <input type="button" value="<< BACK"  onclick="window.location.href='http://www.somewhere.com/sign_up/final/signup1.php'">
    <input type="submit" name="submit" value="NEXT >>" />

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    If you are using method="post", try
    PHP Code:
    value="" htmlentities($_POST['member'.$i] ). "\" 
    (or else try with $_GET there)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry,

    I included the php because it was part of the code.

    The JAVA script is not working.


    Code:
    <script>
    var membernumber = 2;
    
    
    function generateRow() {
    
    var d=document.getElementById("members_area");
    d.innerHTML+="<li>Name: <input name=member"+membernumber+" type='text' id=member"+membernumber+"> Instrument: <input name=instrument"+membernumber+" type='text' id=instrument"+membernumber+"></li>";
    
    }
    
    </script>

    I open the page.

    I see 1 set of fields member name and instrument
    I type something into those fields.
    I hit add another member button

    the information I entered disappears...the new fields are added, but I have to go back and reenter the information.

    This is a javascript issue, I think.

    Can anyone help?

    thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •