In test.ctp file
<?php echo $form->create(null, array('url' => 'test/'.$test['Test']['id'], 'onSubmit'=>'return status(this)')); ?>
<?php echo $form->hidden('id', array('value' => $test['Test']['id'])); ?>
<dl class="editForm">
<?php echo $form->create(null, array('url' => 'test/'.$test['Test']['id'])); ?>
<?php echo $form->hidden('id', array('value' => $test['Test']['id'])); ?>
<dt><label><?php __('Update Status');?>:</label></dt>
<dd><?php echo $form->select('status_id', $statuses, $selectedStatus, array(), false); ?></dd>
<dd><?php echo $form->end(__('Update Status', true)); ?></dd>
</dl>
In the same .ctp file I need a dialogue box to appear when update button is clicked for confirmation that if user wants to continue with "No Status" or not?
Following code is not working for me, where I am not getting status_id value.
<script type="text/javascript">
function status() {
var status_id = $("#status_id").val();
alert(status_id);
}
</script>
Required: If status_id value is 1 in posted data then dialogue box should appear for confirmation.
To create one button you don't need to keep create a new form. by using form->create...
what you want is just to check the dropdown if the value equals 1 confirmation_window appears.
To do so first you have to know the basic of HTML and JS. if you could implement that you will be able to do so. convert the code blow to cakephp tagging and form. it will get it work.
<form onsubmit="status();" >
<select name="data[User][field]" id="UserField">
<option value="0">1</option>
<option value="1">2</option>
<option value="2">3</option>
</select>
<input type="submit" />
</form>
<script>
function status() {
var status_id = $("#UserField").val();
//or
var status_id = document.getElemetById("UserField");
alert(status_id.options[status_id.selectedIndex].value);
}
</script>
you could even assign id_name to your dropdown. then you should be able to get the value from dropdown using js or jQuery.
$form->select('status_id', array('id'=>'status_id')); ?>
Related
I have a project in which I am displaying a button tag in a while loop. On every button click I want to display an alert box with the respective UserId. Here is my code:
<?php
$data = mysql_query("Select RegisterId,FName,Image1 from Information where RegisterID='$profileMonth1'") or die(mysql_error());
while ($dis1 = mysql_fetch_array($data)) {
?>
<div id="demo1" value="<?php echo "$RegisterId" ?>">
<button onClick="validate()">Show Interest</button>
</div>
<?php } ?>
Here is my validate function:
function validate1(id2)
{
// var id2;
id2 = document.getElementById('demo2').getAttribute('value');
alert(id2);
}
But it is always showing me last user id .. whereas i want to display userid for every user on everyclick.
Can someone help?
Here man, the function you were calling was undefined validate1, also you don't need to get any arguments on your function declaration, since you are not passing any arguments when you invoke it.
<?php
$data = mysql_query("Select RegisterId,FName,Image1 from Information where RegisterID='$profileMonth1'") or die(mysql_error());
while ($dis1 = mysql_fetch_array($data)) {
?>
<div id="demo" value="<?php echo "$RegisterId" ?>">
<button onClick="validate()">Show Interest</button>
</div>
JS
function validate(){
var id2 = document.getElementById('demo').getAttribute('value');
alert(id2);
}
try this in your code
HTML:
<button onClick="validate('<?php echo $RegisterId; ?>')">Show Interest</button>
Javascript:
function validate(id2)
{
alert(id2);
}
Your code needs some modifications.
Firstly, you have made a provision to send id to javascript function, but, you are not passing id to it.
PHP
<?php
$data = mysql_query("Select RegisterId,FName,Image1 from Information where RegisterID='$profileMonth1'") or die(mysql_error());
while ($dis1 = mysql_fetch_array($data)) {
?>
<div id="demo1" value="<?php echo $dis1['RegisterId'];?>">
<button onClick="validate('<?php echo $dis1['RegisterId'];?>')">Show Interest</button>
</div>
<?php } ?>
Javascript:
function validate1(id2) {
// var id2;
//id2 = document.getElementById('demo2').getAttribute('value');
alert(id2);
}
With this code, your clicks shouldn't even return the last id. Your javascript function is not looking good.
This should work;
<?php
$data = mysql_query("Select RegisterId,FName,Image1 from Information where RegisterID='$profileMonth1'") or die(mysql_error());
while ($dis1 = mysql_fetch_array($data)) {
?>
<!-- removed id attribute, as they're unique, you can't set it to every div.
If you really need id attribute, you can set one by using your RegisterId (e.g. id="demo-<?php echo $RegisterId; ?>)
And moved value attribute to button tag, it's much more useful in it. -->
<div>
<button onClick="validate(this)" value="<?php echo "$RegisterId" ?>">Show Interest</button>
</div>
<?php } ?>
Javascript
function validate(element){
alert(element.value)
}
This way, you can use it in other stuff much easier.
I have the following code that allows the user to put the Timing Status on either On or Off
<html>
<?php
if (isset($_POST['Submit1']))
{
$TimingStat=$_POST['timestat'];
$fileName = 'test.txt';
$lines = file($fileName);
$lines[0]="Timing_status= ". $TimingStat;
file_put_contents($fileName, implode($lines));
fclose( $fileName);
}
else
{
$TimingStat=explode(" ",$lines[0]);
$TimingStat=$TimingStat[1];
}
?>
<form action="test.php" name="Calculation" method="post">
Timing Status: <select selected="selected" name="timestat" VALUE="<?PHP print $TimingStat ; ?>">
<?php $attr= 'selected="selected"'; ?>
<option VALUE="On" <?php echo $TimingStat == 'On' ? $attr : ''; ?>>On</option>
<option VALUE="Off" <?php echo $TimingStat== 'Off' ? $attr : ''; ?>>Off</option>
</select>
<Input Type = "Submit" Name = "Submit1" Value = "Save Parameters">
</form>
</html>
It is important for me that the values be written in a text file and then the code reads from a text file.
Everything works fine, except when I refresh my page the selected value will always go to On although Off has been pressed. Any help would be appreciated. Thank you
MY logic is to make a Library Management System in which it first asks for students Class Name, than if Intermediate is selected (which is 1 in database) then show Intermediate Groups else if BS is selected than show BS Department.
<?php
require '/include/connect.inc.php';
require '/include/core.inc.php';
?>
<script type="text/javascript" src="include/JS/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="include/JS/jQuery.js"></script>
<style>tr.Department_Options{ display: none; }</style>
<div class="articles">
<form method="POST" action="#">
<table align="center">
<tr><th><label for="ChoosedClassID">Class : </label></th><td><select name="ChoosedClassID" id="ChoosedClassID"><option disabled selected>Select Class :</option><?php
$query="SELECT ClassID,ClassName from class ORDER BY ClassName ASC";
$query_run=mysqli_query($connect,$query) OR die(mysqli_error($connect));
while($catch=mysqli_fetch_array($query_run)) {
$ClassName=$catch['ClassName'];
$ClassID=$catch['ClassID']; ?>
<option value="<?php echo $ClassID;?>"><?php echo $ClassName; ?></option>
<?php } ?></select><br></td></tr>
<tr id="tr_A" class="Department_Options"><th><label for="id_A">Choose Your Group : </label></th><td><select name="InterGroupID" id="InterGroupID"><option disabled selected>Intermediate Group :</option><?php
$query="SELECT DID,DepartmentName from department WHERE ClassID=1 ORDER BY DepartmentName ASC";
$query_run=mysqli_query($connect,$query) OR die(mysqli_error($connect));
while($catch=mysqli_fetch_array($query_run)) {
$DepartmentName=$catch['DepartmentName'];
$DID=$catch['DID']; ?>
<option value="<?php echo $DID;?>"><?php echo $DepartmentName; ?></option>
<?php } ?></select><br></td></tr>
<tr id="tr_B" class="Department_Options"><th><label for="id_B">Choose Department : </label></th><td><select name="DepartmentName" id="DepartmentName"><option disabled selected>BS Department Name</option><?php
$query="SELECT DID,DepartmentName from department WHERE ClassID=2 ORDER BY DepartmentName ASC";
$query_run=mysqli_query($connect,$query) OR die(mysqli_error($connect));
while($catch=mysqli_fetch_array($query_run)) {
$DepartmentName=$catch['DepartmentName'];
$DID=$catch['DID']; ?>
<option value="<?php echo $DID;?>"><?php echo $DepartmentName; ?></option>
<?php } ?></select><br></td></tr>
</table>
</form>
</div>
The jQuery.js File
$(document).ready(function(){
$('#ChoosedClassID').on('change', function() {
$('tr.Department_Options').hide();
$('#tr_' + $(this).val() ).show();
});
});
According to code above, When I select BS,Intermediate, Next Drop Down Meny doesn't appear.
What I want is that drop down menu appear and when I select some value from it, it should ask for Student Library Number and then I want to make insert query.
Did you try some debugging in your JavaScript? Put temporary alert() statements in, thus:
$(document).ready(function(){
alert(1);
$('#ChoosedClassID').on('change', function() {
alert(2);
$('tr.Department_Options').hide();
$('#tr_' + $(this).val() ).show();
});
});
Do you get "1" on page load and "2" on the control change event? That's the first thing you need to do. If you do, you could perhaps move onto looking at $(this).val() to see what value that resolves to.
As I outlined in the comments, it is worth checking your browser's console, in case any JavaScript errors pop up. Also, check your network panel to ensure your external JavaScript resources (jQuery in particular) are loaded correctly.
I have a HTML form with dropdown list populated by php. I want the user to be able to select an option from the dropdown list and click on "Proceed" button which would open a new page based on the selected value.
<form name="selectPatient" method="post">
<div align="centre">
<select name="patient_dropdown">
<?php
include "connection.php";
$sql = mysql_query("SELECT Name from patient_info");
while ($row = mysql_fetch_array($sql)) {
echo "<option value=".$row['Name'].">".$row['Name']."</option>";
}
?>
</select>
</div>
<br>
<br>
<input type="submit" name="submit" value="Proceed"/>
</form>
<?php
if(isset($_POST['submit'])) {
header("Location: http://localhost/lei/test.com/proper/specific_patient.php");
}
?>
The code above works fine. How do I get the selected value from dropdown list?? I want to use the selected value to run a SQL query using php to get other details of the patient and then call a javascript file with that information. How can I do that??
Thanks in advance !
You need to check your $_POST variables on submit:
$patient_dropdown = isset($_POST['patient_dropdown']) ? $_POST['patient_dropdown'] : false;
I am stuck in a place in Yii. I have two drop Down box, second is dependent on the first. In this first drop Down, I have many options. By referring to these options, I must decide whether the second box must be a drop Down or a text Field.
I have uploaded My code here. Please help me solving this.
Thanks in advance.
My View:
<td>
<?php echo $form->labelEx($model,'cm_classification_id'); ?>
<?php echo $form->dropDownList($model,'cm_classification_id', CHtml::listData(masterClassification::model()->findAll(array('order' => 'cm_classification_id ASC', 'condition'=>'cm_classification_type=:type', 'params'=>array('type'=>'initiate'))), 'cm_classification_id', 'cm_classification_name'), array('empty'=>'Select classification')); ?>
<?php echo $form->error($model,'cm_classification_id'); ?>
</td>
<td>
<label>Change Description <span class="required" id="desc_req_note" style="display:none;">*</span></label>
<?php echo $form->dropDownList($model,'cm_description',array(),array('empty'=>'Select Change Description')); ?>
<?php echo $form->error($model,'cm_description'); ?>
</td>
based on the change classification, I must decide where Change Description must be a drop Down or a text field.
This must be done using Javascript.
Have you tried this -
Change the code to -
<label>Change Description <span class="required" id="desc_req_note" style="display:none;">*</span></label>
<span id="cm_desc_select" style="display:none;"><?php echo $form->dropDownList($model, 'cm_description', array(), array('empty'=>'Select Change Description')); ?></span>
<span id="cm_desc_input" style="display:none;"><?php echo $form->textField($model,'cm_description'); ?></span>
<?php echo $form->error($model,'cm_description'); ?>
2.
$('#cm_classification_id').change(function() {
var val = $(this).val();
var cm_desc_select_elem = $('#cm_desc_select');
var cm_desc_input_elem = $('#cm_desc_input');
if(val === COMPARE_WITH_YOUR_VALUE) {
$(cm_desc_select_elem).show();
} else {
$(cm_desc_input_elem).show();
}
});
I hope is helps for a quick fix.