jquery write html into variable - php

i am writing two list application where data from one list can be shifted to other list.
i am using DIV like this
<div id="all_users">
<div id="user1" userid="1" class="innertxt"> <img src="images/images.jpg" width="50" height="50"><strong>Test User 01</strong>
<ul>
<li>User ID: 1</li>
<li>Email: user1#nodomain.com</li>
<li style="padding-top:5px;">
<input type="checkbox" id="select1" value="1" class="selectit" />
<label for="select1"> Select it.</label>
</li>
</ul>
</div>
<div id="user2" userid="2" class="innertxt"> <img src="images/images.jpg" width="50" height="50"><strong>Test User 02</strong>
<ul>
<li>User ID: 2</li>
<li>Email: user2#nodomain.com</li>
<li style="padding-top:5px;">
<input type="checkbox" id="select2" value="2" class="selectit" />
<label for="select2"> Select it.</label>
</li>
</ul>
</div>
<div class="float_break"></div>
</div>
for removing data from div i use following script
$("#move_new").click(function() {
$('#all_users .innertxt').each(function() {
$(this).remove();
});
});
now what i need is:
add new data into DIV.
i try following code
$('#all_users').append(new_data_var);
where new_data_var is variable which contain following HTML value
<div class="innertxt" userid="1" id="user1"> <img height="50" width="50" src="images/images.jpg"><strong>Test User 01</strong>
<ul>
<li>User ID: 1</li>
<li>Email: user1#nodomain.com</li>
<li style="padding-top: 5px;">
<input type="checkbox" class="selectit" value="1" id="select1">
<label for="select1"> Select it.</label>
</li>
</ul>
</div>
i want to figure out how can i store above HTML value into new_data_var ?
second if my values are coming from MYSQL & PHP how can i use this in loop to add more values.
Thanks

To store HTML-code to a variable, you could use this:
var new_data_var = $('<div class="innertxt" userid="1" id="user1"> <img height="50" width="50" src="images/images.jpg"><strong>Test User 01</strong><ul><li>User ID: 1</li> <li>Email: user1#nodomain.com</li><li style="padding-top: 5px;"><input type="checkbox" class="selectit" value="1" id="select1"><label for="select1"> Select it.</label></li></ul></div>');
$('#all_users').append(new_data_var);

Try wrapping your code in jquery set call:
$('#all_users').append( $(new_data_var) );

Same as the others suggested really, I recommend using jQuery to build your HTML prior to appending it, this is a minimalist version but you could generate the lot in a similar manner.
var new_data_var = $('div', {'id': 'user1', class: 'innertxt'}).html('
<img height="50" width="50" src="images/images.jpg"><strong>Test User 01</strong>
<ul>
<li>User ID: 1</li>
<li>Email: user1#nodomain.com</li>
<li style="padding-top: 5px;">
<input type="checkbox" class="selectit" value="1" id="select1">
<label for="select1"> Select it.</label>
</li>
</ul>
);

Related

How can I dynamically fetch data in Tabs and Pills using their IDs? Using PHP & Codeigniter

I am creating a module for Question and Answers and I need to fetch the data separatedly each.
I created a Tab where I'll click the Question I want to answers, and its children or the answer should match.
For visual reference, here is my problem
I have this data that are all fetched, which should not be. That is why I created Tabs and Pills so I can separate questions and answers
12 and 13 are the id number of each data
So in Tabs and Pills, I got this
The problem of this, is that I cannot fetch the data dynamically, it just shows ID 13 data for question and answer. How can I change this dynamically so I can click back and forth the tabs and show the right data by its id?
I need to fetch the ID 12 of the 1st Tab
So here is my view
<ul class="nav nav-tabs" role="tablist">
<?php foreach($questions as $question){ ?>
<?php echo $question->id; ?>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#<?php echo $question->id ?>" role="tab"><h4><?php echo $question->question ?></h4></a>
</li>
<?php } ?>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane" id="13" role="tabpanel">
<div class="card" style="border:2px solid black;">
<div class="card-body">
<?php foreach($this->question_model->findAnswersByQuestion($question->id) as $answer){ ?>
<?php if($answer->type_id==0): ?>
<input type="radio" name="question_<?php echo $question->id; ?>" value="<?php echo $answer->answer ?>" required/>
<?php echo $answer->answer; ?><hr>
<?php endif; ?>
<?php if($answer->type_id==1): ?>
<div class="input-group input-group-lg">
<input type="text" class="form-control col-md-6" placeholder="Enter Answer" name="question_<?php echo $question->id; ?>" required/>
</div>
<?php endif; ?>
<?php } ?>
</div>
</div><br>
</div>
</div>
Fix the tabs structure, your looping over questions for nav-item, but not looping over for tab-pane which is why clicking the tab link does nothing.
<ul class="nav nav-tabs" role="tablist">
<?php foreach($questions as $question){ ?>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab-<?php echo $question->id ?>" role="tab"><h4><?php echo $question->question ?></h4></a>
</li>
<?php } ?>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<?php foreach($questions as $question){ ?>
<div class="tab-pane" id="tab-<?= $question->id ?>" role="tabpanel">
<div class="card" style="border:2px solid black;">
<div class="card-body">
<?php foreach($this->question_model->findAnswersByQuestion($question->id) as $answer){ ?>
<!-- form input $answer / item -->
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</div>

Show 1 Cell of data as list in laravel

i have database table 'jobs' where there`s description and requirement column.
Each description and column can have several value in the cell separated by an "enter"
how can i show the data in laravel blade as a lists?
This is my blade
<ul class="lst">
<li class="it">
<input class="ipt-hidden" name="tabs-1" type="radio" id="tab1" checked>
<label class="title twomenu" for="tab1">JOB DESCRIPTIONS</label>
<div class="wrp-content">
<ul class="show-item">
<li>{{ $jobs->description }}</li>
</ul>
</div>
</li>
<li class="it">
<input class="ipt-hidden" name="tabs-1" type="radio" id="tab2">
<label class="title twomenu" for="tab2">REQUIREMENTS</label>
<div class="wrp-content">
<ul class="show-item">
<li>{{ $jobs->requirement }}</li>
</ul>
</div>
</li>
</ul>
What i want is the jobs requirements & descriptions can show as several list, can i do that?
because what i get is just 1 list separated by spacing.
Thankyou all :)

Select option from dropdown with selenium and php webdriver from facebook

I'm trying to put together a script with PHP facebook/webdriver 1.4.1 and selenium 3.5 that will automate the task of giving online orders to our selected transport company (TNT) because they do not provide any rest api to fulfill this function and it is really tedious do it every singel time by hand.
My script works fine except for the Selectboxes, that are jscript generated with a bunch of <ul> and <li>, and I can not select the desired values.
This is an example of the select
<td>
<select id="latestCollectionTime" name="latestCollectionTime" style="display: none;">
<option value="" selected="selected">
selecteer...
</option>
<option value="2230">
22:30
</option>
<option value="2245">
22:45
</option>
<option value="2300">
23:00
</option>
<option value="2315">
23:15
</option>
<option value="2330">
23:30
</option>
<option value="2345">
23:45
</option>
</select>
<span id="latestCollectionTime-dropdown" class="selectboxit-container">
<span id="latestCollectionTimeSelectBoxIt" class="selectboxit dropdown-menu" style="" name="latestCollectionTime" tabindex="0" unselectable="on" role="combobox" aria-autocomplete="list" aria-expanded="false"
aria-owns="latestCollectionTimeSelectBoxItOptions" aria-activedescendant="0" aria-label="" aria-live="assertive">
<i id="latestCollectionTimeSelectBoxItDefaultIcon" class="selectboxit-default-icon selectboxit-option-icon" unselectable="on" style="margin-top: 5.5px;">
</i>
<span id="latestCollectionTimeSelectBoxItText" class="selectboxit-text" unselectable="on" data-val="" style="line-height: 22px; max-width: 88px;">
selecteer...
</span>
<span id="latestCollectionTimeSelectBoxItArrowContainer" class="selectboxit-arrow-container" unselectable="on" style="height: 22px;">
<i id="latestCollectionTimeSelectBoxItArrow" class="selectboxit-arrow caret" unselectable="on" style="margin-top: 7px;">
</i>
</span>
</span>
<ul id="latestCollectionTimeSelectBoxItOptions" class="selectboxit-options" tabindex="-1" role="listbox" aria-hidden="true" style="max-height: 198px; top: auto; display: none;">
<li id="0" data-val="" data-disabled="false" class="selectboxit-option selectboxit-option-first" style="" role="option">
<a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>selecteer...</a>
</li>
<li id="1" data-val="2230" data-disabled="false" class="selectboxit-option" style="" role="option">
<a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>22:30</a>
</li>
<li id="2" data-val="2245" data-disabled="false" class="selectboxit-option" style="" role="option">
<a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>22:45</a>
</li>
<li id="3" data-val="2300" data-disabled="false" class="selectboxit-option" style="" role="option">
<a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>23:00</a>
</li>
<li id="4" data-val="2315" data-disabled="false" class="selectboxit-option" style="" role="option">
<a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>23:15</a>
</li>
<li id="5" data-val="2330" data-disabled="false" class="selectboxit-option" style="" role="option">
<a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>23:30</a>
</li>
<li id="6" data-val="2345" data-disabled="false" class="selectboxit-option selectboxit-option-last" style="" role="option">
<a class="selectboxit-option-anchor"><i class="selectboxit-option-icon " style="margin-top: 3.5px;"></i>23:45</a>
</li>
</ul>
</span>
</td>
The <li> id is automatic generated, and duplicated in other selectboxes in the page, so i can't $driver->findElement(WebDriverBy::id('6'))->click();.
I can't select the normal way.
$driver->findElement( WebDriverBy::id('latestCollectionTime') )
->findElement( WebDriverBy::cssSelector("option[value='11']") )
->click();
because the select is hidden style="display: none; and neither with the xpath.
I would like to be able to directly select a value like data-val="2330" but taking in consideration that are other 3 selectboxes with the same <li> ids and data-val values, but with diferent <span> and <ul> ids .
Can anyone help me with this?
Thanks in advance.
EDIT:
I finish using it like this:
//make the dropdow list visible.
$driver->findElement(WebDriverBy::id('latestCollectionTimeSelectBoxIt'))->click();
// to click in the desired option.
$driver->findElement(WebDriverBy::xPath('//*[#id = "latestCollectionTimeSelectBoxItOptions"]/li[#data-val = "'.$desired_value.'"]'))->click();
Thanks again to #DAN in the answer below for pointing me in the right direction with the xPath sintax.
Firstly, elements with duplicate ids are not valid HTML, and it is up to each browser to determine what they will do with the illegal page elements. As far as I know, most browsers will allow multiple DOM elements with duplicate IDs, but this may change in the future.
Secondly, you can select the element you're interested in via XPath. For example, the XPath (//*[#id = 'someID'])[1] selects the first element with an id of someID.
However, as you mentioned that the <ul> elements have different IDs, you can use XPath such as //ul[#id = 'latestCollectionTimeSelectBoxItOptions']/li[#data-val = '2230'] to select the element.
Finally, you mention that the list items are not clickable because they are hidden, presumably because they're part of a dropdown menu.
In this case, you need to firstly click on the dropdown to open it, then find and click on the appropriate list item.
Hope this helps.
You only have to click on the option you want to choose.
I am using xpath for that because i want to access the option from the given select box.
$optionFromSelectBox = $driver->findElement(
WebDriverBy::xpath(
'//select[#id=\'latestCollectionTimeSe‌​lectBoxIt\']//option[2]'
)
);
$optionFromSelectBox->click();

Find whether checkbox is checked in php

This question has been asked before but i used the same thing as said in the answer to the question but it is not working
My form:
$home=
"<div class='heading' >
<p><b>EHD HOME AUTOMATION</b></p>
</div>
<div class='menu-wrap'>
<nav class='menu'>
<ul class='clearfix'>
<li><a href='./member.php'>$username's Home</a></li>
<li>
<a href='#'>States <span class='arrow'>▼</span></a>
<ul class='sub-menu'>
<li><a href='#' onclick='changeAllStatesToFalse();'>ALL APPLIANCES OFF</a></li>
<li><a href='#' onclick='changeAllStatesToTrue();'>ALL APPLIANCES ON</a></li>
<li><a href='#' onclick='getStates();'>GET STATES</a></li>
</ul>
</li>
<li><a href='#'>Security</a></li>
<li><a href='#'>Page info</a></li>
<li><a href='./logout.php'>Logout</a></li>
</ul>
</nav>
</div>
<!3 Toggle Buttons start>
<div class='buttonsArea'>
<div class='display'>
<label class='label toggle'>
Appliance 1
<input type='checkbox' class='toggle_input' id='button1' name='A1'/>
<div class='toggle-control'></div>
</label>
</div>
<div class='display'>
<label class='label toggle'>
Appliance 2
<input type='checkbox' class='toggle_input' id='button2' onclick='updateTable(2);'/>
<div class='toggle-control'></div>
</label>
</div>
<div class='display'>
<label class='label toggle'>
Appliance 3
<input type='checkbox' class='toggle_input' id='button3' onclick='updateTable(3);' />
<div class='toggle-control'></div>
</label>
</div>
</div>
<!3 Toggle Buttons end>";
if(isset($_POST['A1'])){
echo "<script type='text/javascript'>alert('A1 pressed');</script>";
}
if($username && $userid){
echo "$home";
if($errormsg)
echo "<script type='text/javascript'>alert('$errormsg');</script>";
}
The checkbox A1 is not responding to isset function. No matter set or not set nothing echo's.
Please help
See the 3 toggle button division

How to send information from CSS-styled button to PHP-script

I am trying to read information from a css-styled web page and send it to a PHP script to be handled. However I can not figure how to do it.
This is the menu button located on the page
<ul class="vmenu">
<li> <span class="l"></span><span class="r"></span><span class="t">Group 1</span> </li>
<li> <span class="l"></span><span class="r"></span><span class="t">Group 2</span> </li>
</ul>...
and this is how I am trying to do it, but it changes it to a visible button and does not fit the styling.
<form name="sidemenu" action="index.php" method="post">
<ul class="vmenu">
<?php while (!empty($categoryname[$categointeger])) { ?>
<li> <input type="submit" name="categoryname" class="button" value="<?php echo"$cateid[$categointeger]"?>"></li>
<?php } ?>
</ul>
</form>
How can I read the information without touching the styling of the page and not using <a href="#">.

Categories