Hi I'm writing a code to get the value of a textbox. Though all the other values prints perfectly well alert(FormID) prints as Undefined. Here I have clearly commented on what I'm getting. Please someone help me to show the mistake I have done.
<html>
<title></title>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script></head>
<script src="UserTypeSubmit.js"></script></head>
<script>
$(document).ready(function(){
$(".FormEdit").click(function(){
var B=$(this).attr('id');// Ex: Getting ID as FormEdit1 if click on first Edit link
var ReplacesVal=B.replace("FormEdit","");//Prints Value as 1 a I I need.
alert("FormIDInput"+ReplacesVal);//Alert : FormIDInput1
var FormID=$("#FormIDInput"+ReplacesVal).val();
alert(FormID);// Alert: Undefine. Im expecting the value 1 to be in the alert as $("#FormIDInput"+ReplacesVal).val() is equal to 1. and it prints well in the text box.
});
return false;
});
</script>
</head>
<body>
<div class="User" style="color:#0B173B">Forms_Available_to_Collect_Pubic_Health_Information </div>
<br><br>
<?php
include 'connectionPHP.php';
$result=mysqli_query($con,"SELECT * FROM Form");
echo "<table border='1' id='DisplayFormDetailss'>
<tr style='background-color:#D0A9F5;' height='40px;'>
<th width='100px;'>Form ID</th>
<th width='420px;'>Form Name</th>
<th width='100px;'>Inactivate</th>
<th width='70px;'>Edit</th>
<th width='70px;'>Delete</th>
<th width='70px;'>Save</th>
</tr>";
$i=1;
while($row = mysqli_fetch_array($result))
{
$w=$row['Form_ID'];
$v=$row['Form_Name'];
echo "<tr height='25px;'>";
echo "<input id='FormIDInput ".$i."' value='$w' ></input>";
//Prints 1,2,3,4,5,6 as the values of input boxes perfectly.
echo "<td name='FormID[]' class='FormID' align='center' value='$w'>$w</td>";
echo "<td name='FormName[]' id='FormName".$i."' align='left'>$row[Form_Name]</td>";
echo "<td name='FormInactive[]' id='FormInactive".$i."' align='center'><input type='checkbox'></input></td>";
echo "<td class='FormEdit' id='FormEdit".$i."' align='center'><a href='' align=left>Edit</a></td>";
echo "<td name='FormDelete[]' id='FormDelete".$i."' align='center'><a href='' align=left>Delete</td>";
echo "<td name='FormSave[]' id='FormSave".$i."' align='center'><a href='' align=left>Save</td>";
echo "</tr>";
$i++;
}
echo "</table>";
?>
</body>
</html>
In your PHP code, there is a space in the input box:
echo "<input id='FormIDInput ".$i."' value='$w' ></input>";
try to replace it with
echo "<input id='FormIDInput".$i."' value='$w' ></input>";
in input type filed missing type ='text' & space issue:
echo "<input type='text' id='FormIDInput".$i."' value='$w' ></input>";
You need to use id='FormIDInput".$i."' instead of id='FormIDInput ".$i."'.
And You can use the FormID[] input textfiled for FormIDInput
try using,
echo "<td name='FormID[]' id='FormIDInput".$i."' class='FormID' align='center' value='$w'>$w</td>";
instead of
echo "<input id='FormIDInput ".$i."' value='$w' ></input>";
//Prints 1,2,3,4,5,6 as the values of input boxes perfectly.
echo "<td name='FormID[]' class='FormID' align='center' value='$w'>$w</td>";
Related
I have code
if($rowcount1 > 0){
?>
<h3 class="text-muted"><u>DEPARTURE</u></h3>
<h4><?php echo "$origin to $destination "?></h4>
<table class="table table-hover">
<thead>
<tr>
<th>FLIGHT NO.</th>
<th>DEPART</th>
<th>ARRIVE</th>
<th>AIRPORT</th>
<th>DURATION</th>
<th>FLY ONLY</th>
<th>FLY + BAGGAGE</th>
</tr>
</thead>
<tbody>
<?php
foreach ($query as $flightr) {
echo "<tr>";
echo "<td>".$flightr['id']."</td>";
echo "<td>".$flightr['depart']."</td>";
echo "<td>".$flightr['arrive']."</td>";
echo "<td>".$flightr['airport']."</td>";
echo "<td>".$flightr['duration']."</td>";
echo "<td> <label for=lbl7> <input type='radio' checked id='lbl7' name='flight[]' value='".$flightr['flyonly']."'> PHP ".number_format($flightr['flyonly'])."</label></td>";
echo "<td> <label for=lbl8> <input type='radio' checked id='lbl8' name='flight[]' value='".$flightr['flybaggage']."'> PHP ".number_format($flightr['flybaggage'])."</label></td>";
echo "</tr>";
}
?>
</tbody>
</table>
<hr>
<?php
}else{
echo " <div class='alert alert-info' role='alert'>
No results found on <BIG class='text-muted'>Departure</BIG> pick another flight thank you.
</div>
";
}
}
}
?>
<button type="button" name="forform" onclick="" class="hit">hit</button>
how to put info message that user cant continue (and they cant click the button to continue), if number of rows is not true. Via button onclick. begginer in js sorry. Thanks in advance
Add disabled attribute of button based on rowCount
<button type="button" name="forform" onclick="" class="hit"
<?php echo ($rowcount1 > 0) ? '' : 'disabled'; ?>>hit</button>
You can do that by put button in if else condition with disable attributes
if ($rowcount1 > 0) {
?>
<h3 class="text-muted"><u>DEPARTURE</u></h3>
<h4><?php echo "$origin to $destination " ?></h4>
<table class="table table-hover">
<thead>
<tr>
<th>FLIGHT NO.</th>
<th>DEPART</th>
<th>ARRIVE</th>
<th>AIRPORT</th>
<th>DURATION</th>
<th>FLY ONLY</th>
<th>FLY + BAGGAGE</th>
</tr>
</thead>
<tbody>
<?php
foreach ($query as $flightr) {
echo "<tr>";
echo "<td>" . $flightr['id'] . "</td>";
echo "<td>" . $flightr['depart'] . "</td>";
echo "<td>" . $flightr['arrive'] . "</td>";
echo "<td>" . $flightr['airport'] . "</td>";
echo "<td>" . $flightr['duration'] . "</td>";
echo "<td> <label for=lbl7> <input type='radio' checked id='lbl7' name='flight[]' value='" . $flightr['flyonly'] . "'> PHP " . number_format($flightr['flyonly']) . "</label></td>";
echo "<td> <label for=lbl8> <input type='radio' checked id='lbl8' name='flight[]' value='" . $flightr['flybaggage'] . "'> PHP " . number_format($flightr['flybaggage']) . "</label></td>";
echo "</tr>";
}
?>
</tbody>
</table>
<hr>
<button type="button" name="forform" onclick="" class="hit">hit</button>
<?php
} else {
echo " <div class='alert alert-info' role='alert'>
No results found on <BIG class='text-muted'>Departure</BIG> pick another flight thank you.
</div>
";
echo '<button type="button" name="forform" onclick="" class="hit" disable="disable">hit</button>';
}
?>
i am retrieving some data from database and show them in a html table.but right now i am struggling with the following scenario.
if user clicks disable button it should be hide and enable button should be show.if user clicks on enable button it should be hide and disable button should be show.
Here is my code
<html>
<title></title>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$('input:submit').click(function(){
$('input:submit').attr("disabled", true);
});
</script>
</head>
<body>
<?php
echo "<table border='1' align='center' width='100%'>
<tr>
<th>ID</th>
<th>Image</th>
<th>Modified Date</th>
<th>URL</th>
<th>Clicks</th>
<th>Status</th>
<th>Action</th>
</tr>";
while($row = mysqli_fetch_array($query))
{
$id = $row['img_id'];
echo "<tr>";
echo "<td align='center'>" . $row['img_id'] . "</td>";
echo "<td align='center' width='500px'>" . '<img width = 200px; height=100px; src=" '. ($row['img_path']) . '"/>'. "</td>";
echo "<td align='center' width='350px'>" . $row['date'] . "</td>";
echo "<td align='center'>" . $row['url'] . "</td>";
echo "<td align='center'>" . $row['clicks'] . "</td>";
echo "<td align='center'>" . $row['status'] . "</td>";
echo "<td align='center'><a href='image_update.php?id=$id'><button>Update</button></a>
<form method='post' >
<input type='hidden' name='tid' value='$id'/>
<input type='submit' name='disable' id='disable' value='Disable'>
<input type='submit' name='enable' id='enable' value='Enable'>
</form>
</td>";
$id = $_POST['tid'];
if($_SERVER['REQUEST_METHOD']=='POST') {
$sql = "UPDATE advertisementnew SET status = 'Disabled' WHERE img_id='$id'";
mysqli_query($con, $sql);
}
echo "</tr>";
}
echo "</table>";
try this js:
$('#enable').css("display", "none");
$('#disable').click(function(){
$('#enable').css("display", "block");
$('#disable').css("display", "none");
});
instead of:
$('input:submit').click(function(){
$('input:submit').attr("disabled", true);
});
can you try this hope this is works
<script type = "text/javascript" >
$('input:submit').click(function () {
var check = $(this).attr('id');
if (check == 'disable') {
$('#enable').show();
$('#disable').hide();
}
if (check == 'enable') {
$('#disable').show();
$('#enable').hide();
}
});
</script>
You can have class
.hide-show{
display : none;
}
HTML :
<input type='submit' name='disable' id='disable' value='Disable' class="enable-disable-btn">
<input type='submit' name='enable' id='enable' value='Enable' class="enable-disable-btn hide-show">
Initially put the hide-show class on the button which should be need to hide.
Add class enable-disable-btn to both button enabled/disbaled
JS:
You can use jQuery#toggleClass
$(".enable-disable-btn").on('click',function(){
$(".enable-disable-btn").toggleClass('hide-show')
})
You need to add unique id dynamically created in while loop in your case id is not unique
for this
changes in php replace these two lines
<input type='submit' onclick='doEnableDesable(this)' name='disable' id='disable".$id."' value='Disable'>
<input type='submit' onclick='doEnableDesable(this)' name='enable' id='enable".$id."' value='Enable'>
And in javascript define function for dynamic Id
function doEnableDesable(params)
{
if (params.value == 'disable') {
$('#'+params.id).show();
$('#'+params.id).hide();
}
if (params.value == 'enable') {
$('#'+params.id).show();
$('#'+params.id).hide();
}
}
I want to allow clicking on a whole host table in foreach loop in codeigniter. For some reason, the code does not work for me. Do you have an idea how to fix it?
Thanks in advance
<table class="table table-hover">
<thead>
<tr>
<th>השולח</th>
<th>נשלחה בתאריך</th>
<th>נושא ההודעה</th>
<th>תוכן ההודעה</th>
</tr>
</thead>
<tbody>
<?php foreach ($messages->result() as $row)
{
?>
<script type="text/javascript">
function newDoc() {
window.location.assign("<?php echo base_url();?>/read_messages/<?php echo $row->id;?>")
}
</script>
<?php
echo "<tr>";
echo "<td>".$row->author. "</td>";
echo "<td>".$row->posted_in. "</td>";
echo "<td>".$row->title. "</td>";
echo "<td>".$row->body. "</td>";
?>
onclick="newDoc()";
<?php
echo "</tr>";
}
?>
</tbody>
</table>
</div>
As I understand your question you want fetch click on every row. then your code should be as:
Your Script should be out side
<script type="text/javascript">
function newDoc(id) {
window.location.assign("<?php echo base_url();?>/read_messages/"+id);
}
</script>
<?php foreach ($messages->result() as $row)
{
echo "<tr onclick='newDoc(".$row->id.")'>";
echo "<td>".$row->author. "</td>";
echo "<td>".$row->posted_in. "</td>";
echo "<td>".$row->title. "</td>";
echo "<td>".$row->body. "</td>";
echo "</tr>";
}
?>
You have to assign onClick="newDoc" to html element like
<table onClick="newDoc()">
You have to issues, one your newDoc() function is not assigned to element and two you want create the newDoc function once and only once passing in the $row->id so that its affect changes for each <tr>
<script type="text/javascript">
function newDoc(rowId) {
window.location.assign("<?php echo base_url();?>/read_messages/" + rowId);
}
</script>
<?php
foreach ($messages->result() as $row) {
echo "<tr onlick='newDoc(<?php echo $row->id ?>)'>";
echo "<td>".$row->author. "</td>";
echo "<td>".$row->posted_in. "</td>";
echo "<td>".$row->title. "</td>";
echo "<td>".$row->body. "</td>";
echo "</tr>";
}
?>
I have two buttons on one submit form but when I post the submit button it returns nothing;"ABOUT THE BUTTON"; the other data is retrieved WELL.
I have been using different names for the submit button but nothing works.. Could someone help me? thank you.
The FORM data is retrieved well but not the submit button value? i need the value to differ the condition
controller: admin.php
function submit_unitgroupwd(){
$this->access_chk(); //CHECK USER ACCESS
$sbm=$this->input->post('sbm'); // returns NOTHING
echo $_POST["sbm"]; // returns undefined index sbm
echo $_POST['sbm']; // returns undefined index sbm
var_dump($_POST); // returns all the post data bt the submit button
//echo var_dump($this->input->post("sbm"));
exit();
if($this->input->post('sbm') == "Update") {
// do update
} else {
// do delete
}
}
view:
echo "<form action=".site_url("admin/submit_unitgroupwd")." method=post id=form>";
echo "<div style='float:left;color:red;' id='res'></div>";
?><?php
foreach($q1->result_array() as $r1){
$bankname= substr($r1["bank"],0,3);
//echo $bankname;
echo "<input type=hidden name=dgroup value='".$dgroup."'>";
echo "<tr>";
echo "<td width=20% colspan=3 style='font-size: 16px;'>".strtoupper($r1["bank"])."</td>";
echo "</tr>";
echo "<tr>";
echo "<td width=100>".$group_[0]."</td>";
echo "<td><input type=text name='$bankname-utama' value='".str_replace(" ","",$r1["utama"])."' style='width: 100%;'></td>";
if ($r1["bank"] == 'ALL'){
echo "<td rowspan='1'><br><input type='checkbox' name='cek[]' id='cek[]' value='$bankname' ></td>";
echo "<input type=hidden name=_code$bankname value='".$r1["bank"]."'>";
echo "</tr>";
echo "</tr>";
continue;
}
echo "<td rowspan=".($dgroup + 1)."><br><input type='checkbox' name='cek[]' id='cek[]' value='$bankname' ><br><br><br><br><br><br><br>";
echo "<input type=hidden name=_code$bankname value='".$r1["bank"]."'>";
echo "</tr>";
$_alp = "a";
for ($_g=0; $_g<$dgroup; $_g++){
echo "<tr>";
echo "<td width=100>".$group_[($_g + 1)]."</td>";
echo "<td width=80%><input type=text name='$bankname-wd$_alp' value='".str_replace(" ","",$r1["wd$_alp"])."' style='width: 100%;'></td>";
echo "</tr>";
$_alp++;
echo "</tr>";
}
}
?>
>
<input type="submit" class="button" value='Update' name="sbm"/>
<input type="submit" class="button" value='Delete' name="sbm"/>
I'm not completely clear on your description of the problem, but you can't name both submit buttons the same.
You seem to think that push one or the other button will only submit THAT button's value, but in fact the second one is always submitted, because it is the last on the form.
So change your button names to "update" & "delete", and then you can check with
if(isset($_POST['update']))....
for example.
However, you might want to look around the internet for some cleaner examples of how to code what you are after.
You could simply use only the
<input type="submit" class="button" value='Update' name="sbm"/>
and use an anchor for the delete action,
echo "<a href ='controller_delete/$item_id' class='button'>Delete</a>
since you normally wont need other inputs on the delete action if you get my point.
I'm retrieving data from mysql like this structure =>
echo "<table id='postI" . $chat_row['id'] . "'>";
echo "<tr>";
echo "<td><p class='post_author'>" . $chat_row['user_name'] . "</p><a href='javascript: void(0)' class='edit_post_a'><div class='edit_post'></div></a></td>";
echo "</tr>";
echo "<tr>";
echo "<td><p class='posted_on'>" . $chat_row['posted_on'] . "</p></td>";
echo "</tr>";
echo "<tr>";
echo "<td><br></td>";
echo "</tr>";
echo "<tr>";
echo "<td><p class='posted_msg'>" . $chat_row['message'] . "</p></td>";
echo "</tr>";
echo "</table>";
and I can get the table id with this expression =>
$(".edit_post_a").bind("click",function(){
var tb_id = $(this).closest("table").attr("id"); // works , gets the id of the table
alert($(tb_id + ".posted_msg").text()); // don't work, gets nothing , just alert box
});
My problem is that want to know text of the third p, what I've tried =>
alert($("#" +tb_id + ".posted_msg").text());
alert($("#" +tb_id).find("p").last().text());
alert($("#" +tb_id + " p:nth-child(3)").text());
nothing works , get empty alert box , I've no idea whats wrong ? how can I fix it ? thanks
HTML code =>
<table id='postI245'>
<tr>
<td><p class='post_author'>USER</p><a href='javascript: void(0)' class='edit_post_a'><div class='edit_post'></div></a>
</td>
</tr>
<tr>
<td><p class='posted_on'>DATE</p></td>
</tr>
<tr>
<td><br></td>
</tr>
<tr>
<td><p class='posted_msg'>MSG</p></td>
</tr>
</table>
and so on ...
Your selector selects nothing, you should add # for selecting an element by id.
var txt = $('#'+tb_id + " .posted_msg").text();
or:
var txt = $(this).closest("table").find("p:eq(2)").text()