0

I use a css style for personal information cards.

For example:

<strong>Name: </strong><p>Bla Bla</p>
<h1>Contact Info</h1>
<p>E-mail: blablabla</p>

Now I want to do this with PHP. I've designed my code and template for this. When you fill two textboxes (name, e-mail) and click the button, it gives me the HTML code.

But some people has more than one e-mail. So I've to add second (3rd, 4th) textbox for them. How can I do this without losing the old textbox datas?

Name: filled E-mail: filled

I need to enter another e-mail so lets click this button for another textbox.

Boom

Name: empty E-mail: empty Email2: empty

How to prevent that?

Degauser
  • 120
  • 1
  • 2
  • 9

2 Answers2

0

I believe it would be beneficial for everybody if you could post snippet of the code you attempted.

Anyway I have to admit I don't really understand what exactly you're trying to achieve but you may want to check out the variable passing in php PHP variable passing

Community
  • 1
  • 1
TomasH
  • 148
  • 1
  • 7
  • Actually, it's like ASP.NET postback. For example, you're filling a form. Selected your country from dropdownlist and page refreshed for getting cities of your country. But still, browser keeps your previous entries because of autopostback. I'm trying to do something like this in PHP. Fill your data, ask for another textbox, textbox comes with page refresh but your data is still there. Simply, bring another textbox to the page without losing previous ones data. – Degauser Jul 21 '14 at 18:58
  • Sorry - I'm not familiar with ASP.NET, but generally you seem to be interested in dynamically re-drawing the page based on the checkbox / other control element being clicked / selected. There are many sources on the Internet, you can pick pretty much any. I would suggest you give this: http://www.w3schools.com/ajax/default.asp a look though. – TomasH Jul 21 '14 at 19:03
  • I've heard about it but was not sure if it works for me. Thanks for this suggestion. – Degauser Jul 21 '14 at 19:05
0

If I understodd.

To do this has two ways:

1) do in Jquery.

<html>
<head>
<title>jQuery add / remove textbox example</title>

<script type="text/javascript" src="jquery-1.3.2.min.js"></script>

<style type="text/css">
    div{
        padding:8px;
    }
</style>

</head>

<body>

<h1>jQuery add / remove textbox example</h1>

<script type="text/javascript">

$(document).ready(function(){

    var counter = 2;

    $("#addButton").click(function () {

    if(counter>10){
            alert("Only 10 textboxes allow");
            return false;
    }   

    var newTextBoxDiv = $(document.createElement('div'))
         .attr("id", 'TextBoxDiv' + counter);

    newTextBoxDiv.after().html('<label>Textbox #'+ counter + ' : </label>' +
          '<input type="text" name="textbox' + counter + 
          '" id="textbox' + counter + '" value="" >');

    newTextBoxDiv.appendTo("#TextBoxesGroup");


    counter++;
     });

     $("#removeButton").click(function () {
    if(counter==1){
          alert("No more textbox to remove");
          return false;
       }   

    counter--;

        $("#TextBoxDiv" + counter).remove();

     });

     $("#getButtonValue").click(function () {

    var msg = '';
    for(i=1; i<counter; i++){
      msg += "\n Textbox #" + i + " : " + $('#textbox' + i).val();
    }
          alert(msg);
     });
  });
</script>
</head><body>

<div id='TextBoxesGroup'>
    <div id="TextBoxDiv1">
        <label>Textbox #1 : </label><input type='textbox' id='textbox1' >
    </div>
</div>
<input type='button' value='Add Button' id='addButton'>
<input type='button' value='Remove Button' id='removeButton'>
<input type='button' value='Get TextBox Value' id='getButtonValue'>

</body>
</html>

2) in PHP using Session

Store variable in a Session after you submit your form

ivanfromer
  • 329
  • 1
  • 5
  • Thanks for your answer. I'm not familiar with jQuery. Will this code store data in previous textboxes? – Degauser Jul 21 '14 at 18:55