Retrieve javascript string from mysql for subsequent edit - javascript

I have constructed an on-line What's On page supported by a mysql database table including a field to contain an event title. An admin page permits entries to be added, edited and deleted. More recently I was asked if web links could be embedded in the title field, and found that editing the field to include a link of the form:
Click <a class=hdg onclick="newWindow('http://www.address');"> HERE </a> to open web link
would do the trick and open the URL in a new window via the newWindow function.
Unfortunately any attempt to use the admin page to edit such a mysql record corrupts the admin page display, since the string is returned from the title field as the value of a text box, and the link text is then interpreted by the browser so that only part of the field displays in the box on the screen. The remainder of the string appears outside the box, which is confusing to a non-technical user.
A quick and dirty fix is to use Ctrl-A to select the whole of the text box contents when editing, and then type or paste the whole of the title content into the box, when it commits correctly to the database. However, if anybody knows of a way to code the javascript so that on the one hand it will function correctly as a web link and on the other hand can be edited via an HTML form, I would be glad to know. Ultimately I guess I'll re-construct the database to hold the actual URL separately and use php to build the javascript link, but meanwhile ?

Use htmlentities() to put the field value into the web page with all the HTML special characters replaced with entities, so they won't be interpreted:
echo '<textarea>' . htmlentities($value) . '</textarea>';

Related

How can I get a user input and display it on a single page for my chat app

I am working on a chat web app just like Whatsapp and I have created a form where users can type a message but after doing that, I have a problem with making a users input display on a single page but it's displaying on a new page please how can I do that. I use the document.write()
I used a document.write() method but It's showing me what I am not expecting. What I need is to display input on a single page, not on another page
document.write is old and even strongly discouraged. You should append a new element to part of your page.
document.createElement would work well.

How do I make specific inputs go into another .html file in the project?

I wanted to make specific inputs go into another part of a site (e.g. https://myexamplesite.com/anotherpartofit.html)
And also make those specific inputs be the ones that someone saved it in.
An example of what I think would work is: Get value from input 1 from /apartofit.html and put it in input 2 at /anotherpartofit.html and make it non-editable
If it needs to use a database, I would prefer if you could help me with firebase (Google's Database). But in my knowlege, it probably needs to use javascript, so I'll be tagging it, if it doesn't, let me know!
in visual studio or notepad or every offline web creating spaces you can't but if you buy a domain or simple , online site , you have to crate a page and get the link of that page then open another page create a button set the button's href to link of pervious page finally hit the button !

How to make an interactive website and allow the user to edit website content?

To begin with, I'm fairly knowledgeable with both html5 and css3. Right now I'm trying to create a website that allows visitors to edit website content so that all visitors are able to see the edits. I know about contenteditable but this attribute does not last when the page is refreshed and no other visitors to see the edits. For example:
<p> Edit me please </p>
A visitor would be able to edit the element above by visiting the website and simply selecting and typing. Also I have heard that javascript, jquery, sql, and php can all allow visitors to edit website content but I don't know which is the best.
To sum up, if anyone knows how to allow visitors of a website to edit its' content it would be much appreciated to share their knowledge.
Create a database table (lets call it "strings") , and just define 2 columns - "string_identifier" and "string_value"
When you render the page, simply query the database to fetch the strings and their identifiers. Each editable element should have an attribute containing its identifier.
You can use jquery to capture the click event on all editable elements, and replace it with an input with that text.
Then assign an event handler to that input, so when the enter key is pressed, it sends a request to a php script (with the identifier and new string as data) on the server to update the database with the new string.
If you would like live updates to all other clients (no need to refresh), use jquery to continuously request a file on the server (endless loop), which will return a JSON object containing all the strings. Then go through and replace the text of all editable elements on the data with the new strings you have received from the server.

How to search on any website in Website Scraping

I am working on a project to scrape data from a website using DOM parsing. It can extract data from a particular website using that page url.
I want to add functionality to pass a php variable to that website's search box. and search that query. When a user manually enters a value in the website search box and presses search, the result comes out and we select that result. I want to do this programmatically.
How I can pass my php variable to a website search box and search on that website?
You will have to check and see how the form works - to which endpoint the data is posted. Then just do the same in your script and process the result (which might be servied in various different formats - JSON, HTML, XML etc.). Sometimes there might be added security, in particular if it's a .NET site that uses viewstate.
A somewhat straight forward suggestion would be to run a script on submission of the form that searches the text in each of the web pages in your working directory to find a match, then display a page with links to the found matches.
I will use PHP for my description of how this is done.
With this in mind, first learn how to read entire pages (i.e. webpages) into a string:
http://php.net/manual/en/function.file-get-contents.php
//YOU WILL HAVE TO LINE THIS UP WITH YOUR WORKING FILE NAMES
$home = file_get_contents('./home.php', FILE_USE_INCLUDE_PATH);
or I suppose you could just search for the actual webpage/URL like so:
$home = file_get_contents('http://www.example.com/');//IMAGINE THIS IS REALLY HOME.PHP
$homePageName = "home.php";//JUST HERE TO SHOW AN EXAMPLE
Example:
///YOUR FORM/INPUT BOX
<form action="search.php" method="post">
<input type="text" name="findMe" placeholder="Search...">
</form>
Now search.php
$search = $_POST['findMe'];
//$search = "example";//THIS WOULD WORK, BUT I WAS SHOWING HOW TO USE FORM
//IF WORD FOUND IN HOME PAGE
if (stripos($home, $search) !== false) {//USING EXAMPLE.COM TO SHOW IT WORKS
echo ''.$homePageName.'';
}
Then if you want to be simplistic and not use an array to store the found pages, take the same code above and use it for every page you want searched (i.e. home, about, products, etc..).
Now a user can search your site (or the pages you want indexed), to find all pages that have matching text. If you want specific keywords to be searched, just add them to the page metadata and the process I have described will still work as it searches everything that makes up the page.
<meta name="keywords" content="keyword1, keyword2, keyword3 " />

Facebook-like textbox that fetches a URL's contents upon paste

hi all i stuck at a point in which i want to ma a multiple line text box to work just like a FACEBOOK text box . i.e. when a URL is pasted or typed (along with the text) it will it fetches the information from the page specifed by URL
well i found somthing at
This post
i want to know how to get URL in VAR in javascript
coz when i enter a url it fetches complete information how ever when i put another url it treat it as a text
Constantly search the text for a url via regex, possibly on a javascript event like onkeyup. Use ajax to load the page, and scrape out whatever info you want to display.
http://www.devguru.com/technologies/ecmascript/quickref/evhan_onkeyup.html
http://regexlib.com/Search.aspx?k=URL

Categories