0
<table>
  <tbody id="eb_body">
    <tr>
      <td>Booking Bills:</td>
      <td><input type="text" id="e_brochure0" name="e_brochure0" placeholder="From           Bill No........" required/></td>

    </tr>
    <tr>
      <td>
        <a onClick="add_brochures()" style="text-decoration:none !important;"><span style="cursor:pointer; font-size:10px; ">+Add more bill nos.</span></a>
      </td>
    </tr>

    <tr>
      <td>
        <input type="submit" value="save" name="save" />
      </td>
    </tr>
  </tbody>
</table>

there is an anchor tag on that click i am calling a function as below..

<script type="text/javascript">
var b=1;
function add_brochures()
{
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {

            document.getElementById("zone").innerHTML=xmlhttp.responseText;
        }
    }

    xmlhttp.open("GET","five.php",true);
    xmlhttp.send();
    b=b+1;

}
</script>

with this i am directing the page to five.php where i am displaying a select box....

code for five.php is this...

<?php
include 'dbcon.php';
$sql="select * from tb_zone";
$query=mysql_query($sql);
?> 
<tr>
<td>

<select>
<?php
while($row=mysql_fetch_array($query))
    {
        ?>
        <option>
        <?php echo $row["zone_name"]; ?>
        </option>
        <?php } ?>
</select>

</td>
</tr>

when i click on anchor tag it is opening one selectbox but bot more....what i want is that when i click on anchor tag then a selectbox appears...if i click on it 5 times then i should open selectbox 5 times....right now it is opening just 1 selectbox....please help

4
  • see this link. It may help you mkyong.com/jquery/… Commented Jan 23, 2014 at 5:52
  • Since you're setting innerHTML, not concatenating it, it replaces the old contents. Use += instead of = if you want to append. Commented Jan 23, 2014 at 5:53
  • actaully i have to include php script on selectbox that is why i am using ajax Commented Jan 23, 2014 at 5:54
  • @barmer....where i have to make this change/? Commented Jan 23, 2014 at 5:54

1 Answer 1

1

Change:

document.getElementById("zone").innerHTML=xmlhttp.responseText;

to:

document.getElementById("zone").innerHTML += xmlhttp.responseText;

+= will concatenate the response to the existing HTML, which will add a new row to the table.

Sign up to request clarification or add additional context in comments.

6 Comments

what problem are you having?
sir actually it is displaying multiple selectboxes on anchor tag ...for eg i clicked on anchor and the selectbox gets displayed ...i choose some value...and when i click again on anchor tag to choose one more value then the value that i choose above gets blank...then again i have to choose...means when i clcik on anchor tag to open new selectbox the previous values gets vanished...?? what can be done for that/?
That's because you're rewriting the inner HTML of the table, so all the state is lost. It would be better if you created new elements, and added them with appendChild. I know how to do that with jQuery, I'm not sure how to do it with plain Javascript.
i want to insert all these values in database...so will it be possible with jquery??
Yes. jQuery is just a library that makes it easier to write Javascript.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.