Sometimes this script does not work, I am using it in a php file
<script type="text/javascript">
window.onload = function () {
var input = document.body.getElementById("thisActive");
input.focus();
input.select();
}
</script>
here is work
http://cartoon.22web.org/watch/s-watch/index.php
After the page load is complete, the script specifies the link to the page
===========================
But here using multiple pages http://wassim-al-ahmad.22web.org
not selected page selected
Just convert window to document like this:
document.onload = function () {
var input = document.body.getElementById("thisActive");
input.focus();
input.select();
}
JQuery version
$(document).ready(function () {
...
});
You have seen the code and the reason for the priority You are using JavaScript at the beginning of the code and then create a menu to select an item from a database using PHP multiple pages You must use the script at the end of the code
Use PHP to view the data from the database starting with the page order currently displayed. You do not need to use the script you have ever typed in your HTML code.
i had the same problems just you have to change your host if you used free host you must change the host to
Related
I have one input and script to reload table in my page. In the input if I insert 1000 I want to reload page every second, without clicking any buttons.
This is what I tried :
<input id="txtRefresh" />
<script>
document.redy(function () {
$('tblRefresh').load();
setInterval(function () {
$('#tblRefresh').load();
}, 'txtRefresh');
});
</script>
Its cshtml razor page.
What I want to do is to insert the value of seconds in the input andrefresh the page based of the of the inserted value, without submiting any data.
Is it possible to do this? Any suggestions?
Thanks in advance!
UPDATE
I inserted this script:
<script>
document.ready(function () {
$('#refreshDIV').load('url/url/url');
setInterval(function () {
$('#refreshDIV').load('url/url/url');
}, $('#txtRefresh').val());
});
</script>
But it gaves me error!
refreshDIV is a div that I want to refresh
txtRefresh is the input from I insert the seconds
you can try this:
$(document).ready(function(){
var timeout = $("#txtRefresh").val();
setTimeout(timeout, function() { location.href=""; });
});
but each time you will reload the page you will lose, the input.
You could send it through querystring like this:
location.href="?timeout="+timeout
and populate the input server side
This is just a string:
'txtRefresh'
If you want to get the value of that element, it would be more like this:
$('#txtRefresh').val()
You also have a typo in document.ready and in your first #tblRefresh selector (missing the #), and you aren't supplying .load() with the URL you want to load. All together you appear to be trying to do this:
$(document).ready(function () {
$('#tblRefresh').load('/some/url');
setInterval(function () {
$('#tblRefresh').load('/some/url');
}, $('#txtRefresh').val());
});
A couple things to note:
The value /some/url is of course a placeholder in this sample code. Whatever URL you want to use in your application is up to you.
Calling .load() will place the entire response of that URL into the target element. If you want only a subset of that response, you can add selectors to .load(). For example:
$('#tblRefresh').load('/some/url #someElement');
This would tell .load() to grab all the content from /some/url and then only select from it the content of #someElement to place in #tblRefresh. The performance could still potentially be slow as all of the content from the URL is still downloaded. To address performance or for finer control over data, consider returning JSON data from the server and using .ajax() to fetch that data instead of using .load() to reload all of the HTML (when only the data has changed).
I have Wordpress 2 instances: local and remote (remote should be very similar, it was mainly uploaded from local except from a few plugins). Code is using jQuery.noConflict method, because without it it was not working locally after adding a lot of plugins. Now when it's uploaded to remote Wordpress, it's still not starting there, but it works locally :). JS method is just not started. For sure file is attached with proper path in HEAD section of HTML file. No errors displayed in console.
Expected behaviour is: JS alert should appear but it not.
JS code is here:
var jQueryAlias = jQuery.noConflict();
function customizeWebUIForEmailSubscriberPlugin() {
alert("customizeWebUIForEmailSubscriberPlugin");
//format input button
jQueryAlias('#elp_txt_email').removeClass('elp_textbox_class').addClass('form-control').addClass('full-width');
//format input button
jQueryAlias('#elp_txt_email').removeClass('elp_textbox_class').addClass('form-control').addClass('full-width');
//format message text
//jQuery('.elp_msg').removeClass('elp_msg').addClass('post-body');
jQueryAlias('#elp_msg').addClass('message-format');
//hide submit button
jQueryAlias('#elp_txt_button').addClass('hide');
//hide email label
jQueryAlias('.elp_lablebox').addClass('hide');
}
jQueryAlias(customizeWebUIForEmailSubscriberPlugin);
Try the following. The function should fire on document.ready, but you can also call it whenever you like.
jQuery(function ($) {
function customizeWebUIForEmailSubscriberPlugin() {
alert("customizeWebUIForEmailSubscriberPlugin");
//format input button
$('#elp_txt_email').removeClass('elp_textbox_class').addClass('form-control').addClass('full-width');
//format input button
$('#elp_txt_email').removeClass('elp_textbox_class').addClass('form-control').addClass('full-width');
//format message text
//jQuery('.elp_msg').removeClass('elp_msg').addClass('post-body');
$('#elp_msg').addClass('message-format');
//hide submit button
$('#elp_txt_button').addClass('hide');
//hide email label
$('.elp_lablebox').addClass('hide');
}
$(document).ready(function() {
customizeWebUIForEmailSubscriberPlugin();
});
});
Edit:
In order to add jquery in WP, add this code to the bottom of your theme's functions.php file, before the closing php tag tat looks like this: ?>:
function pk_enqueue_scripts() {
wp_enqueue_script('jquery');
}
add_action('pk_enqueue_scripts', 'wp_enqueue_scripts');
The problem is that on both servers (local and remote) jQuery lib is attached in HEAD tag in different sequence. On my local machine: jQuery was attached after script.js and that worked. For remote: jQuery was attached after my script.js. I am not sure why it works in such way on my remote machine.
Solution:
After adding code
<?php wp_enqueue_script("jquery"); ?>
right after HEAD tag, it works:).
I'm using the $.get() function to extract some data from my site. Everything works great however on one of the pages the information I need to extract is dynamically created and then inserted into a <div> tag.
So in the <script> tag, a function is run and then the data is inserted into <div id="infoContainer"></div>. I need to get the information from #infoContainer, however when I try to do so in the $.get() function, it just says it's empty. I have figured out that it is because the <script> tag is not being run. Is there another way to do this?
Edit:I am making a PhoneGap application for my site using jQuery to move content around so it's more streamlined for mobiles.
This is the code on my page:
$(document).ready(function () {
var embedTag = document.createElement("embed");
var infoContainer = document.getElementById("infoContainer");
if (infoContainer != null) {
embedTag.setAttribute("height", "139");
embedTag.setAttribute("width", "356");...other attributes
infoContainer.appendChild(embedTag);
});
});
As you can see, it puts content into the #infoContainer tag. However, when I try to extract info from that tag through the get function it shows it as empty.I have done the same to extract headings and it works great. All I can gather is the script tag is not firing.
This should provide you the contents of the element:
$('#infoContainer').html();
Maybe your script is executing before the DOM is loaded.
So if you are manipulating DOM elements you should wait till DOM is loaded to manipulate it. Alternately you can place your script tag at the end of your HTML document.
// These three are equivalent, choose one:
document.addEventListener('DOMContentLoaded', initializeOrWhatever);
$( initializeOrWhatever );
$.ready( initializeOrWhatever );
function initializeOrWhatever(){
// By the time this is called, the DOM is loaded and you can read/write to it
$.getJSON('/foo/', { myData: $('#myInput').val() }, onResponse);
function onResponse(res){
$(document).html('<h1>Hello '+res+'</h1>');
};
};
Otherwise... post more specifics and code
You have no ID to reference. Try setting one before you append
embedTag.setAttribute("id", "uniqueID");
It looks like you are wanting to use jQuery, but your example code has vanilla JavaScript. Your entire function can be simplified using the following jQuery (jsFiddle):
(function () {
var embedTag = $(document.createElement("embed"));
var infoContainer = $("#infoContainer");
if (infoContainer.length) {
embedTag.attr({"height": 139, "width": 356});
infoContainer.append(embedTag);
}
console.log(infoContainer.html()); // This gets you the contents of #infoContainer
})();
jQuery's .get() method is for sending GET requests to a server-side script. I don't think it does what you are wanting to do.
I have a webpage on which there a button.
On button press, I intent to embed a script in the head section of the page to enable a plugin. I can manually insert the snippet and my plugin but I want to be able to do this on button click itself to keep it as an optional element for my users.
What is the way to go about this?
As per #padde's query, the script looks like the following the way I include in my header:
<script type="text/javascript" src="http://code.abc.com/farfalla.js"></script>
<script type="text/javascript" src="http://code.abc.com/postmessage.js"></script>
Use createElement() of javascript and add it to the DOM
Check the below link for more information : http://www.hunlock.com/blogs/Howto_Dynamically_Insert_Javascript_And_CSS
If you are using jquery then you can use $.getScript to load the external js file.
$.getScript('filename.js',function(){
//your code ...
});
Normally, you would simply put the script inside the <head> tags. Then, extract the initializing code from the included script and run it when the button was clicked.
Edit
You can also try this:
HTML
<button id="share-button">Share this</button>
JavaScript
dynamicCode = 'alert("script loaded");'
scriptLoaded = false;
buttonClicked = function(e) {
if( !scriptLoaded ) {
var script = document.createElement('script');
script.text = dynamicCode;
document.getElementsByTagName('head')[0].appendChild(script);
scriptLoaded = true;
}
alert("thanks for sharing");
};
button = document.getElementById('share-button');
button.onclick=buttonClicked;
where you would load the dynamicCode with an Ajax call or whatever you like. The code is only loaded once. I've put together a jsfiddle for you, so you can try it out.
I use jQuery with $('#countryid').load('/some/url',{country: country_id}); function to automatically load options for regions depending on selected country before.
And it works fine when I load html through ajax.
But I need to load javascript code. When I try to do that all select fields disappear from page at all...
What am I doing wrong?
Code:
<script type="text/javascript">
$(document).ready(function() {
$('#countrydropdown').change(function() {
var countryvalue = $('#countrydropdown option:selected').val();
if(countryvalue==0){clearlist();}
getarea();
});
});
function getarea(){
var countryvalue = $('#countrydropdown option:selected').val();
var area = $('#areadropdown');
if(countryvalue==0){
area.attr("disabled",true);
}else{
area.attr("disabled",false);
area.load('/ajax/2/',{country: countryvalue});
}
}
function clearlist(){
$('#areadropdown').empty();
}
</script>
<form action="" id="form">
<select id="countrydropdown">
<option value="0">Countries</option>
...
</select>
<select id="areadropdown" disabled="disabled">
</select>
</form>
Thanks!!!
Based on the code your comment on my previous answer suggests you are using:
<script type="text/javascript">for(var i in arr) document.write(arr[i]);</script>
After the page has loaded, the document will enter the closed state.
You cannot document.write to a document in the cosed state, so document.open will be automatically called.
This will trash the existing document so a new one can be written.
Use DOM to manipulate the document, don't go near document.write.
You can use eval to execute javascript code
eval(ajax.request);
If you are loading just JavaScript, then use getScript instead of load.
If you are loading a combination of HTML then JavaScript, then I would give serious consideration to refactoring so that the JavaScript is already in place and events are handled using live instead of being bound directly to the elements themselves.