I am creating a small troubleshooting guide which is created in Jquery and HTML. When user selects a step this is designed to give next step to try and from there next one in a flow chart style.
I wanted to add a selection button so that once user completed a flow of troubleshooting they should be able to copy all selected items to a text box automatically. Can anyone help me with a code which will select all user selected items from the flow and paste / populate them into a text box.
Please find the code I used for the troubleshooting guide. Any help will highly appreciated.. Thanks in advance..
$('document').ready(function(){
var count = 0;
$('#questions').hide();
$('#answers').hide();
$('#questions tr:nth-child(2)').attr('id','currow');
var q1 = $('#currow td:nth-child(2)').html();
var q3 = '<div id="d' + count + '"><p>' + q1 + '</p>' ;
var a1 = $('#currow td:nth-child(3)').html();
var r1 = q3 + a1 +'</div>';
$('#showquestion').html(r1);
$('li').live('click',function(){
$(this).addClass('selected').siblings().removeClass('selected');
var target = $(this).attr('id');
var parid = $(this).parent().parent().attr('id');
var parnum = parseInt(parid.slice(1,3));
count = count + 1;
var ps = $('#showquestion div').length;
$('#showquestion div').each(function() {
var divid = $(this).attr('id');
var divnum = parseInt(divid.slice(1,3));
if(divnum > parnum)
$(this).remove()
})
$('td' ).each(function(){
var qnum = $(this).text();
if(qnum == target) {
var q = $(this).next('td').html();
var q2 = '<div id="d' + count + ' "><p>' + q + '</p>';
var a = $(this).next('td').next('td').html();
var qs = $('#showquestion').html();
var r = qs + q2 + a +'</div>';
$('#showquestion').html(r);
window.scrollBy(0,400);
}
})
})
})
<div class="luiTitle"><a href="http://google.com" style=" text-decoration:none; color:#bbb">Support System </a></div>
<div id="showquestion" class="answers"></div>
<p><a href="TEST1.HTML"title="To my second webpage">Click here to go back to Selection Page</a></p>
<table width="50%" border="0" cellspacing="1" cellpadding="2" id="questions" >
<tr>
<td>No</td>
<td>Question/Heading </td>
<td>Answers </td>
</tr>
<tr>
<td>1</td>
<td>Question 1</td>
<td>&l开发者_运维问答t;ul>
<li id="2">Option 1</li>
<li id="3">Option 2</li>
<li id="4">Option 3</li>
</ul></td>
</tr>
<tr>
<td>2</td>
<td>Level 2 - from question 1 Option 1</td>
<td><ul>
<li id="5">Option 1</li>
<li id="6">Option 2</li>
</ul></td>
</tr>
<tr>
<td>3</td>
<td>Level 2 - from question 1 - no</td>
<td><ul>
<li id="9">Option 1</li>
<li id="10">Option 2</li>
<li id="6">Option 3</li>
<li id="7">Option 4</li>
</ul></td>
</tr>
<tr>
<td>4</td>
<td>Level 3 - from level 2 option 1</td>
<td><ul>
<li id="11">Option 1</li>
<li id="12">Option 2</li>
<li id="13">Option 3</li>
<li id="13">Option 4</li>
</ul></td>
</tr>
document
is an object, when you say $('document')
, jQuery will try to look for document
tag on the page. Change that to $(document).ready()
and try it.
var parid = $(this).parent().parent().attr('id');
in this line this
points to li
element and parent
of parent
will give a td
which do not have any id, so parid
will always be null or empty.
精彩评论