Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
User creates new element/node (div) via javascript on click of a button. The new element is saved as "part" of the page through sql.
I dont need a solution, I just need a starting-point. If known, then best practices.
Need better search terms. Thats all.
NB. What I'm finding is how to save the content of the div to sql. That I know. As well as how to create new elements. I suspect its done through fx ID and looping. But I'm not being precise enough when searching.
As a starting point, you're going to need to learn AJAX.
Then, you'll need to extract the contents of a div and send it back to the PHP which will put in your database. Given that it seems you're a novice, I recommend using jQuery to do this.
So, as a starting point, to extract the contents of a div using jQuery do the following:
//Let's say your div is as follows:
<div id="some_div">Here you have some content</div>
//Here's the jQuery to extract the contents:
var divText = $("#some_div").html();
From there, you'll need to use AJAX to send it to PHP to write it to your database. It should be noted that if they're creating a NEW div, you'll need to reference an existing div on the page first and then the created div as a child of that because you're inserting something in to the DOM that wasn't already there and your Javascript won't be aware of it. So you'll have to learn about "delegation" also.
It sounds like a lot to learn but we all have to start somewhere.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I need to fetch the contents under MY TITLE to appear as title within an image on the same page. For example this is a link from my blog and the title of the page appears within the image.
Just a code to fetch my title and use it within an image without having to copy paste manually every time. The structure of my URL is (title.php)
I presume you meant the page's title at the browser's tab, right? (question was a bit unclear)
If so, this value can be accessed in Javascript using
document.title
This is the cleanest way to get it, and the most effective one. There is a weird play if you want to use purely PHP to get it, however, I would stick to using this method if I were you.
For reference, here is the previous SO topic on getting page title in PHP
How to get page title in php?
If you wanted to use that value in PHP, you could use Javascript inside PHP by simply writing
echo '<script type="text/javascript"> document.title </script>';
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
As a disclaimer, I'm quite new to web development and even before I posted this, I have spent hours looking for answers but everything I have read did not help on what I want to do.
I'm basically trying to redirect to a certain page and then execute a php function which also require a variable to be pass to it and is inside a class.
I've read about ajax but people have said that theres no point using it if I want to redirect to another page anyway as its only good to use if you just want to reload a portion of the page.
The most simplistic way I can explain on what I want to do is, when I click on an image, I would like for a new page to be open and then in that said page is all the things about that image. For example, description about it, a short vid and maybe a comment section regarding the image clicked.
Please explain if what I'm trying to do is not possible and if so, please point me in the right direction as to what might be a better way of doing this.
You can just link to a php page and pass a request variable.
Link
// myPage.php
<?php echo($_REQUEST['someVar']); ?>
This will output "someValue" on the new page.
here's a really simple example:`
<img src="test_image.png" alt="your alt"> <!-- Simple link with a id attribute -->
`
On the PHP side:
image_infos($_GET['id']); //Call the PHP function with the image ID
function image_infos($id)
{
//Get your infos from the Server or whatever
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
This is probably a simple question, but I'm struggling with this.
Basically, how to browse in a database, as the user is typing something?
For example, in a website such as https://www.doesthedogdie.com/, how do they do it to show all the movies beggining with the string of characters you're typing, as you're typing it?
I guess javascript is involved?
It's called autocomplete
Please do some googling next time yourself.
You can use jQuery autocomplete or Bootstrap typeahead to achieve this.
Hope this helps
My personal preference on how to make these kind of systems is fairly awkward, yet it seems to work just fine for me without requiring too much client-side scripting.I use ASP.NET's Page_Load event to save all content in a SQL database into an XML file. Then, when the user enters some text into the field, I make a hidden div class underneath it unhidden to display filtered results from the XML document. This way, you can update the SQL database at any time fairly simply to add new records which should be listed on the website.This is server-side scripting, which I prefer to client-side because the user can disable features and mess around with it to view your code which is something I personally hate.I hope this helps you somewhat.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am very familiar with programming, MySQL, PHP, JavaScript, jQuery, HTML and CSS, and this issue of mine has nothing to do with what I just mentioned. It all boils down to three things:
Defining a menu layout with link options.
Rendering a dropdown menu on-demand with position calculated live.
Determining if the current user with current session is owner of the object clicked.
Nr. 2 is not a big problem, very simple indeed. Nr.1 & 3 are a bit problematic. And it is this part that I do not fully understand, I know that for Nr. 3 Ajax can be used to communicate with the PHP in the backend and determine ownership of an object through IDs.
As for Nr.1 should this be put in PHP or as a JavaScript AMD definition, I am not so sure about this myself.
I hope things are much clearer now.
Yes it is. Ajax can be used to load any data (html also) it depends on the programmer that what he wants to do with the data. For example, if you send a request to server to send some html, and in response it sends HTML to you then you can just simply render that html code in your DOM. It is as simple as that...
It actually depends on the requirement that you should use an ajax call or just use jquery to append or show some html.
(For simplicity and for your question):
Use Ajax:
To get data from server.
Append html using ajax if the html contains the data which needs to be get from the server.
Use Jquery:
To append/show html which is present on page ,no need of ajax call.
Like for example in above quora dropdown ,
-There is no ajax when you click on that "..." image(Although you can use ajax here but it depends on the application requirement,here quora is getting this drpdown values on page load).
-There is ajax when you click on "Make anonymuous" ,"Add to reading list" etc etc.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Is there any possibility to save a DIV, that has contenteditable="true", to a MySQL Table? I need to use PHP for this (and JS as a "helper").
I though of doing something like this:
Putting a button on the site that copies the content of the contentEditableDIV to a formDIV (a DIV that is in a form with method="POST" action="send_to_mysql.php").
The button is supposed to auto-trigger the submit button/function at the same time.
But is there any other, more convenient way? I am quite a beginner in MySQL, so I couln't think of any other way yet.
I appreciate any kind of help or response.
With best regards,
Dave
Conceptually...
//contenteditable element
//read element with JS
//URIencode to PHP via JS/AJAX
//Send to database with PHP/PDO
You're in for a real can of worms if you want this to work well. Especially if you want this to work well AND be able to accept pasted content from MS Word.