Get selected option value which is dynamically generated in a nested loop - javascript

Here is the function I am working on. I need to get the selected option which is inside a while loop.
Every time I am trying to get the selected value through select id, it's only getting the last selected value for the rest of the row.
Please help me. How can I get and store the full table data?
function generate_schedule($con,$sy,$year_id){
$time = array(1=>'9:30-11:00',2=>'11:30-1:00',3=>'1:30-3:00',4=>'3:15-4:45');
$days = array(1=>'Sunday',2=>'Monday',3=>'Tuesday',4=>'Wednesday',5=>'Thursday',6=>'Friday',7=>'Saturday');
$rooms=array(1=>'302',2=>'303',3=>'304',4=>'701',5=>'702',6=>'704',7=>'901',8=>'902',9=>'1402',10=>'1405');
$yls=mysqli_query($con,"SELECT * FROM year_level_subject as yls join subjects as s on yls.subj_id=s.subj_id where yls.year_id='$year_id'");
$num=mysqli_num_rows($yls);
$x = 0;
echo '<table class="table table-bordered table-hover" id=" datatable">';
echo '<thead><tr><th>Time</th><th>Days</th><th>Subject</th><th>Teacher</th><th>Room</th></tr></thead>';
while($row=mysqli_fetch_assoc($yls)){
extract($row);
echo '<tr>';
echo '<td><select id ="seltime" ><option value=0>Select Time</option>';
foreach($time as $key => $value) {
echo '<option value='.$key.'>';
echo $value .'</option>';
}
echo '</select></td>';
echo '<td><select class="selday" ><option value=0>Select Day</option>';
foreach($days as $key => $value) {
echo '<option value='.$key.'>';
echo $value .'</option>';
}
echo '</select></td>';
echo '<td>'.$subj_desc.'</td>';
$teach = mysqli_query($con,"SELECT * FROM teachers");
echo '<td><select id="selteacher" onchange="schedata(this)"><option value=0>Select Teacher</option>';
while($row=mysqli_fetch_assoc($teach)){
extract($row);
echo '<option value='.$teach_id.'>'.$teach_fname.' '.$teach_mname.' '.$teach_lname.'</option>';
}
echo '</select></td>';
echo '</select></td>';
echo '<td><select name ="selroom" ><option value=0>Select Room</option>';
foreach($rooms as $key => $value) {
echo '<option value='.$key.'>';
echo $value .'</option>';
}
echo '</select></td>';
echo '</tr>';
}
echo '</table>';
}

you did't give the name atribute to your select element
echo '<td><select id="selteacher" onchange="schedata(this)" >
give a name for this as
echo '<td><select id="selteacher" name="selteacher" onchange="schedata(this)" >

Related

how to disable checkbox after due date has passed

I've this code in php, and it retrieve all the value I've in my database, and I want the user not be able to choose or tamper with the one that has expired date,
please can you help me ?
my code below only show u the word 'Expired' and 'Not Expired' on the web, since I'm only Echoing it.
I want to just disable the check box, and not let the user be able to change anything like the statues or remove the job.
please can you help me ?
$result = mysqli_query($dbCIE,$sqlCommand) or die(mysql_error());
echo "<form action='JobsLists.php' method='post'>";
while($row = mysqli_fetch_array($result))
{
$exp_date = $row['DueDate'];
$today_date = date('Y/m/d');
$exp=strtotime($exp_date);
$td=strtotime($today_date );
if($td>$exp){
echo"Expiered";
}else{
echo"NOT Expiered";
}
echo "<tr>";
echo "<td> <input type='checkbox' id='myCheck' name='JobId[]' value='". $row['JobId'] ."' /> </td>";
echo "<td align=center>" . $row['SSU'] . "</td>";
echo "<td align=center>" . $row['JobName'] . "</td>";
echo "<td align=center> " . $row['Description'] . "</td>";
echo "<td align=center>" . $row['DueDate'] . "</td>";
echo "<td>"."<select name='JobStatus[".$row['JobId']."]'>";
if($row['JobStatus'] == "InProgress"){
echo "<option value='InProgress' selected>In Progress</option>";
echo "<option value='Completed'>Completed</option>";
} else {
echo "<option value='InProgress'>In Progress</option>";
echo "<option value='Completed' selected> Completed </option>";
}
echo "</select>" . "</td>"; // need to be worked on..
echo "</tr>";
}
"</table>";
?>
Why not just not print it out?
if (!$td->exp)
echo "<td> <input type='checkbox' id='myCheck' name='JobId[]' value='". $row['JobId'] ."' /> </td>";
It's better to just not show a button or input than to disable it sometimes. Inputs can be disabled with the DISABLED keyword
<input type="checkbox" name="foo" DISABLED>

Option in dropdown box render outside

English is not my first language so i'm trying to be as specific as possible.
I have a table stored , all of the signed up account to my website. Inside of it i have a dropdown box automatically generated by php. So the problem is, when i click to changed the option in the dropdown menu, all of my option appeared outside of the box and was duplicated . Just like this error dropdown box. Here is the code
$sql1="Select ID, user_login,user_email, display_name from wp_users ";
$result1=mysqli_query($conn,$sql1);
echo '<div id="div_package" style="display: none" >';
echo '<div style="text-align:center"><h1>Đổi gói thành viên</h1><input type="text" id="myInput_pack" onkeyup="FilterUsers()" placeholder="Nhập thông tin người dùng cần tìm" title="Type in a user" style="width: 20%;height:35px; font-size: 16px;border: 1px solid black; margin-bottom: 12px;text-align:center"></div>';
echo "<table id='tb_user' class='tbadmin' border='1' cellpadding='10' align='center' style='border-collapse:collapse'>";
echo "<tr><th>ID người dùng</th><th>Tên đăng nhập</th><th>Tên hiển thị</th><th>Email</th><th>Gói hiện tại</th><th></th></tr>";
while($row= mysqli_fetch_array($result1))
{
$userid=$row['ID'];
echo '<tr>';
echo '<td>'.$userid.'</td>';
echo '<td>'.$row['user_login'].'</td>';
echo '<td>'.$row['display_name'].'</td>';
echo '<td>'.$row['user_email'].'</td>';
echo "<td><select name='package_$userid' id='package'>";
$sqlcheck="SELECT 1 FROM wp_usermeta WHERE user_id=".$userid." AND meta_key='package_id' LIMIT 1";
$result_check= mysqli_query($conn,$sqlcheck);
if( mysqli_num_rows($result_check)!=0)
{
$sql_metaval="Select meta_value from wp_usermeta where user_id=".$userid." and meta_key='package_id'";
$result_metaval= mysqli_query($conn,$sql_metaval);
while($metaval= mysqli_fetch_array($result_metaval))
{
$val_package=$metaval['meta_value'];
$test="Select post_title, ID from wp_posts where post_type='membership_package' and ID=".$val_package ;
$sql2="Select post_title, ID from wp_posts where post_type='membership_package' and ID<>".$val_package ;
$result_test=mysqli_query($conn,$test);
if(mysqli_num_rows($result_test)==0)
{
echo '<option value="">FREE</option>';
$sql3="Select post_title, ID from wp_posts where post_type='membership_package' and ID<>''";
$packages= mysqli_query($conn,$sql3);
while($pack = mysqli_fetch_assoc($packages)){
echo '<option value="'.$pack['ID'].'">'.$pack['post_title'].'</option>';
}
echo '</select>';
}
else
{
while($row= mysqli_fetch_array($result_test))
{
echo '<option value="'.$val_package.'">'.$row['post_title'].'</option>';
}
$packages= mysqli_query($conn,$sql2);
while($pack = mysqli_fetch_assoc($packages)){
echo '<option value="'.$pack['ID'].'">'.$pack['post_title'].'</option>';
}
echo '<option value="">FREE</option>';
echo '</select>';
}
}
}
else
{
echo '<option value="">FREE</option>';
$sql3="Select post_title, ID from wp_posts where post_type='membership_package' and ID<>''";
$packages= mysqli_query($conn,$sql3);
while($pack = mysqli_fetch_assoc($packages)){
echo '<option value="'.$pack['ID'].'">'.$pack['post_title'].'</option>';
}
echo '</select>';
}
echo "<td><a onclick='return confirmEdit();' href='#' id='update_$userid' class='update_user'>Cập nhật</a></td>";
echo '</tr>';
}
echo "</table></br></div>";
It's appear that some kind of loop has happened in the first else section. I tried to delete the select tag in side that section, all the option appeared inside but still be duplicated like this one
Can someone show me how to solve the duplicate option? This has trouble me for days.
I think the problem because you loop the selected option and not selected options in same select without exclude the select option from query of get not selected options ($sql2).
$test="Select post_title, ID from wp_posts where post_type='membership_package' and ID=".$val_package ;
$sql2="Select post_title, ID from wp_posts where post_type='membership_package' and ID<>".$val_package ;
-------------------------------------------------------
while($row= mysqli_fetch_array($result_test))
{
echo '<option value="'.$val_package.'">'.$row['post_title'].'</option>';
}
$packages= mysqli_query($conn,$sql2);
while($pack = mysqli_fetch_assoc($packages)){
echo '<option value="'.$pack['ID'].'">'.$pack['post_title'].'</option>';
}

Get ID automatically in input-field after <SELECT> without button click

I have an SQL-database with many tables. Now I would like to create an input-form to be able to get data into the db without writing the entire sql-code every time. And this should work as follows:
All table names are listed in a drop-down menu. After having selected a table name, a new table with 4 columns is created automatically:
The first column of this table simply contains an increasing number.
The second column contains the field-names of the selected table.
In the third column there are empty input fields to enter the values for the database. Only in the third line (=product name) there is a drop-down menu with all product names from the main-table of the db.
The fourth column contains the data type (e.g. int or varchar)
All tables in the database have the same structure in the first 3 columns: the first column contains the table-id, the second column the foreign-key (=master_id) and the third column the product_name.
Up to this point, the script works well with the following 2 php-files (javasql.php and getuser.php):
javasql.php:
enter code here
<!DOCTYPE html>
<html>
<head>
<script>
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
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 (this.readyState==4 && this.status==200) {
document.getElementById("txtHint").innerHTML=this.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
<option value="" class="optdrugs">please select</option>
<?php
include("files/zugriff.inc.php"); // database Access
$sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = 'product'";
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_assoc($result)) {
echo '<option class="optdrugs" value="'. $row['TABLE_NAME'] . '">' .
$row['TABLE_NAME']. '</option>';
echo '<br>';
}
?>
</select>
</form>
<br>
<div id="txtHint"><b>Bitte Tabelle auswählen:</b>
<br>
<?php
if (isset($_POST["submit"])) {
$sent = $_POST['sent'];
$q = $_POST['tablename'];
$column_passed = unserialize($_POST['column']); // content of array
$column is passed from getuser.php
foreach ($_POST["insertvalue"] as $key => $value) {
echo $value . "<br>";
$werte[] = "'$value'";
}
$sql="INSERT INTO $q ($column_passed) VALUES (" .
implode(", ", $werte) . ")"; // data entry
mysqli_query($db, $sql);
if (mysqli_affected_rows($db) > 0) {
echo "<h3 style='color:blue'>successful</h3>";
} else {
echo "<h3 style='color:red'>not
successful</h3>";
}
}
?>
</div>
</body>
</html>
enter code here
getuser.php:
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<form id="formdatabase" name="formdatabase" action="javasql.php"
method="post">
<input type="hidden" name="sent" value="yes">
<?php
$q = strval($_GET['q']);
$con = mysqli_connect('localhost','root','','product');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM $q";
$result = mysqli_query($con,$sql);
$numcols = mysqli_num_fields($result); // gets number of columns in result table
$field = mysqli_fetch_fields($result); // gets the column names from the result table
$data_type_array = array(
1=>'tinyint',
2=>'smallint',
3=>'int',
4=>'float',
5=>'double',
7=>'timestamp',
8=>'bigint',
9=>'mediumint',
10=>'date',
11=>'time',
12=>'datetime',
13=>'year',
16=>'bit',
252=>'text',
253=>'varchar',
254=>'char',
246=>'decimal'
);
$data_type_array = array_flip($data_type_array);
echo "<table>";
echo "<tr>";
echo "<th>" . 'Nr' . "</th><th>" . 'Column names' . "</th>
<th>" . 'Values for db-entry' . "</th><th>" . 'Type' . "</th>";
echo "</tr>";
echo "<tr>";
$nr = 1;
for($x=0;$x<$numcols;$x++):?>
<td><?= $nr; ?></td>
<td><?= $field[$x]->name; ?></td>
<?= $column[] = $field[$x]->name; ?>
<td>
<?php
if ($field[$x]->name == 'Name') { // if-Beginn
?>
<select name="insertvalue[<?= $x; ?>]" id="insertvalue<?=
$x; ?>" size="1" onchange = "javascript:getSelectedRow()">
<?php
include("files/zugriff.inc.php");
$sql = "SELECT * FROM product_main ORDER BY Name";
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_assoc($result)) {
echo '<option class="optdrugs" value='. $row['Name'] . '>' .
$row['Name'] . '</option>';
echo '<br>';
}
?>
</select>
<?php
$name_option = "";
} else {
$name_option = "<input type='text' id='insertvalue" . $x . "'
name='insertvalue[" . $x . "]' size='50'>";
echo $name_option;
}
?>
</td>
<?php
$key = array_search($field[$x]->type, $data_type_array);
if($key !== false){
echo "<td>" . $key . "</td>";
}else{
echo "<td>" . $field[$x]->type . "</td>";
}
?>
<td><?= $field[$x]->type; ?></td>
<?= $nr = $nr + 1; ?>
</tr>
<?php endfor;
echo "</table>";
mysqli_close($con);
?>
<input type="hidden" name="tablename" value="<?= $q; ?>">
<input type="hidden" name="column" value="<?php echo htmlentities
(serialize($column)); ?>">
<input type="submit" value="Enter values" name="submit">
</form>
</body>
</html>
Since I need the master_id (= foreign key) in addition to the product-name for database entry, I would like to extend my script, so that the respective master_id is automatically sent to the input field in line 2, when a product-name is selected in line 3 ... without clicking a button. I tried to do this with javascript but it didn´t work. As far as I know, the solution would be to use AJAX but unfortunately, I am not very used to AJAX.
I would be more than happy, if someone could help me to solve this problem!

Auto fill text box depending on Drop Down value

This might be a stupid question but I would like to have a clarification on how to go about this. I have come across quite a few articles that let to set the values of a text box depending on the choices made in a drop down menu using jQuery and Ajax. My issue is when I'm trying to do the same depending on the choices made in 5 drop down menus. I have the Id values stored in the database which should be used to populate the text box. Can anyone guide on how to go about this issue with multiple drop downs. This is my code so far:
<?php
$sql1="SELECT Schlungen FROM schulung as s";
$result=mysql_query($sql1);
echo "<p align='left'> <strong>Schulung 1</strong> <select name='Schlungen1'> <option value default></option>";
while ($row = mysql_fetch_array($result))
{
echo "<option value='" . $row['Schlungen'] . "'>" . $row['Schlungen'] . " </option>";
}
echo "</select>";
?>
<?php
error_reporting(0);
//Drop Down for Schulung 2
$sql2="SELECT Schlungen FROM schulung as s";
$result=mysql_query($sql2);
echo "<p align='left'> <strong>Schulung 2</strong> <select name='Schlungen2'> <option value default></option>";
while ($row = mysql_fetch_array($result))
{
echo "<option value='" . $row['Schlungen'] . "'>" . $row['Schlungen'] . " </option>";
}
echo "</select>";
?>
<?php
error_reporting(0);
//Drop Down for Schulung 3
$sql3="SELECT Schlungen FROM schulung as s";
$result=mysql_query($sql3);
echo "<p align='left'> <strong>Schulung 3</strong> <select name='Schlungen3'> <option value default></option>";
while ($row = mysql_fetch_array($result))
{
echo "<option value='" . $row['Schlungen'] . "'>" . $row['Schlungen'] . "</option>";
}
echo "</select>";
?>
<?php
error_reporting(0);
//Drop Down for Schulung 4
$sql4="SELECT Schlungen FROM schulung as s";
$result=mysql_query($sql4);
echo "<p align='left'> <strong>Schulung 4</strong> <select name='Schlungen4'><option value default></option>";
while ($row = mysql_fetch_array($result))
{
echo "<option value='" . $row['Schlungen'] . "'>" . $row['Schlungen'] . " </option>";
}
echo "</select>";
?>
<?php
error_reporting(0);
//Drop Down for Schulung 5
$sql5="SELECT Schlungen FROM schulung as s";
$result=mysql_query($sql5);
echo "<p align='left'> <strong>Schulung 5</strong> <select name='Schlungen5'><option value default></option>";
while ($row = mysql_fetch_array($result))
{
echo "<option value='" . $row['Schlungen'] . "'>" . $row['Schlungen'] . " </option>";
}
echo "</select>";
?>
<p align="left"><strong>Access_level </strong>
<input type="text" name="a_level" disabled="disabled">
</p>
For achieving auto completion,you can create a select field in html file,call a javascript function on keyup event and use jQuery for calling your php file
<html>
<head>
<script>
$('.autosuggest').keyup(function(){
$.post("<your file.php>",{any data you need},function(data){
//echo the data
//echo "<option value='" . $row['Schlungen'] . "'>" . //$row['Schlungen'] ." </option>";
$('.result').html(data)
});
});
$('.result option').click(function(){
var rValue = $(this).text();
$('.autosuggest').attr('value',rValue);
$('.result').html('');
});
</script>
</head>
<body>
<input type='text' class='autosuggest'/>
<select class='result'>
</select>
</body>
</html>
try to set the value of each html select option to be the id of that text
so the echo should be
echo "<option value='" . $row['id'] . "'>" . $row['Schlungen'] . " </option>";
then on the html select add the event onchange and add the JS function foo() to fill a hidden input with all selected ids by getting them from the page using the JQuery or Javascript
also you have to add id or class for each html select to get its selected value easily
$("#select1").val();
$("#select2").val(); ...
then insert these values in a hidden input field so the hidden input now contains all selected ids

Cloned Select Options With Javascript and Store them In A Hidden Field

I have a table with 3 select option values; airdate_year, airdate_month, and airdate_day. Also a hidden field called episode_airdate[] to store all 3. The problem here is that the table tr is cloned using javascript therefore the values are not being sent to episode-airdate properly, any thoughts?
This is the script I use to combine the 3 select values to make the value for the hidden field.
<script>
function datepopulate(){
var day = document.getElementById('airdate_day').value;
var month = document.getElementById('airdate_month').value;
var year = document.getElementById('airdate_year').value;
var completedate = day+'-'+month+'-'+year;
document.getElementById('episode_airdate[]').value = completedate;
alert(document.getElementById('episode_airdate[]').value);
return true;
}
</script>
The php
<table id="template" style="display: none;" cellpadding="0px 20px" cellspacing="0px 20px">
<tr class="line">
<td width="100%">
<p>
<label><?php _e('Season:'); ?></label>
<?php
for($i=1; $i<=50; $i++)
$season_nums[]=$i;
echo '<select name="episode_season[]" select id="episode_season[]" class="season regular-text" style="width:50px; float:left; margin-right:10px;">';
echo '<option value="">' . __("0" ) . '</option>';
foreach($season_nums as $season_num){
$selected = '';
echo '<option value="' . $season_num . '" ' . $selected . '>' . $season_num . '</option>';
}
echo '</select>';
?>
</p>
<label><?php _e('Episode:'); ?></label>
<p>
<?php
for($i=1; $i<=50; $i++)
$episode_nums[]=$i;
echo '<select name="episode_number[]" select id="episode_number[]" class="number regular-text" style="width:50px; float:left;">';
echo '<option value="">' . __("0" ) . '</option>';
foreach($episode_nums as $episode_num){
$selected = '';
echo '<option value="' . $episode_num . '" ' . $selected . '>' . $episode_num . '</option>';
}
echo '</select>';
?>
</p>
<label><?php _e('Title:'); ?></label>
<p>
<input type="text" name="episode_title[]" id="episode_title[]" value="" class="title regular-text" style="width:400px;" />
</p>
<label><?php _e('Airdate'); ?></label>
<p>
<script>
function datepopulate(){
var day = document.getElementById('airdate_day').value;
var month = document.getElementById('airdate_month').value;
var year = document.getElementById('airdate_year').value;
var completedate = day+'-'+month+'-'+year;
document.getElementById('episode_airdate[]').value = completedate;
alert(document.getElementById('episode_airdate[]').value);
return true;
}
</script>
<?php
for($i=1910; $i<=2012; $i++)
$years[]=$i;
echo '<select id="airdate_year" onChange="javascript:datepopulate();" style="width:50px; float:left; margin-right:10px;">';
echo '<option value="">' . __("2012" ) . '</option>';
foreach($years as $year){
$selected = '';
echo '<option value="' . $year . '" ' . $selected . '>' . $year . '</option>';
}
echo '</select>';
for($i=1; $i<=12; $i++)
$months[]=$i;
echo '<select id="airdate_month" onChange="javascript:datepopulate();" style="width:50px; float:left; margin-right:10px;">';
echo '<option value="">' . __("0" ) . '</option>';
foreach($months as $month){
$selected = '';
echo '<option value="' . $month . '" ' . $selected . '>' . $month . '</option>';
}
echo '</select>';
for($i=1; $i<=31; $i++)
$days[]=$i;
echo '<select name="airdate_day" id="airdate_day" onChange="javascript:datepopulate();" style="width:50px; float:left; margin-right:10px;">';
echo '<option value="">' . __("10" ) . '</option>';
foreach($days as $day){
$selected = '';
echo '<option value="' . $day . '" ' . $selected . '>' . $day . '</option>';
}
echo '</select>';
?>
<input type="hidden" name="episode_airdate[]" id="episode_airdate[]" class="airdate regular-text" value="">
</p>
<p>
<label><?php _e('Plot:'); ?></label>
<textarea name="episode_plot[]" id="episode_plot[]" class="plot regular-text"value="" cols="100%" rows="10" tabindex="4" ><?php echo $_POST['episode_season'] ?></textarea>
</p>
</td>
<td width="10%" class="commands">
<a rel="delete" class="button">-</a> <a rel="add" class="button">+</a>
</td>
</tr>
</table>
<table id="attachments" style="border-spacing: 0px 30px;">
</table>
<script>
(function($)
{
lines = 0;
function items_init()
{
<?php $episodes = get_post_meta($post->ID, 'episodes', true) ?>
<?php if ( empty($episodes) ) : ?>
items_add();
<?php else: ?>
<?php
// Get serialized data
$episodes = unserialize($episodes);
// Compare episode numbers
function compare_number($a, $b) {
if ($a['season'] == $b['season']) {
return $b['number'] - $a['number']; }
return strnatcmp($b['season'], $a['season']);
}
// Sort by episode number
usort($episodes, 'compare_number');
// Show episodes
foreach ($episodes as $episode) :
?>
items_add({
title: '<?php echo base64_decode($episode['title']) ?>',
airdate: '<?php echo $episode['airdate'] ?>',
season: '<?php echo $episode['season'] ?>',
number: '<?php echo $episode['number'] ?>',
plot: '<?php echo base64_decode($episode['plot']) ?>',
});
<?php endforeach ?>
<?php endif ?>
// Delete the "-" button in first row
$('#attachments tr:first-child .commands a[rel="delete"]').remove();
}
function items_add()
{
obj = $('#template tr').clone().appendTo('#attachments');
lines++;
if (arguments.length > 0) {
options = arguments[0];
$('.title', obj).val( options.title );
$('.airdate', obj).val( options.airdate );
$('.season', obj).val( options.season );
$('.number', obj).val( options.number );
$('.plot', obj).val( options.plot );
}
}
$('#attachments').delegate('.commands a', 'click', function()
{
var action = $(this).attr('rel');
var confirm_delete = true;
// Add action
if ('add' == action) {
items_add();
}
// Delete action
if ('delete' == action) {
// La TR en la tabla
var oTr = $(this).parent().parent();
var episode_name = $('.title', oTr).val();
var episode_airdate = $('.airdate', oTr).val();
var episode_season = $('.season', oTr).val();
var episode_number = $('.number', oTr).val();
var episode_plot = $('.plot', oTr).val();
if (episode_name != '' || episode_number != '' || episode_plot != '') {
if ( !confirm('Are you sure you want to delete ' + episode_name + '?') ) {
confirm_delete = false;
}
}
if (confirm_delete) {
oTr.next().remove(); oTr.remove();
lines--;
}
}
});
$(document).ready(function()
{
items_init();
});
})(jQuery);
</script>
Since the document contains multiple episode_airdate[] elements, you can't use document.GetElementById, but you can use a different selector. Looking at how the DOM is structured, it seems airdate_year, airdate_month, and airdate_day are all siblings of the target element. So in this case the JQuery nextAll function should work: http://api.jquery.com/category/traversing/
$(this).nextAll("#episode_airdate[]").attr('value', completedate);
alert($(this).nextAll("#episode_airdate[]").attr('value'));

Categories

Resources