JavaScript

121K

Solutions

41K

Contributors

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and  in almost every mainstream web browser.

Share tech news, updates, or what's on your mind.

Sign up to Post

I need to center the language dropdown field in the footer over mobile on this site https://ccdenver.org/ but it's not working. Any ideas?
0
This is related to this question https://www.experts-exchange.com/questions/29108573/jQuery-click-event-doesn't-get-called.html

I'll go step by step.

1. The solution in that thread worked. I tested it by hardcoding some rows and it worked. Then, I plugged it in my actual code and that worked except that I needed to fix the position of the rows.

I had this code to add the row dynamically

 
var schedule = $('.schedule:last', '#scheduleArea'); 
            var newSchedule = $(schedule).clone(true, false).html();

            // Change the 'Id' of all the elements
          //... some code here

            // Append the new schedule and hide it
	$(schedule).after('<div class="row"> <div class="toggle"> <div class="col-xs-4" style="background-color:rebeccapurple">left</div> </div><div id=Schedules[' + scheduleCurrentIndex + '].Type class="schedule hidden">' + newSchedule + '</div></div>'); 
 

Open in new window


The divs looked like this
d1.png
2. I made a change to the HTML to get the rows correctly. Instead of ".after", I used ".append"

	var schedule = $('.schedule:last', '#scheduleArea'); 
            var newSchedule = $(schedule).clone(true, false).html();

            // Change the 'Id' of all the elements
      //... some code here

			//console.log($(schedule));

            // Append the new schedule and hide it
			//$(schedule).after('<div class="row"> <div class="toggle"> <div class="col-xs-4" style="background-color:rebeccapurple">left</div> </div><div id=Schedules[' + scheduleCurrentIndex + '].Type class="schedule hidden">' + newSchedule + '</div></div>'); //camilla added collapse in per stackoverflow
		    
			
$("#schedgroup").append('<div class="row"> <div class="toggle"> <div class="col-xs-4" style="background-color:rebeccapurple">left</div> </div><div id=Schedules[' + scheduleCurrentIndex + '].Type class="schedule hidden">' + newSchedule + '</div></div>')

Open in new window


Now it looked correctly
d2.png
3. I had the code in the accepted solution above but the divs weren't hiding/displaying
$('.row').on("click", ".toggle", function() {
console.log($(this).parents().children('.schedule'));
    $(this).parents().children('.frequency').toggleClass("hide");
	});

Open in new window


I saw this in console when I was clicking on the div. "click" event looked like being called twice

d3.png
4. I went to Julian's solution and that worked. Why is that? Julian has an explanation here but maybe that's what I don't understand
Julian's explanation

I think this is the key
To get around this we need to bind to a parent element that will be static -


If use #schedgroup instead of 'body'...code below works because #schedgroup is static
$('body').on("click", ".toggle", function() {

Open in new window


You can see it here

Works http://jsfiddle.net/jv2oudhg/

Doesn't work with my HTML change http://jsfiddle.net/gm5uxh7q/
0
Hi Experts,

I have a standalone web application (Html5, jquery and css3 application) which is running only on ipad pro in a safari browser.  I want to make this application full screen without address bar and title.  How to make this possible.  Please help me in resolving this issue.  

With Many thanks,

Bharath AK
0
I am following an example http://jsfiddle.net/glebkema/73gtkvjt/  to have have divs collapse and expand.

But I create controls dynamically so the JS code in that JSFiddle wasn't working... the divs weren't being collapsed.

I found this link that explained why dynamic controls work differently Explanation

I created this JSfiddle (forked the one above)

http://jsfiddle.net/3zw18rxe/7/

What I tried:
      
$('.toggle').on("click", ".schedule", function() {

Open in new window


Tried this but the divs won't collapse correctly...all of them will collapse

$(document).on("click",".toggle",function(){
    // code goes here
});

Open in new window


As a test, I hardcoded the id, but this didn't work either

$('.toggle').on("click", "#Schedules[0].Type", function() {

Open in new window


How can I do this when the controls are created dynamically?
0
1. I'm following this example http://jsfiddle.net/glebkema/73gtkvjt/
that I got from here. I'm doing the jquery version Example

2. You can download my sample code here. Unzip and just click on "page.html" to see it. The js file is Reporting.js
https://drive.google.com/open?id=17IuFhPlYPX5B7EATvE9sDES-EoB3i7gA

This is what's happening

1. I click on "Add Report Delivery" button and I see the control displayed. I click on the purple div and I can hide and display the control. This works.
j1.png
2. Click on "Add Report Delivery" again and you'll see the second control. Now, click on the puruple div and that div (control) doesn't collapse. I put debug steps in the JS code and for the second puruple div...the js code is not even called. Only the first div collapses and expands. I see I have unique Ids . Not sure what I'm missing.

j2.png

EDIT I ran a test. When I click on "add delivery schedule", the control is built dynamically. Something with this dynamic control that the "click" control on "toggle" doesn't work. Don't know why.
0
I was looking at this code and don't understand why there are so many "JSON.stringify" uses? I'm assuming it is completely wrong. Won't it change the string every time you use it? Also wouldn't it just be OK to only use this line var json = JSON.stringify(xhttp.responseText); since that stringifies everything and remove all the others?
                var idAtSource = Math.random().toString(36).slice(-5);
                var now = new Date().toJSON().slice(0, 10) + " " + new Date(new Date()).toString().split(' ')[4];
                var referralUrl = encodeURIComponent(_satellite.getVar("Full URL"));
                var jsonAction = JSON.stringify(action);
                var postBody = JSON.stringify(
                    {
                        "idAtSource": idAtSource,
                        "campaignType": "action",
                        "rawValueEncoded": jsonAction,
                        "referringUrl": referralUrl
                    }
                );

                var xhttp = new XMLHttpRequest();
                xhttp.open("POST", postUrl, true);
                xhttp.setRequestHeader("Content-type", "application/json");

                xhttp.onreadystatechange = function () {//Call a function when the state changes.
                    //readyState 4 is completed, status 200 or 201 is fulfilled
                    if (xhttp.readyState == 4 && (xhttp.status == 200 || xhttp.status == 201)) {
                        var json = 

Open in new window

0
Hi Experts,

     window.location.href is not working simlarly, document.location.href is also not working in javascript.  I want to redirect to a different url on a button click.  I had tried in javascript, it is not working.  Please help me in resolving this issue.

With Many thanks,
Bharath AK
0
Anyone knew...i had an issue .... if i have to save the timer to the server, i'll need the JavaScript to animate and increment the timer.
Have the JavaScript periodically send the value of the timer back to the server for saving so that the user can logout and login back in from anywhere and continue their timers..how????.please explain??
0
I recently asked a similar question but left out some important stuff. Here goes again...

Source Array
I have an array of items that looks like the following code. There can and will be many items in here.
[
    {
        "ItemId": "12345",
	"rmaId": "777",
        "UPC": "73343324400098",
        "Name": "Time Machine",
        "Description": "A new product you will love",
        "SerialNumberRequired": true,
        "Notes": "This is a note someone just entered",
        "Condition": 2,
        "Qty": 2,
        "SerialNumber": [
            "33",
            "34"
        ]
    },

   {
// more items will be here
}

]

Open in new window

Edit Array
I have a second array that looks like this. There will only be one object in this array.
[
    {
        "ItemId": "12345",
	"rmaId": "777",
        "UPC": "73343324400098",
        "Name": "Time Machine",
        "Description": "A new product you will love",
        "SerialNumberRequired": true,
        "Notes": "This is a note someone just entered",
        "Condition": 2,
        "Qty": 2,
        "SerialNumber": [
            "11112222",
            "3333344444"
        ]
    }
]

Open in new window

Based on the itemId in Edit array, I need any changes that don't match the source array returned to me in an array in this format.
For instance, if I am editing itemID 12345...
So if an item in the source array has two serial numbers, and both were changed, the result would be:

Desired Return Array
[
{
   rmaId: "777",
   itemId: "12345",
   serialNumber: "11112222",
   notes: "Some Notes",
   condition: "Good"	
},
{
   rmaId: "777",
   itemId: "12345",
   serialNumber: "3333344444",
   notes: "Some Notes",
   condition: "Good"
}

]

Open in new window


Some things to note:

1. rmaId, itemId, upc, name, qty cannot/will not be change.
2. some items may NOT have any serial numbers, so we need to still track notes and description
3. The return array only has those 5 properties, that is deliberate.

THANKS. I way above my paygrade on this one, lol
0
I have two arrays of similar data. I need to know what information has changed and a new array returned with old value, and new value. For instance,

Thank you for looking.

Array #1
[
    {
        "ItemId": "556784",
        "UPC": "73343324400098",
        "Name": "Time Machine",
        "Description": "A new product you will love",
        "SerialNumberRequired": true,
        "Notes": "This is a note someone just entered",
        "Condition": 2,
        "Qty": 2,
        "SerialNumber": [
            "33",
            "34"
        ]
    }
]

Open in new window


Array 2:
[
    {
        "ItemId": "556784",
        "UPC": "73343324400098",
        "Name": "Time Machine",
        "Description": "A new product you will love",
        "SerialNumberRequired": true,
        "Notes": "This is a note someone just entered",
        "Condition": 2,
        "Qty": 2,
        "SerialNumber": [
            "9999",
            "34"
        ]
    }
]

Open in new window


So in the above example, one SerialNumber was changed, so I would get back this:

[
{
    SerialNumber:  {
          old: "33",
         new: "9999"
    }
]

Open in new window

0
This code partly works but I think I need to do something with the "click" event. I'm building this dynamically.

You can download and unzip it from here. Just click on page.html to see it.
https://drive.google.com/file/d/1dU8yOCmzQJUeruaeKu1qxJLPs1-HlHF_/view

1. I click on "Add Report Delivery"
2. It calls $('#showSchedule').click(function () { in Reporting.js and adds a "schedule"
r1.png
3. Now, I click on "Add Report Delivery" again and another "schedule" is added. The first one I added is now hidden. You can add more.

r2.png
This is NOT the functiolity I'm looking for. I don't want the first one or additional ones to be hidden. I want to wrap each in a div... to be minimized...like collapse... with header.."schedule1", "schedule2", "schedule3", etc.

So, with each click...have the previous "schedule" div collapsed with a header title. I don't want them hidden. The toggle and "click" event are not working together correctly looks like it.

How can I do this? When I click on the button, each section gets an ID. Maybe I need to find the parent "div" which is "schedule" and attach the ID to the parent DIV for what I clicked on and collapse it? Here is a screenshot
r3.png
0
I am looking for an elegant and easy management solution to test my API's. For instance, we have a DEV environment, a QA environment, and a PROD environment.

Sometimes, for whatever reason, the endpoints do not match in each environment. For example...
DEV:  http://myDevEnvironment.com/Users

QA: http://myQa.com/QAGetUsers

PROD: http://mySite.com/GetAllUsers

Open in new window


So what I would like is a simple script to define the endpoints. I would like it easy to change enviromnents, and assign an alias to the method ( in the above example maybe call the alias "GetUsers"

This would be in a config file. So if I wanted to change environments, I could simply change a variable in the config file. Here is an example of how it would be used:


$.post( GetUsers, function( data ) {
  $( ".result" ).html( data );
});

Open in new window


Of course there can be many endpoints.

Can someone help me define a simple Javascript object or script to get this working?

Thank you!

John
0
I'm confusing myself by going back and forth and reading about DataTable and jqGrid.

This is my dilemma:
1. Working on a project that has lots of grids. Grid.MVC is used for the grids
2. There's one section that uses jqGrid. Probably it's because "grouping (group by)" is needed (our  ex-developer coded this).
3. I bought this template  https://keenthemes.com/preview/metronic/theme/admin_1/table_datatables_managed.html and it uses DataTable (not that I can't replace it)

This is what I need
1. "Group by" for at least one section of our site
2.  Inline edit - one of our existing grids has that
3. Performance - some grids have large amount of data to display.
4. Export to Excel and CSV but I can use EPPlus to export the data
5. Sorting
6. Nice to haves : user be able to hide/display columns
7.  jqGrid needs a license but DataTable is free. Ex-developer has coded the jqGrid but looks like he didn't ask our manager to get the license.

From what I read, jqGrid has better performance. I don't know if DataTable has "group by".

What to do? Anyone has used either? My preference is to use DataTable because it doesn't require a license but again...I don't know if it supports "group by". I looked at their site and not clear if they have it or not.

I've found these links with pros and cons:

https://www.slant.co/versus/4837/4840/~jqgrid_vs_datatables

http://debapk.blogspot.com/2012/01/jqgrid-and-datatable-comparision.html
0
I have this partly working but not completely

1. I create dynamic controls by clicking on a button. This is an example of having 2 rows
f1.png
2. I have an X next to each row and when user clicks on it, I want to hide the div

f2.png
3.  I have this jQuery code. It works only if I have one row and hides the div. But when I have more than one, it doesn't do anything.


How can I have.... hide the div that corresponds to this X being clicked?

$(".remDelSched").on("click", function (event) {
		console.log($(this))
		$(this).closest(".schedule").addClass('hidden');
		//event.preventDefault();
	});

Open in new window


This is the code for X delete. I wonder if I need to have a unique id for each X (delete)
	<div class="col-md-2">
									<a href="javascript:void(0);" class="remDelSched"><span style="color: red" class="glyphicon glyphicon-remove"></span></a>
								</div>

Open in new window

0
Hi all,

My code currently loops through my table and displays results of teachers in separate divs displayed across each page. Corresponding to each teacher, there is a send email button, which links to php mailer and also triggers off a progress bar. This is all done in a pop modal specific to each teacher.

My issue is that my progress bar is only working (i.e. increasing) for the entry (teacher) who is at the top of my table, and not working for any of the the other teachers in the table. The progress bar isn't actually linked to the php mailer function - I just set it to last the approximate length of time it takes to send an email via my server (bit of a cheat but hey ho..)

Can anybody think why the progress bar is only working for the first teacher within the table? Any help much appreciated.

Thanks,

I have attached my code here,

<?php 
	$i = 0; // sequence number to identify modal id
	?>

Open in new window



....

<!--// Modal start //-->
<div class="modal fade" id="exampleModal-<?php echo $i?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel-<?php echo $i?>" aria-hidden="true">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title" id="exampleModalLabel-<?php echo $i?>">A Message to <?php echo h($teacher['firstname']); ?></h5>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
		

Open in new window

0
Java usage vs Javascript usage.

If I undestand:

--- knowing Java  you can develop Applications that interacts with Databases. I am not sure knowing Java by itself if you can develop Dynamic Web Applications that interacts with Databases and fetch the results.( I mean probably you will have to learn other languages too, such as HTML, JSS,etc..)

---knowing Javascript what kind of advantage you get over know just Java ? I believe JavaScripts also interacts with Databases on the server and fetch the result and render the result to end user via the browser.

so it sounds to me, Java can be used for Non Web Application. JavaScript for Web Application.

If that's the case it sounds to me that knowing Java Scripts is more useful that knowing Java, Web Apps are much more in demand.


Any Expert to shade some lights on that?

Thank you
0
Hi Experts,

      I have standalone web application which is running only an Ipad.  It is supposed to only run on this ipad.  I want to enable autoplay audio for this ipad pro.  Please help me in resolving this issue.  In ipad I had tried chrome://flags/#autoplay-policy it is not found.  I had tried to enable autoplay through javascript but it didn't help.  I dont want auto play on all browser just on only one ipad.  I came to know from the previous questions it is not possible to make it on all browsers.  But I just want autoplay to be on one ipad

 $(function() {		  
		  $("a.active").find("h1").hide();
		  var adio;
		  adio = document.createElement('audio');
		  adio.src = "audio/Stolen - Audio - Marjorie Foster.mp3";
		  /*adio.pause;
		  adio.currentTime = 0;*/
		  adio.play();
		  adio.autoplay;
		  $("a.active div div").addClass("blinker");
		  
		  $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {			    
			$("a.active").find("h1").hide();
			$("a:not(.active)").find("h1").show();
			switchAudio();
			$("a.active div div").addClass("blinker");
		  })
    
		  function switchAudio()
		  {
			var num = $("a.active").find("h1").text();
			stopAudio();      
			switch(num) {
			  case "1":				
				adio.src = "audio/Stolen - Audio - Marjorie Foster.mp3";				
				break;
			  case "2":				
				adio.src = "audio/Stolen - Audio - Barbara Raymond.mp3";				
				break;
			  case "3":				
				adio.src = "audio/Stolen - Audio - Charlie King.mp3";				
				

Open in new window

0
I found this JSFiddle and applied it to my code http://jsfiddle.net/hQnWG/614/

1. You can download my code from here. Unzip and click on "page_copy.html"
https://drive.google.com/file/d/1qYWpX712PZL-flacmspsVog5VzDxsm2p/view

2. It doesn't happen all the time. You might have to clear your cache to see it. I did this in Chrome

3. Click on "Billing Attention to" to select it. Now, drag it to under "Asset tax" in the right hand box. It won't get placed there. It moves back to the left hand side box.

j1.png

4. Clear cache. Now, you can drag "Billing Attention to" to the first place in the right-hand-side box. This works It's like it can be dropped anywhere but not at the last place. Again, looks like sometimes it works and sometimes it doesn't.

Very odd. I looked here https://api.jqueryui.com/sortable/ to find maybe an event or something to "sort anywhere in any position" type of event but nothing jumped out.
0
Why is image bouncing in mobile view?

I have two sites, not completely the same as I've made some changes to CSS in one.

magickitchen dot com is the one that's live.

dev2 dot magickitchen dot com is the one I'm having trouble with on mobile. You can log in using the attached credentials.

It's the photo and caption atthe top of the page that's causing me grief on dev2.

It starts out short, then gets taller. See attached screenshots.
mk-dev-for-outside.txt
start.jpg
nest-slide.jpg
0
I am showing and hiding multiple radio groups based on another radio  group selection. I am able to do this part.

But now I am trying to make the ONLY VISIBLE radio groups to be required, if they are not checked, then show an error message saying they are required.

Here is my JSFiddle

JSFIDDLE

The code I am using and that's not working is as below


$("#js-add-to-cart").click(function(e) {
var check = 0
$(":radio[name^=Product_Attribute]:visible").each(function() {

            if(!$(":radio[name^=Product_Attribute]").is(':checked')){
                check = 1;
            }


});

 if(check == 1){
         $(".error").show();
          alert('Please select one option in each question.');
         e.preventDefault();	return false;
           
        }

});

Open in new window


What am I missing?

Thanks
0
I used Leaflet.js at my previous job last year. I think in C# code, we created a FeatureCollection (something like that). We also had Geometry column in the database.

1. Now, I have an address and have its longitude and latitude. I get this, for example, from Google API.  I'll save this in the database

2. In Leaflet.JS, I can use GeoJson --> https://leafletjs.com/examples/geojson/

My questions... can I just use the Longitude and Latitude of the address with Leaflet.js?  how does GeoJson come into play ... I don't know why that project had a Geometry column in the database? Why do I need GeoJson? How can I create GeoJson for an address?
0
This is a related question to this question that I asked a while back

Related question


I found a sample code to get the longitude and latitude of addresses. I want to save this data in the database and then use Leaflet.JS to display the addresses on a map.

string address = "123 ABC Court, MyCity, MyState 12345";
			string requestUri = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", Uri.EscapeDataString(address));

			WebRequest request = WebRequest.Create(requestUri);
			WebResponse response = request.GetResponse();
			XDocument xdoc = XDocument.Load(response.GetResponseStream());

			XElement result = xdoc.Element("GeocodeResponse").Element("result");
			XElement locationElement = result.Element("geometry").Element("location");
			XElement lat = locationElement.Element("lat");
			XElement lng = locationElement.Element("lng");

Open in new window


That code works but I don't have the GoogleMap API Key in there. I don't need an API Key? how could that code work and get me the latitude and longitude?
0
ColdFusion 9
Windows Server 2008
JQuery

I have captured a signature (Json value - TicketSignature) that I save to database.  I am using JQuery UI Signature to capture the signature (http://keith-wood.name/signature.html).  I can re-generate the signature on a web page without problem by using:

<cfoutput>
          <textarea style="display:none;" name="TicketSignature" id="sig">#TicketSignature#</textarea>
</cfoutput>

<script>
       $(function() {
		$('#redrawSignature').signature('enable').
		signature('draw', $('#sig').val());
		signature('disable'); 
	});
	$('#redrawSignature').signature({disabled: true});
</script>
<div style="margin-top:10px;font-size:12px;margin-bottom:7px;">
          <div id="redrawSignature"></div>
</div>

Open in new window


But when I try to embed the code above in a CFMAIL tag, it will not redraw the signature ... the "redrawSignature" box remains blank ... is this possible within CFMAIL tags?  Works fine on a regular .cfm page to display on the screen, but I need a copy emailed to my customers with their signature.

I have tried moving the TEXTAREA and SCRIPT outside (above) the CFAMIL tags, and also with them inside the tags, with no success.  Any ideas?

Max
0
Im using revolution slider to build a images slider on my site, Im trying to add some layer with some text.

in this first image as you can see the layer cames and all is good
first_image
But suddenly the layer change his position and became shorter,
second_image
 I truly dont know whats is happend, I hope you can help me to disable this auto resize

this is the code that im using
				<div class="slider-container">
                    <div class="slider" id="revolutionSlider" data-plugin-revolution-slider data-plugin-options='{"startwidth": 1699, "startheight": 600}'>
						<ul>  
						<li data-transition="fade" data-slotamount="10" data-masterspeed="300">
						<img src="/imagenes/myimage.jpg" data-bgposition="left center" data-bgfit="100% auto" data-bgrepeat="no-repeat" />
						
						<div class="tp-caption my-custom-label" data-x="0" data-y="200" data-speed="300" data-start="500" data-easing="easeOutExpo" style="background-color:#4baa2b;"><a href="dragon/leamos-poesia">Leamos Poesía</a>
						</div>
						</li>

						</ul>
					</div>
				</div>

Open in new window

0
I found this JSFiddle that I want to use

http://jsfiddle.net/hQnWG/

The error sometimes happens and sometimes it doesn't.

1. select more than one item
j1.png
2. Drag and drop them in the other . The items disappear with the error. Again, this sometimes happens and sometimes doesn't

j2.png
0

JavaScript

121K

Solutions

41K

Contributors

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and  in almost every mainstream web browser.