i am using below code, Its displaying the ??? only in place of result. Can you please help me out to correct the error in the below form ? message is displaying the blank result like in ?? format. any help ? --
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="12%"> </td>
<td width="2%"> </td>
<td width="2%"> </td>
<td width="2%"> </td>
<td width="16%"> </td>
<td width="66%"> </td>
</tr>
<tr>
<td><img src="images/australia1.jpg" width="132" height="70"></td>
<td> </td>
<td> </td>
<td> </td>
<td><select name="select">
<option>Select Course Type</option>
<option>Under Graduate</option>
<option>Post Graduate</option>
</select>
</td>
<td><div id="message"></div></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<script type="text/javascript" language="javascript">
var messages = {
Under Graduate: 'UG text is here',
Post Graduate: 'PG text is here'
}
$('select').change(function() {
$('#message').text(messages[$(this).val()]);
});
</script>
<script type="text/javascript" language="javascript">
var messages = {
under: 'UG text is here',
post: 'PG text is here'
}
$('select').change(function() {
if($(this).val() != '')
$('#message').text(messages[$(this).val()]);
});
</script>
<select name="select">
<option value="">Select Course Type</option>
<option value="under">Under Graduate</option>
<option value="post">Post Graduate</option>
</select>
You have syntax errors in your message object. You need to use quotes around keys that have spaces in them:
var messages = {
'Under Graduate': 'UG text is here',
'Post Graduate': 'PG text is here'
}
i think you just missing value attribute and use one-word identifier
<option vale="under_graduate">Under Graduate</option>
var messages = {
under_graduate: 'UG text is here',
val1: 'PG text is here'
}
</script>
try this
<script type="text/javascript" language="javascript">
$('#select').change(function() {
var selectVal = $('#select :selected').val();
$(#message).text(selectVal);
});
</script>
and replace
<select name="select">
by
<select id="select">
Related
I have design a dynamic html table and it contains 2 table columns :
column1: Item Name. It comes from selected option.
column2: Item Price. It comes from selected option value.
Right now I am selecting option in first column and passing value into input field in second column. After adding as many rows I need, I want to pass both their text and value in php.
But php is getting only option value instead of having both text and value.
Here is my code
$('#myTable').on('change', '.mySelect', function() {
// you can use .closest() to find
// particular input on same row with select
$(this).closest('tr').find('.amount').val($(this).val());
//$(this).closest('tr').find('.mySelect').val($(".mySelect option:selected").text());
});
$('#myTable').on('click','.remScnt', function(e) {
e.preventDefault();
// find the tr element of remove link
// which is a parent
$(this).closest('tr').remove()
});
$(".mySelect option").filter(function() {
//may want to use $.trim in here
return $(this).text() == $(this).val();
}).prop('selected', true);
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<style>
table, th, td {
border-collapse: collapse;
margin: 10px auto;
}
</style>
<script>
function addMore() {
var table = document.getElementById("myTable");
var row = table.insertRow(-1);
var cell1 = row.insertCell(-1);
var cell2 = row.insertCell(-1);
var x = document.getElementById("myTable").rows[1].cells;
cell1.innerHTML = x[0].innerHTML;
cell2.innerHTML = x[1].innerHTML;
}
function removeLast() {
document.getElementById("myTable").deleteRow(-1);
}
function removeRowNo() {
var index = document.getElementById('value').value
document.getElementById("myTable").deleteRow(index);
}
</script>
</head>
<body>
<form action="testlist.php" method="post">
<table>
<tr>
<td>
Month:
</td>
<td>
<select name="SALMT" id="month" onchange="" size="1">
<option value="" disabled selected>Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</td>
<td>
Year:
</td>
<td> <input type="text" name="SALYR">
</td>
</tr>
<tr>
<td>
Employee ID:
</td>
<td> <input type="text" name="EMPID">
</td>
<td>
Name:
</td>
<td><input type="text" name="NM">
</td>
</tr>
<tr>
<td>
Department Code:
</td>
<td> <input type="text" name="DPTID">
</td>
<td>
Designation:
</td>
<td><input type="text" name="DSG">
</td>
</tr>
</table>
<table id="myTable">
<tr>
<th>Items</th>
<th>Amount</th>
</tr>
<tr>
<td >
Remove
<select class="mySelect" name="DESCRP[]" >
<option disabled="" selected="">Select</option>
<option value="100">Item-1</option>
<option value="200">Item-2</option>
<option value="300">Item-3</option>
<option value="400">Item-4</option>
<option value="500">Item-5</option>
</select>
</td>
<td> <input type="text" class="amount" name="ALAMT[]"></td>
</tr>
</table>
<table>
<tr>
<td><input type="submit" /> </td>
</tr>
</table>
</form>
<br>
<table>
<tr>
<td><button onclick="addMore()">Add More</button></td>
<td><button onclick="removeLast()">Remove Last Row</button></td>
</tr>
<tr>
<td><input type="text" maxlength="3" name="value" id='value'></td>
<td><button onclick="removeRowNo()">Remove By Row No.</button></td>
</tr>
</table>
</body>
</html>
Here is php code:
<?php
var_dump($_POST);
echo "<br>";
echo count($_POST["DESCRP"]);
foreach ($_POST["DESCRP"] as $d) {
echo "<br>";
echo $d;
}
echo "<br>Amount:";
echo count($amount = $_POST["ALAMT"]);
foreach ($_POST["DESCRP"] as $a) {
echo "<br>";
echo $a;
}
?>
You mean
<td>
<select class="mySelect">
<option value="">Select</option>
<option value="100">Item-1</option>
<option value="200">Item-2</option>
<option value="300">Item-3</option>
<option value="400">Item-4</option>
<option value="500">Item-5</option>
</select>
<input type="hidden" class="descr" name="DESCRP[]" />
</td>
<td> <input type="text" class="amount" name="ALAMT[]"></td>
using
$('#myTable').on('change', '.mySelect', function() {
$(this).closest('tr').find('.amount').val($(this).val());
$(this).closest('tr').find('.descr').val($("option:selected",this).text());
});
For DESCRP[0] = item-1, DESCRP[1] = item-5
modify the select as follows :
<option value="Item-1" data-val="100">Item-1</option>
$('#myTable').on('change', '.mySelect', function() {
$(this).closest('tr').find('.amount').val($(this).attr('data-val'));
});
When I select one of the choice in the datalist, I want the textfield to be auto filled. I have this code but it does not work. Sorry my English is not good
<tr>
<td width="15%"><div class="tabtxt">Pilih Pembayaran</div></td>
<td width="2%"><div class="tabtxt">:</div></td>
<td width="83%">
<input list="bayar" name="bayar" style="width: 203px">
<datalist id="bayar">
<option value="Visual Basic Islam">
<option value="Baitul Arqam">
<option value="Shortcourse">
<option value="Sertifikasi">
<option value="Seminar SID">
<option value="TOEFL & Bahasa Inggris">
</datalist>
</td>
</tr>
<tr>
<td width="15%"><div class="tabtxt">Kode Pembayaran</div></td>
<td width="2%"><div class="tabtxt">:</div></td>
<td width="83%">
<input name="id_bayar" style="width: 200px" type="text" class="tfield" id="id_bayar">
<script type="text/javascript">
$("#bayar").change(function(){
var in = $("#bayar").val();
$("id_bayar").val("hallo");
});
</script>
</td>
</tr>
How do I solve this? Thanks for the answers
Firstly add an id ,for example inbayar, to the input element:
<input id="inbayar" list="bayar" name="bayar" style="width: 203px">
They, you have to bind this html5 element's event like that:
$(document).ready(function () {
$("#inbayar").bind('input', function () {
$("#id_bayar").val(this.value);
alert("Working!");
});
});
Working solution here http://jsfiddle.net/csdtesting/gk3r8da9/
Revision solution asked vol.1 http://jsfiddle.net/csdtesting/gk3r8da9/1/
<table>
<tr>
<td width="15%"><div class="tabtxt">Pilih Pembayaran</div></td>
<td width="2%"><div class="tabtxt">:</div></td>
<td width="83%">
<select id="bayar">
<option value="Visual Basic Islam">Visual Basic Islam</option>
<option value="Baitul Arqam">Baitul Arqam</option>
<option value="Shortcourse">Shortcourse</option>
<option value="Sertifikasi">Sertifikasi</option>
<option value="Seminar SID">Seminar SID</option>
<option value="TOEFL & Bahasa Inggris">TOEFL & Bahasa Inggris</option>
</select>
</td>
</tr>
<tr>
<td width="15%"><div class="tabtxt">Kode Pembayaran</div></td>
<td width="2%"><div class="tabtxt">:</div></td>
<td width="83%">
<input name="alert();" style="width: 200px" type="text" class="tfield" id="id_bayar">
</td>
</tr>
</table>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#bayar").on('change',function(){
var a = $("#bayar").val();
$("#id_bayar").val(a);
});
});
</script>
I want to display the selected price, category and size on the dropdown slideingDiv. But what I have done below is not working. I have try to echo out to see if the data have been sent thought but I got nothing. Is anything wrong with my code?
Script
<script type="text/javascript">
$(document).ready(function () {
$(".slidingDiv").hide();
$(".show_hide").show();
$('.show_hide').click(function () {
$(".slidingDiv").slideToggle();
});
});
</script>
Button
<button a href="product.php?ProdID=<?php echo $id; ?>" class="show_hide" id="button" name="button">Add to cart</a></button>
PHP
<?php
dbconnect();
if(isset($_POST['pid']) && isset($_POST['length']) && isset($_POST['Qty']) && `isset($_POST['Category'])){`
$pid = $_POST['pid'];
$length = $_POST["length"];
$qty = $_POST['Qty'];
$Category = $_POST['Category'];
echo $pid; // I have add this echo to see data have been passed though but i get nothing in return
echo $length;
$stmt4 = $conn->prepare("
SELECT Product.Name as ProductName, Category.Name, size, Price
FROM item_Product, Product, Category
WHERE Product.ProdID =:pid
AND size= :length AND Category.Name = :Category Limit 1");
$stmt4->bindParam('pid',$pid);
$stmt4->bindParam('length',$length);
$stmt4->bindParam('Category',$Category);
$stmt4->execute();
foreach ($stmt4->fetchAll(PDO::FETCH_ASSOC) as $row4 ) {
$product_name = $row4["ProductName"];
$price = $row4["Price"];
$length = $row4["size"];
$Category = $row4["Name"];
?>
Item was added shopping bag </br>
Name:<?php echo $row4['ProductName']; ?> </br>
Length:<?php echo $row4['size']; ?> </br>
Category:<?php echo $row4['Name']; ?> </br>
Price:<?php echo $row4['Price']; ?> </br>
<?php } }
?>
View Cart
</div>
TABLE
<td width="160">Price:</td>
echo '<td name="pricetag" id="pricetag">'.$row2['Price'].'</td>';
</tr>
<tr>
<td>Category</td>
<td>
<select id="Category" name="Category">
echo '<option value="'.$row['Name'].'">'.$row['Name'].'</option>';
</select>
</td>
</tr>
<tr>
<td width="160">Length:</td>
<td>
<select name="length" id="length">
<option SELECTED value="'.$row3['size'].'">'.$row3['size'].</option>
</select>
</td>
</tr>
<tr>
<td>Quantity</td>
<td><input type="text" name="Qty" id="Qty" value="1" style="width: 20px; text-align: right" /></td>
</tr>
</table>
<div class="cleaner h20"></div>
<input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />
<div class="button">
<button class="show_hide" id="button" name="button">Add to cart</button>
</div>
Try this: SEE MY FIDDLE
HTML
<table>
<tr>
<td>Price</td>
<td>
<select id='priceTag'>
<option value='p1'>price 1</option>
<option value='p2'>price 2</option>
</select>
</td>
</tr>
<tr>
<td>Category</td>
<td>
<select id='Category'>
<option value='c1'>cat 1</option>
<option value='c2'>cat 2</option>
</select>
</td>
</tr>
<tr>
<td>Size</td>
<td>
<select id='Size'>
<option value='s1'>size 1</option>
<option value='s2'>size 2</option>
</select>
</td>
</tr>
</table>
<button id='button'>Submit</button>
<div id='selected'>
<table cellpadding="5" border='1'>
<tr>
<td>Price:</td>
<td id='sprice'></td>
</tr>
<tr>
<td>Category:</td>
<td id='scat'></td>
</tr>
<tr>
<td>Size:</td>
<td id='ssize'></td>
</tr>
</table>
</div>
JQuery
$(document).ready(function()
{
$('#selected').hide();
$('#button').click(function()
{
var price = $('#priceTag').val();
var cat = $('#Category').val();
var size = $('#Size').val();
$('#sprice').text(price);
$('#scat').text(cat);
$('#ssize').text(size);
$('#selected').slideDown();
});
});
Seems that you do not have a space in your <?php} ?>
Do something like <?php } ?>
Error:
<?php} ?>
try this,
<?php } ?> // add space between php and }
<?php}
should be
<?php }
Also
<button a href="product.php?ProdID=<?php echo $id; ?>" class="show_hide" id="button" name="button">Add to cart</a></button> is in correct
should be
<button>Add to cart</button>
I need to check when a select tag's value change if it is equal to say "NA" if so it needs to change the other select tag's value to something different and or disable it?
I am working with php. If there is a way in php let me know. Please
<html>
<center>
<title>Testing</title>
<head>
<script>
function closeWin()
{
alert('Posted');
window.open('', '_self', '');
window.close();
}
//Function to test value and change value
function value()
{
if (Question4DDL == 'NA')
{
Question5DDL == 'NA'
}
{
}
</script>
</head>
<form name="input" action="index.php" method="post" >
<body>
<div id="Questions">
<table>
<tr><td>
<div id="Q1">Subscribed to service provider?</div>
</td>
<td>
<select Name="Question1DDL">
<option value = 'BLANK'></option>
<option value = 'YES'>YES</option>
<option value ='NO'>NO</option>
</select>
</td>
</tr>
<tr>
<td>
<div id="Q2">Which provider are you currently with?</div>
</td>
<td>
<select Name="Question2DDL">
<option value = 'BLANK'></option>
<option>t1</option>
<option>t2</option>
<option>t3</option>
</select>
</td>
</tr>
<tr>
<td>
<div id="Q3">Type of dwelling/premisis?</div>
</td>
<td>
<select Name="Question3DDL">
<option value = 'BLANK'></option>
<option>CLUSTER</option>
<option>FLAT</option>
<option>PLOT</option>
<option>TOWNHOUSE</option>
<option>FARM</option>
</select>
</td>
</tr>
<tr>
<td>
<div id="Q4">Alarm in working order?</div>
</td>
<td>
//select tag in question.
<select Name="Question4DDL" onchange="value()">
<option value = 'BLANK'></option>
<option>YES</option>
<option>NO</option>
<option value = 'NA'>(N/A) - No Alarm</option>
</select>
</td>
</tr>
<tr>
<td>
<div id="Q5">Age of alarm?</div>
</td>
<td>
<select Name="Question5DDL">
<option value = 'BLANK'></option>
<option>-1</option>
<option>-3</option>
<option>+3</option>
</select>
</td>
</tr>
<tr>
<td>
<div id="Q6">Paying more than R350 per month?</div>
</td>
<td>
<select Name="Question6DDL"><option value = 'BLANK'></option>
<option>YES</option>
<option>NO</option>
</select>
</td>
</tr>
<tr>
<td>
<div id="Q7">Is the prospect in a known response area? (Have they seen sign boards in their area?)</div>
</td>
<td>
<select Name="Question7DDL">
<option value = 'BLANK'></option>
<option>YES</option>
<option>NO</option>
</select>
</td>
</tr>
<tr>
<td>
<div id="Q8">Request site visit from agent?</div>
</td>
<td>
<select Name="Question8DDL">
<option value = 'BLANK'></option>
<option>YES</option>
<option>NO</option>
</select>
</td>
</tr>
<tr>
<td>
</td>
<td>
<textarea name="comments" rows="5">
</textarea>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input name="sb1" type="submit" value="Submit" onClick="closeWin()">
</td>
</tr>
</table>
</div>
</body>
</form>
</center>
</html>
first you get user input which is select by user.
After that using that input you will used if condition like if service provider is yes then execute if loop and display other option that you want to display otherwise follow further procedure you will provide.
I don't know PHP so here i give description otherwise i make code that first get user input and then proceed.
I have 2 tables one is category and one is products. Now I want to PC calculator.
I have all the fields generated dynamically based on the database. So how can I write script to make like this.
<table ALIGN=CENTER WIDTH=100% BORDER=1 CELLSPACING=1 CELLPADDING=3>
<tr>
<th>Category Name</th>
<th>Product Name</th>
<th>Price</th>
</tr>
<tr class="odd">
<td>Speaker</td>
<td>
<select name="1" size="1" id="1">
<option value="1200.00">intex</option>
<option value="2100.00">creative</option>
<option value="1400.00">intex 2.1</option>
<option value="2000.00">intex 2.1 with woofer</option>
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Laptop</td>
<td>
<select name="3" size="1" id="3">
<option value="31000.00">sony</option>
<option value="31500.00">hp</option>
<option value="31000.00">Acer</option>
<option value="36000.00">ibm</option>
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Mouse</td>
<td>
<select name="4" size="1" id="4">
<option value="120.00"> teccom</option>
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>CPU</td>
<td>
<select name="6" size="1" id="6">
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Projector</td>
<td>
<select name="7" size="1" id="7">
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Anti Virus</td>
<td>
<select name="23" size="1" id="23">
<option value="450.00">McAfee</option>
<option value="1200.00">AVG</option>
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Processor</td>
<td>
<select name="59" size="1" id="59">
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>testing</td>
<td>
<select name="60" size="1" id="60">
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>sadfasdfasdfadsfad</td>
<td>
<select name="61" size="1" id="61">
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>dfgd</td>
<td>
<select name="62" size="1" id="62">
</select>
</td>
<td><div id="t1" class="price">0</div></td>
</tr>
<tr>
<td></td>
<td>Total</td>
<td><div id="total"></div></td>
</tr>
</table>
here is jQuery
jQuery(document).ready(function() {
$("#sellp").change(function () {
var str = 0.00;
$("#sellp :selected").each(function () {
var test = $(this).val();
//alert(test);
var tr = parseInt(str) + parseInt(test);
//alert(tr);
$("#t1").text(test);
});
});
var sum = 0;
$("form :element").change(function() {
$('.price').each(function() {
sum += parseFloat($(this).text());
});
$('#total').html(sum) });
});
Firstly show some code.
Assuming all items are in the page when it loads, you need to add some event handlers
Here is plain JS - jQuery may be more elegant. You will likely need to start with this and then add the validation. You will make your life much easier if you name your fields in a way that is easy to get to
<html>
<head>
<script>
function calc(theForm) {
var total = 0;
for (var i=1;;i++) {
var item = theForm.elements["item_"+i];
if (item) {
var price = item.options[item.selectedIndex].value;
if (price && !isNaN(price)) {
price = parseFloat(price);
total+=price;
var priceId = item.id.replace('item','price');
document.getElementById(priceId).innerHTML=price.toFixed(2);
}
}
else break;
}
if (total) document.getElementById('total').innerHTML="$"+total.toFixed(2);
}
window.onload=function() {
var theForm = document.forms[0]; // first form on page
for (var i=0,n=theForm.elements.length;i<n;i++) {
if (theForm.elements[i].type.indexOf("select") !=-1) {
theForm.elements[i].onchange=function() { calc(this.form); }
}
}
theForm.onsubmit=function() { calc(this); return validate(this) }
calc(theForm)
}
</script>
</head>
<body>
<form>
<table ALIGN=CENTER WIDTH=100% BORDER=1 CELLSPACING=1 CELLPADDING=3 >
<tr>
<th>Category Name</th>
<th>Product Name</th>
<th>Price</th>
</tr>
<tr class="odd">
<td>Speaker </td>
<td><select name="item_1" size="1" id="item_1">
<option value="1200.00"> intex</option>
<option value="2100.00"> creative</option>
<option value="1400.00"> intex 2.1</option>
<option value="2000.00"> intex 2.1 with woofer</option>
</select>
</td>
<td><div id="price_1" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Laptop </td>
<td><select name="item_2" size="1" id="item_2">
<option value="31000.00"> sony</option>
<option value="31500.00"> hp</option>
<option value="31000.00"> Acer</option>
<option value="36000.00"> ibm</option>
</select>
</td>
<td><div id="price_2" class="price">0</div></td>
</tr>
<tr class="odd">
<td>Mouse </td>
<td><select name="item_3" size="1" id="item_3">
<option value="120.00"> teccom</option>
</select>
</td>
<td><div id="price_3" class="price">0</div></td>
</tr>
</table>
</form>
Total: <span id="total"></span>