I am new to PHP development. I wan to echo the selected value in a container and show it as and 'echo'. In the code <div id="selected_mters_container"></div> have the serial number. A jquery call is made and the selected meter serial number is displayed like shown below
Now i want to save this serial number in a variable. Below is the JQuery
jQuery('#the-mter-id').on('typeahead:selected', function (e, datum) {
$('#selected_mters_container').html('');
$('#metersinventorystore-store_id').val('');
$('#metersinventorystore-historic').val('');
var html = '<div class="selcted-meters"><input type="hidden" name="selected_meters[]" value="'+datum.id+'" />'+datum.meter_serial+'<a onclick="$(this).closest(\'.selcted-meters\').remove()">X</a></div>';
$('#selected_mters_container').append(html);
$('#metersinventorystore-store_id').val(datum.store_id);
$('#the-mter-id').typeahead('val','');
$('#metersinventorystore-historic').val(datum.historic);
});
As a newbie I don't know how to do it
Any help would be highly appreciated
Try :
var theVALUE = $('#selected_mters_container').html();
alert(theVALUE);
Related
To start off, sorry if this is a duplicate, or explained already. I've read a minimum of 15 other topics that I assumed are similar to mine, yet I haven't had any success in getting it to work.
I currently have a form that is action="submit.php". The form is an order form (see Jfiddle link at bottom of post). Inside submit.php I'm making an array of all $_POST values. That works great. Now the problem:
On the forum page (where user inputs), I have the following JQuery script that calculates totals. There are 3 types of totals (all this is clear in the JFiddle). The 3rd total, called "overallTotal", takes the sum of all "grandTotal"s and as of now, puts in #overallTotal ID. I need that number to be included in the form submission (i.e., so it is accessible by $_POST).
Thanks in advance, and sorry again if this is repetitive.
JSFiddle: http://jsfiddle.net/rc694dzL/
function oninput(e) {
// process this row first
var row = $(e.target).closest("tr");
// explicitly cast to a number
var quantity = +$(e.target).val();
var price = +row.find(".val1").text();
var output = row.find(".multTotal");
var total = price * quantity;
output.text(total);
// now calculate total
var subtotal = 0;
var table = $(e.delegateTarget);
table.find(".multTotal").each(function () {
subtotal += (+$(this).text());
});
table.find(".grandTotal").text(subtotal);
// now calculate overall total
var overallTotal = 0;
$(document).find(".grandTotal").each(function () {
overallTotal += (+$(this).text());
});
$('#overallTotal').text(overallTotal);
Add a hidden input in your form like this
<input type="hidden" name="overallTotal" id="overallTotalInput">
and set the value from javascript like this
$('#overallTotalInput').val(overallTotal);
Now when submitting the form, the value will be stored into $_POST['overallTotal']
Add some hidden fields in the form, and then populate the values with jquery.
Edit: tweaking your Fiddle now with an example: http://jsfiddle.net/dozecnp6/1/
1) Added the hidden input in the form:
<input type="hidden" name="OverallTotal" id="overallTotalField">
2) Added a bit to your oninput() function:
$('#overallTotalField').val(overallTotal);
in this fiddle i can use type="text" you can change it to type="hidden"
check this
fiddle
I have a function that listens for onkeyup event, that onkeyup checks to see if a box has a value and if not blank is supposed pull the value of an elementID which is a phone number called from another page. It takes that value and inserts it in to a snippet of html that gets sent to another elementID. the folowing code is the function and the associated code.
<script language="javascript">
function monthlycheck() {
var mnthchk = document.getElementById("mdamountBox");
var cancelPhone = document.getElementById("cancelphoneLabel");
document.getElementById("cancelphonelistLabel").value = cancelPhone; <--gives the is null error
if(mnthchk.value!=""){
var newHTML = "<span style='color:#24D330'> Your Monthly pledge in the amount of $__ is valid and will be deducted this time every month<br> untill you notify us of its cancellation by calling <label id='cancelphonelistLabel'> </label>";
" </span>";
document.getElementById("mnthlychkdiscoLabel").innerHTML = newHTML;
}
}
</script>
<label id="mnthlychkdiscoLabel"> </label> <---this is where the final data is to be displayed
<label id="cancelphoneLabel">1-800-555-1111</label> <--- this is the phone number pulled from another page,
all the data is pulled together in a single page when loaded but is written in separate page using smarty templates. I keep getting the entitled error and have tried a number of different things to fix it but im stumped any help is greatly appreciated.
here is a jfiddle http://jsfiddle.net/rn5HH/
I think you are trying to access that id before it's created.
Also .value is only for inputs. It looks like you are creating a label, so you'd use innerHTML instead.
Something like this:
<script language="javascript">
function monthlycheck() {
var mnthchk = document.getElementById("mdamountBox");
var cancelPhone = document.getElementById("cancelphoneLabel");
if(mnthchk.value!=""){
var newHTML = "<span style='color:#24D330'> Your Monthly pledge in the amount of $__ is valid and will be deducted this time every month<br> untill you notify us of its cancellation by calling <label id='cancelphonelistLabel'> </label></span>";
document.getElementById("mnthlychkdiscoLabel").innerHTML = newHTML;
document.getElementById("cancelphonelistLabel").innerHTML = cancelPhone; //<--gives the is null error
}
}
</script>
<label id="mnthlychkdiscoLabel"> </label> <---this is where the final data is to be displayed
<label id="cancelphoneLabel">1-800-555-1111</label> <--- this is the phone number pulled from another page,
I'm not 100% what you are trying to do, so i just tried to make it work. There are many things you could probably simplify in this. It would help if you could create a jsfiddle to show it more clearly.
Edit:
Fixed the fiddle so it works and shows the phone number:
updated fiddle
Is that what it's supposed to do?
I have a form with a table which has 5 rows and 8 columns. This table represents the available seats in a concert hall. After the submit button is clicked, a javascript function is called, which at the moment is this:
<script>
function submit_tickets(form){
var count=0;
var booked_seats=new Array();
var c = document.getElementById(form).getElementsByTagName('input');
for (var i = 0; i < c.length; i++) {
if (c[i].type == 'checkbox' && c[i].checked==true){
booked_seats[count]=c[i].id;
count++;
//create an array with the booked seats' ID
}
}
//alert(booked_seats.length);
} </script>
When this function is called, I want at the same time the table of the localhost database to be updated (a table which contains all the 40 seatIDs) depending on the seats that were booked.
How can I do this, can you help me?
if you'd like to i can write example in native javascript, but for now i'll try to do it using jQUery.
function submit_tickets(form){
var seats=[];
$(form).find("input:checked").each(function(){
seats.push($(this).val());//i hope you do have a value for your input tags, and if not, then push $(this).attr('id') - but highly recommend you to follow w3c
});
$.post("your/url/to/server",{seats:seats},function(data){
console.log(data);//some info from server
})
}
I believe you need to call a php file using PHP, in which the database update is done. You might consider using jquery ajax, as in http://api.jquery.com/jQuery.ajax/
I have a site that appends a textbox to a div when the user clicks a button. The textbox works great. Now, I would like to generate a unique number for the id of each box. The following code is giving me 0 as the id of each box. I'm trying to get them to go 1,2,3,4...
Code:
<?php $x=0; ?>
$("#add").click(function(){
$('#boxes').append(<input type="text" id="<?php echo $x; $x++; ?>">);
});
PHP code is excuted earlier before the javascript code is executed. But in your code example you try to execute both at the same time. That is just not the case.
Instead of a PHP variable you need to use a javascript variable:
var x = 0;
$("#add").click(function() {
$('#boxes').append('<input type="text" id="' + ++x + '">');
});
You can use PHP variable as base for your javascript variable or just plain javascript.
//note, $x can be anything e.g. 1
var boxID = '<?php echo $x; ?>';
$("#add").click(function(){
//insert new box, increase boxID
$('#boxes').append('<input type="text" id="'+boxID+'">');
boxID++;
});
I have a specific array that php needs to access and write to a file. I also want to be able to call the php to get the array info back. I use JSON.strigify to store the array in a string, but i cant figure out how to send it to a server with php. I have very little php experience and i tried:
<script language="javascript">
var COMMENTS_FOR_DISPLAY = new Array('Have fun with this code: Chris');
// Adds a new comment, name pair to the Array feeding textualizer.
function add_comment() {
// Retrieve values and add them to Array.
var new_comment = $('#kwote').val();
var new_name = $('#name').val();
COMMENTS_FOR_DISPLAY.push(new_comment + ': ' + new_name);
// Reset <input> fields.
$('#kwote').val('');
$('#name').val('');
var arrayAsString = JSON.stringify(COMMENTS_FOR_DISPLAY);
}
$(document).ready(function() {
var txt = $('#txtlzr'); // The container in which to render the list
var options = {
duration: 5, // Time (ms) each blurb will remain on screen
rearrangeDuration: 5, // Time a character takes to reach its position
effect: 'random', // Animation effect the characters use to appear
centered: true // Centers the text relative to its container
}
txt.textualizer(COMMENTS_FOR_DISPLAY); // textualize it!
txt.textualizer('start'); // start
});
</script>
in main.php i put:
<?php
$kwoteString = $_GET["arrayAsString"];
echo $kwoteString;
?>
I used echo to see if i was getting any output,but i wasn't. It could be a very simple fix, maybe im missing a header or something telling my html document to read main.php?? any help would be appreciated!
Use jquery with
$.post(url,params);
there are many tutorials around the web and stack overflow itself.
Here the doc:
http://api.jquery.com/jQuery.post/
you can add a hiddenField and set the string to the hidden field.
php code will read the value from hidden field.