Jump to content

Get Multiple Data From Append Jquery


Petani

Recommended Posts

hi friends, im trying a case, n i have problem on it,

 

im gonna input multiple data , here sample my form html:

<div id="form_name">
<select id="name_emp">
 <option value="1234">joko</option>
 <option value="9900">Rudi</option>
<option value="7786">anto</option>
</select>
<div id="id_emp">
</div>
</div>

<button id="addBtn">Add Name</button>

 

n i want, for example, a user can show that select elemen above more than 1, so i create jquery code below:

$("#addBtn").click(function()
{
 $("#form_name").append('<select id="name_emp"><option value="1234">joko</option><option value="9900">Rudi</option>	 <option value="7786">anto</option>
 </select>
 <div id="id_emp">
 </div>');
});

 

so, if a user click Add Name button, the select elemen wil show again.

 

after a user choose from select elemen, i want jquery show the ID, example, if i choose joko, ID will show 1234 n so forth.

so i create jquery code below:

$('#name_emp').change(function()
{
var ID = $("#name_emp").val();
$('#id_emp').html(ID);
});

 

it works when i choose the name n the ID is out between <div id="id_emp"></div> at first time, but, when i click Add Name button to show again the select elemen, n i choose employee name, the ID is not out,that's my problem friends, can you help me?

 

thanks before....

Link to comment
Share on other sites

You're reusing the ID? You can't do that. If you want to reset it, just select the option yourself in JS rather than rewrite it. You can also clear the HTML of the div if you want it gone instead of rewriting it.

 

I could be way off, if so I'm sorry. I don't really understand what you're saying.

Link to comment
Share on other sites

okay, sorrt for that, this is my code friend,

 

<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function()
{
$("#addBtn").click(function()
{
 $("#form_name").append('<select id="name_emp"><option value="1234">joko</option><option value="9900">Rudi</option><option value="7786">anto</option></select><div id="id_emp"></div>');
});
$('#name_emp').change(function()
{
  var ID = $("#name_emp").val();
  $('#id_emp').html(ID);
});
});
</script>
</head>
<body>
<div id="form_name">
<select id="name_emp">
 <option value="1234">joko</option>
 <option value="9900">Rudi</option>
 <option value="7786">anto</option>
</select>
<div id="id_emp">
</div>
</div>
<button id="addBtn">Add Name</button>
</body>
</html>

 

- when i select employee's name, the ID's employee is out,

-after that, i click Add Name button to display that select element again, so that i could choose more employee..

-then i choose the employee's name again, but ID's employee is not out

that's my problem friends,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.