I have parsed a page using curl and it contains some check box and a 'select all' and a 'submit' button . Clicking the button selects every check box.'select all' button triggers a javascript function which actually select all check box.
Now i need to click 'select all' and 'submit' button.How can I do this ??
Here is the button code:
input type="button" onclick="SelectAll(137)" value="Select All"
Here is the js function:
function SelectAll(n)
{
for(i=0;i<n;i++)
document.getElementById("ch"+i).checked=true;
}
You can't. If you must use cURL, you'd have to manually craft the POST request yourself. This would involve finding the names of all the checkboxes and sending a bunch of checkbox1=on&checkbox2=on&... in the POST body. See http://davidwalsh.name/execute-http-post-php-curl for a general example of a POST request through cURL with PHP.
Another option would be to use something like Selenium Web Driver, which pretty much allows you to script a web browser like Firefox that can run JavaScript, click things, etc.
Pass a parameter in with your Curl request that gets parsed by jQuery on its $(document).ready(). There's some plugins that help with parsing parameters.
Something like
$(document).ready(function(){
var buttonPress = $.param("buttonPress");
if (buttonPress == true)
$("#myButton").click();
});
Related
All the above code I saved in a page called dum.php
$(document).ready(function(){
$(".sameclass").click(function (e) {
e.preventDefault();
var QS = $(this).attr('href').split('?');
if(QS.length>0){
var val = QS[1].split('=');
if(val.length>0){
$("#edit_prdct").hide().slideDown('slow');
//Below am adding a value to the hidden text filed
document.getElementById('prd_id').value=val[1];
}
}
});
});
I had some products which i want to edit their info EDIT are the hyperlinks with the query string value
<DIV id="list_prdct">
<a href="dum.php?id=1" class=sameclass>EDIT</A><BR><DIV id="edit_prdct">
<a href="dum.php?id=2" class=sameclass>EDIT</A><BR><DIV id="edit_prdct">
<a href="dum.php?id=3" class=sameclass>EDIT</A><BR><DIV id="edit_prdct">
<a href="dum.php?id=4" class=sameclass>EDIT</A><BR><DIV id="edit_prdct">
</DIV>
In the below div I used a hidden field and I want to used its values in the mysql query in the where condition and I will display a form related to that value
<DIV id="edit_prdct">
<?PHP
$prdid"<input type=hidden id='prd_id' value=''>";
// Here I want to use that value of the hidden field as the condition in the mysql query
?>
I am not sure if I got your question correctly, however, this is my try.
Every system has 3 parts: input, processing and output.
Here, your PHP logic is the processing part. It runs on the server and understands only Php. It doesnot know about your HTML, CSS, JavaScript, etc.
Input is provided through HTML and Javascript(JQuery) using a web browser. When you click a link, or submit a form, or make an Ajax call, then browser basically sends an input to the web server (its called a HTTP Request)
Output is again HTML, CSS and Javascript. The statements you echo or print including the ones outside <?php ?> tag, are all output. These are understood by a web browser and not by the server.
To send any data from client side (the web browser) to the server, you need to use HTTP requests. This can be done in 3 ways:
Synchronous Request(href redirects, form submission, sync. Ajax calls, etc)
Asynchronous Request (Ajax Calls).
URL redirections (its a form of way 1 above!!)
All the ways above typically use either the GET method (query strings) or the POST method.
If you dont want to use Ajax or form submission, you are left with only third option, that is, call the resource links directly. For example, redirecting the user to some URL like:
http://www.example.com/products/134
where 134 is a prod_id.
Then on the server side, you will have to retrieve the URL and extract out prod_id from it. This is a tedious task. Fortunately we have some good frameworks to do that, like CodeIgniter, etc. But this is not the way to send data to the server in case you need to fetch data for a list of prod_id.
So, No, there is no other way to get data from server. Perhaps you need to remodel your problem and understand that Php server can't know about your prod_id magically, you need to send it through one of the methods of HTTP request
I have a php application in which the web page displayed to the user. The page has some links "Edit", "Rename", etc.
When the user clicks on the link a dialogbox prompts. The dialogbox is nothing but a HTML <div> form that gets instantly displayed when the user clicks on the "Rename" or "Edit" link.
When I looked at the html source code (i.e. view -> source in Internet Explorer) I found the following Javascript and HTML code
<a class="update renameButton" href="javascript:void(0);">Rename</a>
I'm unable to understand how the dialogbox gets promted with the above code.
I expected the code to be something like the following:
<a class="update" onclick='rename();' href="javascript:void(0);">Rename</a>
Can someone help me understand this?
Some JavaScript loaded from a <script> element probably binds an event handler function to the element.
The event handler is most likely bound to the element elsewhere (from an included JavaScript file perhaps). For example:
document.getElementsByClassName("update")[0].addEventListener("click", function () {
// Do something on click of the first `.update` element
}, false);
you should not setup event listeners in html anymore like with onclick.
the page registers an event listener to the Object. e.g. with a library like jQuery.
You are absolutely correct! That is very natural to expect such a thing except that there are other ways to bind an event to an object as well.
If you check the JavaScript code on the page I am sure you will find perhaps something that looks like $('a.renameButton').click(function(){}); (if the site is using jQuery) or something similar that binds the onclick event of that particular tag to perform some specific actions.
I'm trying to learn how make an AJAX script
for a LIKE button, on my website. I have the following questions:
if i'm sending 1 variable.... id.. I do this
data: "action=vote_up&id="+(this).attr("id")",
is this syntactically correct if i'm sending two variables id and id1 ?
data: "action=vote_up&id="+(this).attr("id")&id1="+(this).attr("id1")",
2) What goes into the href attribute? The php page or the AJAX?
<img scr="like.png">
3) which is run first.. The php page or the AJAX.
4) Is it mandatory for me to use jQuery or Pure Javascript for running AJAX
thanks for your time and patience. I most appreciate it.
1) Yes, you could simple undestand it as a PHP-Get request to a script, so multiple vars are possible, like Adam mentioned.
2) For backwards compatibility you should just link to a PHP/whatever-Script that provides the same functionality but doesn't rely on javascript (Not everyone has js enabled). In your javascript you just disable the defult click actione ( see: http://api.jquery.com/event.preventDefault/ ) otherwise it you only want to allow the like funktionality if js is enabled than you could just link to the page anchor '#'.
3) The page runs first. It is progressed by the server and than sent to your browser. In the browser the recieved javascript will start its action.
4) Everything you are using in jquery is based on simple javascript functions, but jquery is much more comfortable ;) The equivalent to the ajax method of jquery is XMLHttpRequest ( http://www.w3schools.com/xml/xml_http.asp )
Here is a idea, hope it helps.
If handle_vote.php is the URL responsible for the handle the up vote, you must do two things:
the a href is the URL with the query string for the up vote, your data, is this case. It must be generated for you server application. It will be used in case of no javascript.
you should put you event to handle the up vote in the a onclick event, to send the ajax request, and use the preventDefault jQuery function to avoid the default event. In this case, a href will never be used, the js will suppress the link click.
A code sample will be almost like this, in you php page:
<a class="like" href="handle_vote.php?action=vote_up&id=<?php echo $post_id; ?>"><img src="like.png"></a>
And it as your jQuery script:
$(function() {
$('a.like').on('click', function(e) {
e.preventDefault();
$.get($(this).attr("href"));
});
});
You can personalize as you like, it is only the idea of how to do it.
<img scr="like.png"> put onclick event on that link, and make AJAX request` to increment count, on success response update count clicks on button. And you forgot about one thing, you should save the state of that button. Because one user can go to your site and click 1000 times on it.
I need to pass some data via AJAX POST or GET to a php file which then uses that data to
reference or access a database without actually refreshing the page. How am i to do it?
For ex: if i use:
function callFunc() {
$.post ( " phpFile.php " , { name: "James"}
...
...
...
}
Take a look at Easy Ajax with jQuery should explain things.
When you use Ajax, an http request is made to the server that calls a php script sending post or get variables to this. The script is then executed and the response returned to the main page, with jquery you can manage the response and make the page not to refresh. If you have a HTML form and a submit button the page will be refreshed, you have to avoid this. Use jquery Val() selector to get the input values and send them trought an Ajax call without the submit button.
I need to create some kind of JS onclick that will run a php mail script that emails a page with broken content.
Would it be best to run a normal javascript onclick that calls a php file which is hidden, grabs the referring url and emails it?
I would also like a message confirming the click, then disable it.
Is there anything like this available?
This will create onClick handler for your link, and action will be done in case user will accept confirm message.
var onClickHandler = function() {
if (confirm("Are you sure?")) {
$.post("your_php_mail_script.php", {broken_url: document.location});
}
};
$("#your_link_id").bind("click", onClickHandler);
And that is all. In your script you'll get broken url as POST parameter ($_POST['broken_url']). This will be done asynchronous.
I can't understand what you want to disable and after what action.