10 Replies - 2677 Views - Last Post: 08 February 2012 - 12:30 PM

#1 Teymour  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-February 12

How to Change Cloned RadioButton's Name

Posted 08 February 2012 - 12:22 AM

Hi,

I cloned an html tablo with jQuery. And while clonning, jQuery also clonned radiobutton's name property and now i can just click one radiobutton when i try it with browser. How can i change name property for each clonned table?

<html>
<head>
<title> html table clonning</title>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>

<script type="text/javascript">
	$(document).ready(function() {
        });
	
	function clonetable () {
		$("#table1").clone().appendTo("#div1");
	}
</script>
</head>

<body>

	<input type="button" id="button1" name="clonner" value="clone table" onclick="clonetable()" />
	
	<br /><br />

	<div id="div1">
		<table border="1" id="table1">
		<tr>
			<td colspan="5">Question text will be here</td>
		</tr>
		<tr>
			<td><input type="radio" id="A" name="ans" />answer1 <br /></td>
			<td><input type="radio" id="B" name="ans" />answer2 <br /></td>
			<td><input type="radio" id="C" name="ans" />answer3 <br /></td>
			<td><input type="radio" id="D" name="ans" />answer4 <br /></td>
			<td><input type="radio" id="E" name="ans" />answer5 <br /></td>
		</tr>
		</table>
	</div>
	
</body>
</html>




Is This A Good Question/Topic? 0
  • +

Replies To: How to Change Cloned RadioButton's Name

#2 Teymour  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-February 12

Re: How to Change Cloned RadioButton's Name

Posted 08 February 2012 - 01:25 AM

*ps: and i also need to change the id of every clonned table :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: How to Change Cloned RadioButton's Name

Posted 08 February 2012 - 02:38 AM

there is a jQuery method (attr()) that lets you do that.
Was This Post Helpful? 1
  • +
  • -

#4 Teymour  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-February 12

Re: How to Change Cloned RadioButton's Name

Posted 08 February 2012 - 04:20 AM

View PostDormilich, on 08 February 2012 - 02:38 AM, said:

there is a jQuery method (attr()) that lets you do that.


thank you very much. it solves my problem (Y)
Was This Post Helpful? 0
  • +
  • -

#5 Teymour  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-February 12

Re: How to Change Cloned RadioButton's Name

Posted 08 February 2012 - 08:05 AM

View PostDormilich, on 08 February 2012 - 02:38 AM, said:

there is a jQuery method (attr()) that lets you do that.



Hi again,

i read the documentation in the link and i also know selectors. But i don't know how to select the clone table. Because, when i clone the table, the original one and the clone have the same id (table1). How can i select the clone table?
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: How to Change Cloned RadioButton's Name

Posted 08 February 2012 - 08:17 AM

$table = $("#table1").clone()?
Was This Post Helpful? 1
  • +
  • -

#7 Teymour  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-February 12

Re: How to Change Cloned RadioButton's Name

Posted 08 February 2012 - 11:34 AM

View PostDormilich, on 08 February 2012 - 08:17 AM, said:

$table = $("#table1").clone()?


Pardon me please, i'm new with Javascript and jQuery.
But, is this the way how to clone a table and change it's id?

$table = $("#table1").clone().attr("id", "newId").appendTo("#div1");

Was This Post Helpful? 0
  • +
  • -

#8 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: How to Change Cloned RadioButton's Name

Posted 08 February 2012 - 12:02 PM

in this case you wouldn’t need the assignment, though. but it looks sensible.
Was This Post Helpful? 0
  • +
  • -

#9 Teymour  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-February 12

Re: How to Change Cloned RadioButton's Name

Posted 08 February 2012 - 12:16 PM

View PostDormilich, on 08 February 2012 - 12:02 PM, said:

in this case you wouldn’t need the assignment, though. but it looks sensible.

I tried it, and it works without any problem, thank you very much :)

And i have one last question my friend, in the part of
attr("id", "newId")


instead of newId, can i call a javascript function, which checks previous table's id and, returns the string of next id according to order of table1, table2, table3, table4.. ?
Was This Post Helpful? 0
  • +
  • -

#10 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: How to Change Cloned RadioButton's Name

Posted 08 February 2012 - 12:18 PM

as you might have noted in the documentation, exactly this is possible.
Was This Post Helpful? 1
  • +
  • -

#11 Teymour  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-February 12

Re: How to Change Cloned RadioButton's Name

Posted 08 February 2012 - 12:30 PM

View PostDormilich, on 08 February 2012 - 12:18 PM, said:

as you might have noted in the documentation, exactly this is possible.

Upss.. I must have failed to remember that part of documentation. But anyway, thank you very much for your all helps again. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1