I have a drop down menu of mobile brands. When a user selects a mobile brand a dynamic drop populates with the mobile model according to the mobile brand I want to validate that mobile model drop down for a blank select value. I am using ajax xmlhttp request for getting the mobile model drop down menu.
My entire code is:
Code for page with mobile brand drop down menu
<script type="text/javascript">
function validate() {
if (document.myform.step3_mobilebrand.value=="") {
document.getElementById("error1").innerHTML = (error1) ? "<img src='images/formerror.gif' height='15' width='18'>" : "";
document.myform.step3_mobilebrand.focus();
return false;
}
var myTextField = document.myform.getElementById('step3_mobilemodel').value;
if (myTextField == "") {
document.getElementById("error2").innerHTML = (error2)?"<img src='images/formerror.gif' height='15' width='18'>" : "";
document.myform.step3_mobilemodel.focus();
return false;
}
}
</script>
<?php
if (isset($_POST['submitted']) and $_POST['submitted']=="Continue") {
$mobilebrand1 = $_POST['step3_mobilebrand'];
$mobilemodel1 = $_POST['step3_mobilemodel'];
if ($mobilemodel1=="") {
echo "Please Select Mobile Model";
}
$connectiontype=$_POST['step3_connectiontype'];
$internet=$_POST['step3_internet'];
include("admin/config.php");
$sql="insert into member_detail (mobilebrand,mobilemodel,connection_type,internet) values('$mobilebrand1','$mobilemodel1','$connectiontype','$internet')";
mysql_query($sql);
}
?>
<script type="text/javascript">
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 (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
<form name="myform" method="post" action="" onsubmit="return validate();">
<table>
<tr>
<td>Mobile Brand</td>
<td><?php
include ("admin/config.php");
echo "<select name='step3_mobilebrand' onchange='showUser(this.value)'><option value='' selected>Select Mobile Brand</option>";
$result = mysql_query ("select * from mobilebrand order by mobilebrand");
while ($adcom=mysql_fetch_array($result)) {
echo "<option value=\"".$adcom['id']."\">".htmlspecialchars($adcom['mobilebrand'])."</option>";
}
echo "</select>";?><span id="error1" style="color:red;"></span></td>
</tr>
</table>
<div id="txtHint"></div>
<table>
<tr>
<td>Connection Type</td>
<td><input type="radio" name="step3_connectiontype" value="PrePaid" checked="checked">Prepaid
<input type="radio" name="step3_connectiontype" value="PostPaid">Postpaid
<span id="error3" style="color:red;"></span>
</td>
</tr>
<tr>
<td>Have Internet On Mobile</td>
<td><input type="radio" name="step3_internet" value="Yes" checked="checked">Yes
<input type="radio" name="step3_internet" value="No">No
<span id="error4" style="color:red;"></span>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submitted" value="Continue"></td>
</tr>
</table>
</form>
and the code of getuser.php is
<table>
<tr>
<td>Mobile Model</td>
<td>
<?php
$q=$_GET["q"];
include("admin/config.php");
echo "<select name='step3_mobilemodel' id='step3_mobilemodel' ><option value=''>Select Mobile Model</option>";
$result = mysql_query ("select * from mobilemodel where brandcode='".$q."'");
while ($adcom=mysql_fetch_array($result)) {
echo "<option value=\"".$adcom['mobilemodel']."\">".htmlspecialchars($adcom['mobilemodel'])."</option>";
}
echo "</select>"; ?>
</td>
</tr>
</table>
The Output am getting is correct i just want to validate the mobile model drop down menu for blank select
For validating select you can do:
var e = document.getElementById("step3_mobilemodel");
var mobileVal = e.options[e.selectedIndex].value;
if(mobileVal == "") {
...//show your error here
}
Hope it helps
This is pretty much what Sudhir posted (+1 from me) but with an example in a fiddle: http://jsfiddle.net/5TYwH/1/ using the onchange event handler.
May be you can just add a php validation for $q.
<table>
<tr>
<td>Mobile Model</td>
<td>
<?php
$q=$_GET["q"];
echo "<select name='step3_mobilemodel' id='step3_mobilemodel'>"
if($q != ""){
include("admin/config.php");
echo "<option value=''>Select Mobile Model</option>";
$result = mysql_query ("select * from mobilemodel where brandcode='".$q."'");
while ($adcom=mysql_fetch_array($result)) {
echo "<option value=\"".$adcom['mobilemodel']."\">".htmlspecialchars($adcom['mobilemodel'])."</option>";
}}else{ echo "<option value=''>Please select a mobile first</option>";} echo "</select>";?></td>
</tr></table>
Related
I have a problem in my following code. I want all data associated with the selected id of the dropdownlist to be viewed in the textboxes as well as inside the table.
When I ran my code, the result of the query created a repetitive result because of the data inside the database is more than 1 row.
What am I missing here? Did Inmake mistakes in the normalization of the database? Can somebody help me?
below is my code in search.php
<?php
//including the database connection file
include_once("dbconnect.php");
$query1 = "SELECT * FROM kursus";
$result1 = mysqli_query($mysqli, $query1);
$result2 = mysqli_query($mysqli, "SELECT * FROM kursus");
?>
<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 (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","search2.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
Carian : <select id="id_kursus" name="id_kursus" onchange="showUser(this.value)">
<option>Sila Pilih</option>
<?php while($row1 = mysqli_fetch_array($result1)){
echo "<option value='".$row1['id_kursus']."'>".$row1['nama_kursus']."</option>";
}
?>
</select>
</form>
<br>
<div id="txtHint"><b>Result will be display here.</div>
</body>
</html>
below is my codes in search2.php
<html>
<head>
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','root','admin','tracer');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql = "SELECT
a.*,
b.*,
c.*,
a.id_kursus AS id_kursus
FROM pelatih a
LEFT JOIN kursus b ON b.id_kursus = a.id_kursus
RIGHT JOIN status_pelatih c ON c.id_status_semasa = a.id_status_semasa
WHERE a.id_kursus = '.$q.'";
$result = mysqli_query($con,$sql);
$no = 1;
while($row = mysqli_fetch_array($result)) {
echo "<table class='table1'>
<tr>
<td>Kod Kursus : </td>
<td><input type='text' value= '$row[kod_kursus]'></td>
</tr>
<tr>
<td>Nama Kursus : </td>
<td><input type='text' size='40' value= '$row[nama_kursus]'></td>
</tr>
<tr>
<td>Sesi : </td>
<td><input type='text' value= '$row[sesi_kursus]''></td>
</tr>
<tr>
<td>Batch : </td>
<td><input type='text' value= '$row[batch_kursus]'></td>
</tr>
<tr>
<td>Tempoh Kursus :</td>
<td><input type='date' value= '$row[tarikh_mula_kursus]'> Hingga <input type='date' value= '$row[tarikh_tamat_kursus]'></td>
</tr>
<tr>
<td>Program Tajaan : </td>
<td><input type='text' value= '$row[penaja_program]'></td>
</tr>
<tr>
<td>Peruntukan : </td>
<td><input type='text' value= '$row[peruntukan]'></td>
</tr>
<tr>
<td>Tarikh Kajiselidik : </td>
<td ><input type='date' value= '$row[tarikh_kajiselidik]'></td>
</tr>
<tr>
<td>Cara Kajiselidik : </td>
<td ><input type='text' value= '$row[cara_kajiselidik]'></td>
</tr>
</table>
<br>";
echo "<table class='table2'>
<tr>
<th rowspan='2'>Bil</th>
<th colspan='4'>Nama dan Butiran Pelatih</th>
<th colspan='6'>Maklumat Tracer Study</th>
</tr>
<tr>
<th>Nama Pelatih</th>
<th>No. K/P</th>
<th>No. Telefon</th>
<th>Status Semasa</th>
<th>Nama Syarikat</th>
<th>Alamat Syarikat</th>
<th>No. Telefon</th>
<th>Nama Jawatan</th>
<th>Tangga Gaji</th>
<th>Catatan</th>
</tr>";
echo '<tr>
<td>'.$no.'</td>
<td>'.$row['nama_pelatih'].'</td>
<td>'.$row['ic_pelatih'].'</td>
<td>'.$row['tel_pelatih'].'</td>
<td>'.$row['status_semasa_pelatih'].'</td>
<td>'.$row['nama_syarikat'].'</td>
<td>'.$row['alamat_syarikat'].'</td>
<td>'.$row['tel_syarikat']. '</td>
<td>'.$row['jawatan'].'</td>
<td> RM'.$row['tangga_gaji'].'</td>
<td>'.$row['catatan'].'</td>
</tr>';
$no++;
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
So I have a PHP page with a drop down form that when an option is selected, it uses an AJAX script to query a result from the same MySQL table. For the most part, it works like expected. However, some results (specifically, options that have " or ' in the name) are not being set properly to the variable for the AJAX/GET script. Here is my main PHP script:
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/styles.css" media="screen" />
<title>Add Inventory</title>
<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 (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getsku.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
session_start();
require_once('includes/config.inc.php');
require_once('includes/functions.inc.php');
// Check login status -- if not logged in, redirect to login screen
if (check_login_status() == false) {
redirect('login.php');
}
$thisPage='add';
include('includes/navbar.inc.php');
?>
<h1>Add New Inventory Record</h1>
<form method="POST" action="submitadd.php" />
<table id="add">
<tr>
<td class="headings"><b>Species:</b></td>
<td><select name="species:" onchange="showUser(this.value)">
<option value="select">Choose a Species</option>
<?php
$prodquery="SELECT name FROM products ORDER BY name ASC";
$result=mysqli_query($con,$prodquery) or die(mysqli_error($con));
while ($row = mysqli_fetch_array($result)) {
echo "<option value='" . $row['name'] . "'>" . $row['name'] . "</option>";
}
?>
</select>
</td>
</tr>
<div id='txtHint' />
<tr>
<td class="headings"><b>Fry Count:</b></td>
<td><input type="text" name="frycount" value="<?php echo $row['quantityfry']; ?>" size="35" maxlength="4" /></td>
</tr>
<tr>
<td class="headings"><b>Juvie Count:</b></td>
<td><input type="text" name="juviecount" value="<?php echo $row['quantityjuv']; ?>" size="35" maxlength="4" /></td>
</tr>
<tr>
<td class="headings"><b>Adult Count:</b></td>
<td><input type="text" name="adultcount" value="<?php echo $row['quantityadult']; ?>" size="35" maxlength="4" /></td>
</tr>
<tr>
<td class="headings"><b>Notes:</b></td>
<td><input type="text" name="notes" value="<?php echo $row['notes']; ?>" size="35" maxlength="255" /></td>
</tr>
<tr>
<td class="headings"><b>Location:</b></td>
<td><select name="location">
<?php
$options = set_and_enum_values($con, 'inventory', 'location');
foreach($options as $option):
?>
<option><?php echo $option ?></option>
<?php endforeach; ?>
</select></td>
</tr>
<tr>
<td class="headings"><b>Owner:</b></td>
<td><select name="owner">
<?php
$options = set_and_enum_values($con, 'inventory', 'owner');
foreach($options as $option):
?>
<option><?php echo $option ?></option>
<?php endforeach; ?>
</select></td>
</tr>
</table>
<br />
<input type="submit" name="submit" value="submit" class="button1" />
</form>
</body>
</html>
And here is getsku.php, which is called by the AJAX script:
<?php
$q = html_entity_decode($_GET['q']);
require_once('includes/config.inc.php');
$sql="SELECT sku FROM products WHERE name = '".$q."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result))
{
echo "<td><input type='hidden' name='sku' value='" . $row['sku'] . "' readonly='readonly' size='35' /></td>";
}
mysqli_close($con);
?>
I've been doing some testing in Firebug and here is a specific example. The row of data is:
name = Lethrinops albus "Kande Island"
sku = HAP002
There is other data, but not of a concern for this. So when the dropdown selects Lethrinops albus "Kande Island", I want HAP002 set to a hidden field and passed to the submit button on this form. Using Firebug, I can see this under Params:
q Lethrinops albus "Kande Island"
Which is correct. Here is another row of data:
name = Cynotilapia afra "Lion's Cove"
sku = MBN002
But within Firebug, I see this under Params:
q Cynotilapia afra "Lion
Which is not correct. I'm assuming I need to sanitize the HTML result, and I found a function that may help:
function htmlsan($htmlsanitize){
return $htmlsanitize = htmlspecialchars($htmlsanitize, ENT_QUOTES, 'UTF-8');
}
But I'm not sure if this is what I need, and how to use it. Can anyone point me in the right direction please?
First of all, you should never construct an SQL query this way:
$q = html_entity_decode($_GET['q']);
$sql="SELECT sku FROM products WHERE name = '".$q."'";
It's not a good practice, and there are security issues like SQL Injection
To solve all your sanitations problems (and many others) I recommend you to use PHP Data Objects (PDO) to all your SQL connections.
Especially take a look at this answer How can I prevent SQL injection in PHP?
Use this function mysql-real-escape-string.php to sanitize you input data in MySQL query.
[EDITED]
Answer your question.
The problem is not in your SQL query. It is at <option value='problem is here!'>.
You should use htmlentities to correctly escape the single-quote when name = Cynotilapia afra "Lion's Cove".
echo "<option value='" . htmlentities($row['name']) . "'>" . $row['name'] . "</option>";
You may need to use html_entity_decode to decode (the reverse operation) in getsku.php.
Since you're passing data via GET you need to urlencode() the strings to pass them to the next page. Do not decode them in the next script. The superglobals are already decoded.
Once you're in the next script you should use your DB extension's escape functions to use the $_GET param in your SQL query.
I have a table which has a dynamic content.
the table contains a drop down list, where the user needs to choose an option then the displayed data will be returned using ajax.
currently it's work BUT the problem is that it's working only with the first row.
After l choose from the drop down list in the second row the result was displayed on
the first row :"/ !!
table code
<table class="bordered" >
<tr class="bordered">
<?php
$qry=mysql_query("SELECT *
FROM `order` ");
//Check whether the query was successful or not
$qry1="SELECT *
FROM `order` ";
$result=mysql_query($qry1);
if(mysql_num_rows($qry)>0){
?>
<th>delete</th><th>edit</th><th>staff info</th><th>staff</th><th>ex</th><th>phone</th><th>name</th><th>id</th><th>quantity</th><th>status</th><th>time</th><th>date</th><th>order number</th><th></th>
</tr>
<?php
while($info = mysql_fetch_array( $result ))
{
$idem = $info['emp_id'];
$q="select * from empoyee where emp_id= '".$idem."';";
$r=mysql_query($q);
?>
<tr>
<td>
<form method="POST" action="delete_asu.php">
<input type="image" src="delete1.png" width="25%" height="20%"/>
<input type="hidden" name="delete_id" value="<?php echo $info['order_num']; ?>" />
</form></td>
<td>
<?php $id=$info['order_num'];
echo '<form method="POST" action="update_asu_form.php?id='.$id.'">' ?>
<input type="image" src="settings-24-128.png" width="20%" height="15%"/>
</form></td>
<td id="txtHint"></td>
<td>
<select name="users" onchange="showUser(this.value)">
<option></option>
<?php
$sql=mysql_query("SELECT asu_name from asu_staff");
while($row = mysql_fetch_array($sql)){
echo "<option>" .$row["asu_name"]. "</option>";
}
?>
</select>
</td>
<?php
while($row = mysql_fetch_array( $r ))
{
?>
<td><?php echo $row['ex']; ?></td><td><?php echo $row['phone']; ?></td><td><?php echo $row['emp_name']; ?></td><td><?php echo $row['emp_id']; ?></td>
<?php
}
?>
<td><?php echo $info['quantity']; ?></td><td><?php echo $info['status']; ?></td>
<td><?php echo $info['time']; ?></td><td><?php echo $info['date']; ?></td>
<td><?php echo $info['order_num']; ?></td><td><input type="radio" name="choose" value="<?php echo $info['order_num']; ?>" /></td>
</tr>
<?php
}
}
else echo "<h1>no orders</h1>";
?>
</table>
The ajax code
<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 (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
The php code
$q=$_GET["q"];
$sql="SELECT * FROM asu_staff WHERE asu_name = '".$q."'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo "<table>";
echo "<tr> <td>" . $row['asu_id'] . " </td><td>staff id</td></tr>";
echo "<tr> <td>" . $row['phone'] . " </td><td>staff phone</td></tr>";
echo "</table>";
Yaaah It's work
the idea:
Alhamdullilallah it's working perfectly now :D
the problem was from the id of the where I retrieve the content
I make an incremental id and send it to the ajax , then it's work
The value that is given by the select is what is in the value="" attribute on each option. In your case you need to change the code displaying the options to:
<select name="users" onchange="showUser(this.value)">
<option value="" selected></option>
<?php
$sql=mysql_query("SELECT asu_name from asu_staff");
while($row = mysql_fetch_array($sql)){
echo "<option value=\"".$row["asu_name"]."\">" .$row["asu_name"]. "</option>";
}
?>
</select>
Try this.
p.s. you could select an id with the name in your query, then use the id in the value="" attribute. Your query in your php code could then use the id in stead of the name.
I have this html form:
<form method="post">
<input type="radio" name="news" id="new" value="nuova" onchange="newstype(this.id);">Nuova News
<input type="radio" name="news" id="mod" value="modifica" onchange="newstype(this.id);">Modifica News
<select name="news" id="modifica" style="display:none" onchange="shownews(this.value)">
<?php
include "../flock/sql.php";
$connection = new mysqli($host, $user, $pw, $db) or die("Impossibile connettersi");
$querylistanews = "SELECT * FROM NEWS ORDER BY id DESC";
$listanews = $connection->query($querylistanews);
print '<option>Seleziona una news...</option>';
while ($newsdamodificare = $listanews->fetch_object()) {
print '<option value="'.$newsdamodificare->id.'">'.$newsdamodificare->data." - ".$newsdamodificare->title.'</option>';
}
$listanews->close();
$connection->close;
?>
</select>
</form>
this javascript:
function newstype(param) {
if(param == 'new') {
document.getElementById('crea').style.display = 'inline';
document.getElementById('modifica').style.display = 'none';
document.getElementById('newsdamodificare').style.display = 'none';
} else {
if(param == 'mod') {
document.getElementById('crea').style.display = 'none';
document.getElementById('modifica').style.display = 'inline';
document.getElementById('newsdamodificare').style.display = 'inline';
}
}
}
function shownews(str) {
if (str=="") {
document.getElementById("newsdamodificare").innerHTML="";
return;
}
if (window.XMLHttpRequest) { // codice per IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // codice per IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("newsdamodificare").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","modifica.php?news="+str,true);
xmlhttp.send();
}
and this php:
<head>
<script type="text/javascript" src="../editor/ckeditor.js"></script>
<script type="text/javascript" src="/js/charscounter.js"></script>
</head>
<?php
$news=$_GET["news"];
include "../flock/sql.php";
$connection = new mysqli($host, $user, $pw, $db) or
die('Impossibile connettersi al database: ' . mysql_error());
$newsdaldatabase="SELECT * FROM NEWS WHERE id = '".$news."'";
$result = $connection->query($newsdaldatabase);
$count = mysqli_num_rows($result);
if($count==1){
while($dati = mysqli_fetch_array($result)) {
$id = $dati['id'];
$data = $dati['data'];
$title = $dati['title'];
$body = $dati['body'];
}
} else {
die('Errore del sistema. PiĆ¹ di una news selezionate: ' . mysql_error());
}
mysqli_close($connection);
?>
<div class="normal" id="modifica">
<table style="width:100%;height:100%;">
<tr>
<td colspan="3" border="0">
<strong class="confirm">Modifica news</strong>
</td>
</tr>
<tr>
<td width="107" align="right">
<strong>Data</strong>
</td>
<td colspan="2">
<form name="modificanews" method="post" action="italiano.php?modifica=yes">
<input name="idmodificanews" type="text" style="display:none" value="<?php echo $id ?>">
<input name="datanewsmodificata" type="text" maxlength="10" size="8" value="<?php echo $data ?>"> gg.mm.aaaa
</td>
</tr>
<tr>
<td align="right">
<strong>Titolo</strong>
</td>
<td width="360">
<input name="modificatitolo" type="text" maxlength="50" size="50" value="<?php echo $title ?>" onKeyPress="return taLimit(this)" onKeyUp="return taCount(this,'myCounter')">
</td>
<td width="522">
<b><span id=myCounter>50</span></b> caratteri rimanenti per il titolo</font>
</td>
</tr>
<tr>
<td colspan="3">
<textarea name="modificatesto"><?php echo $body ?></textarea>
<script>
CKEDITOR.replace('modificatesto');
</script>
</td>
</tr>
All is working quite well, except one thing:
when I select the news to edit, the content is from the server is correcly posted on the php, but on the HTML the scripts in the php (CKEDITOR and Char Cunter) are not active.
So, on my HTML, were the user will edit the news, i get only a simple textarea instead of the CKEDITOR, etc.
Is there a way to fix that? Can you help me somehow?
Thank you!
EDIT: I solved by myselft the problem. See solution as answer.
For those who have the same question:
I solved my problem in the following way: on javascript add a new row:
document.getElementById("newsdamodificare").action=CKEDITOR.replace('modificatesto');
between this 2 lines:
document.getElementById("newsdamodificare").innerHTML=xmlhttp.responseText;
NEW LINE TO INSERT HERE
}
And remove from the php these rows:
<script>
CKEDITOR.replace('modificatesto');
</script>
Hope this helps!
You're trying to select your textarea by it's name, but CKEDITOR.replace('modificatesto'); is looking for an ID.
Try
<textarea id="modificatesto"><?php echo $body ?></textarea>
<script>
CKEDITOR.replace('modificatesto');
</script>
<table border="1">
<tr>
<th>
SR No.<br />
</th>
<th>
Name
</th>
<th>
Address
</th>
<th>
Area
</th>
<th>
City
</th>
<th>
Contact No.
</th>
<th>
Volunteer List
</th>
<th>
Bird Namea
</th>
<th>
Status
</th>
<th>
Send SMS
</th>
</tr>
<?php
while($row = mysql_fetch_array($pager->result))
{
?>
<tr>
<td>
<?php echo $row['InqID']; ?>
</td>
<td>
<?php echo $row['InqFromName']; ?>
</td>
<td>
<?php echo $row['InqFromAddress']; ?>
</td>
<td>
<?php echo $row['InqArea']; ?>
</td>
<td>
<?php echo $row['InqCity']; ?>
</td>
<td>
<?php echo $row['InqContactNo']; ?>
</td>
<td>
<select name="volunteerSelect1" id="volunteerSelect1">
<option value="" selected="selected">Please Select Volunteer</option>
<?php
$select="SELECT * FROM tran_ngovolent where ngovolentNGOCode=".$ngoSelectId;
//echo $select;
$result=mysql_query($select);
while($rowBird=mysql_fetch_array($result))
{
echo"<option value=".$rowBird['ngovolentMobile']." id='volmobile'>".$rowBird['ngovolentName']."</option>";
}
?>
</select>
</td>
<td>
<?php
$birdID=$row['InqBirdType'];
$birdSelect="SELECT Bird_Name FROM mst_bird WHERE Bird_Code=".$birdID;
$result=mysql_query($birdSelect);
while($bird_name=mysql_fetch_array($result))
{
$birdname=$bird_name['Bird_Name'];
echo $birdname;
}
?>
</td>
<td>
<?php
$inqStatus=$row['InqStatus'];
if($inqStatus==0)
{
echo "<a href='index.php?id=".$row['InqID']."&status=status&page=".$pageid."' onclick='return confirmAction()'>Pending</a>";
}else
{
echo "Finished";
}
?>
</td>
<td>
<input type="button" name="SendSMS" value="Send SMS" onclick="smsNgo(<?php echo $birdID;?>,<?php echo "'".$row['InqFromAddress']."'";?>,<?php echo "'".$birdname."'";?>,<?php echo "'".$row['InqCity']."'";?>,<?php echo "'".$row['InqArea']."'";?>,<?php echo "'".$row['InqFromName']."'";?>,<?php echo "'".$row['InqContactNo']."'";?>);return sms()"/>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="10">
<?php echo $pager->show(); ?>
</td>
</tr>
</table>
In this Program i get value from database in my selection box. show this image
In first selection box i got perfect out put in my JavaScript but other one selection box value is null or empty Here is my JavaScript and Ajax code.
function smsNgo(birdno,address,birdname,city,area,name,contact)
{
//document.write(mobile1);
var ngocontact = document.getElementById("volunteerSelect1").value;
//var ngocontact = selectElement.options[selectElement.selectedIndex].value;
var xmlhttp;
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 (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//document.getElementById("smsStatus").innerHTML=xmlhttp.responseText;;
window.open("http://localhost/goal_bird/admin/edit.php","_self");
}
}
var url="http://www.****.co.in/sendsms.aspx?mobile=******&pass=******& senderid=SMSIdea&to="+ngocontact+"&msg=Bird id is "+birdno+" "+birdname+" "+name+" "+address+" "+area+" "+city+" "+contact;
document.write(url);
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send();
setTimeout("location.href='index.php'",2000);
}
You can make the volunteerSelect1 name unique by adding some db unique id with it. May be InqID in this case?
<select name="volunteerSelect_<?php echo $row['InqID']; ?>"
id="volunteerSelect_<?php echo $row['InqID']; ?>">
From a glance, i can see the name="" for all the <select> tags are the same... "volunteerSelect1"
try using something like volunteerSelect[id] or volunteerSelect[]
The SAME thing applies to the id="" attribute, they are all using the same ID, this is used by javascript to identify a particular DOM item
However you cant use [] in the id try volunteerSelect_ID
That's probably the problem, the ID attribute
modify this <select name="volunteerSelect1" id="volunteerSelect1"> to this
<select name="volunteerSelect1" id="volunteerSelect<?php echo $row['InqID']; ?>">
then this <input type="button" name="SendSMS" value="Send SMS" onclick="smsNgo(<?php echo $birdID;?>,<?php echo "'".$row['InqFromAddress']."'";?>,<?php echo "'".$birdname."'";?>,<?php echo "'".$row['InqCity']."'";?>,<?php echo "'".$row['InqArea']."'";?>,<?php echo "'".$row['InqFromName']."'";?>,<?php echo "'".$row['InqContactNo']."'";?>);return sms()"/>
to this
<input type="button" name="SendSMS" value="Send SMS" onclick="smsNgo(<?php echo $row['InqID']; ?>,<?php echo $birdID;?>,<?php echo "'".$row['InqFromAddress']."'";?>,<?php echo "'".$birdname."'";?>,<?php echo "'".$row['InqCity']."'";?>,<?php echo "'".$row['InqArea']."'";?>,<?php echo "'".$row['InqFromName']."'";?>,<?php echo "'".$row['InqContactNo']."'";?>);return sms()"/>
then this function smsNgo(birdno,address,birdname,city,area,name,contact)
to this function smsNgo(inqid,birdno,address,birdname,city,area,name,contact)
and finally this var ngocontact = document.getElementById("volunteerSelect1").value;
to this var ngocontact = document.getElementById("volunteerSelect" + inqid).value;
Basically, what I did that i added an unique identifier to each selectbox according to inqid. Then I call function smsNgo with this ID and select the right selectbox :)
Since you tagged this as jquery. so to get the value from select dropdown, you will use something like this