PHP $_Get and JQuery .load [duplicate] - javascript

This question already has answers here:
Encode URL in JavaScript
(22 answers)
Closed 8 years ago.
I want to load another page via Javascript like this
$("#resultarea").load("searchresults.php?searchstring=" + $("#searchbox").val());
in searchresults.php, a single statement
echo $_GET["searchstring"];
what I type in searchbox appears when searchresults.php is loaded except when I add space and another word, no thing appear at all. I heared it can be done by encoding or somewhat, I searched but didn't find a solution.

Try encodeURIComponent:
var encodedValue = encodeURIComponent($("#searchbox").val());
$("#resultarea").load("searchresults.php?searchstring=" + encodedValue);
Source
Demo

Related

How to add “ ?&max-results= ” after the /search/label/LABEL_NAME in blogger use javascript [duplicate]

This question already has answers here:
How to update (append to) an href in jquery?
(4 answers)
Append URL parameter to href with JavaScript
(2 answers)
How to append to an anchor's href attribute with JavaScript but not affect query string?
(3 answers)
Closed 2 years ago.
I want to change all the labels links and have a specific number to access it in blogger using JavaScript automatically
An illustrative example
../search/label/Label_name and add max-results=7 after "label name"
how i can do it .. i want help and thank you.
Something like this should do the trick. If you have further questions feel free to ask them :)
var x = document.querySelectorAll("a");
x.forEach(function(element){
var link = element.href;
console.log(link)
element.href = link + "?max-results=7";
console.log(element.href);
});
Example link

How do I translate HTML code into normal text with javascript? [duplicate]

This question already has answers here:
HTML Entity Decode [duplicate]
(17 answers)
Closed 6 years ago.
I want to translate an input from an API like this
<p>Communication that doesn’t take a chance doesn’t stand a chance.</p>
into something like this
"Communication that doesn’t take a chance doesn’t stand a chance."
I understand that html could translate this but I don't know how to translate this directly for use in javascript
Insert it into an element as HTML, and read it back out as text.
var elt = document.createElement('div');
elt.innerHTML = apiResponse;
alert(elt.textContent);

Javascript equivalent of PHP's "print" [duplicate]

This question already has answers here:
Is there a php echo/print equivalent in javascript
(9 answers)
Closed 8 years ago.
If I have some PHP HTML that reads like this:
<html> I am feeling <?php print urldecode($_GET["emotion"]);?> today!</html>
and Get's "emotion" in URL title is "Happy", the HTML renders "I am feeling Happy today!".
Now, migrating away from PHP, how do I do this with javascript?
In Javascript I have a variable $emotion = "Happy"; so what Javascript goes inbetween the script tags below (where there are currently asterisks********)
<html> I am feeling <script>*********************</script> today!</html>
You can do it easily by putting an element where you want the text to change, then accessing that element by it's id.
$emotion = "Happy";
var e = document.getElementById('emotion');
e.innerHTML = $emotion;
I am feeling <span id="emotion"></span> today!

Jquery is not accepting hypen in the jsp page? [duplicate]

This question already has answers here:
How do I reference a JavaScript object property with a hyphen in it?
(11 answers)
Closed 8 years ago.
I have a field sent by SERVICE which is having hypen in it. Eg., first-name (As JSON object)
But when I try to get the value of that field through the jsp. I am getting a script error.
Please let me know how to access the hypen also in this?
var nameList = msg.RESPONSE.DATA.NAME-LIST;
The above way when I try to access it is throwing script error
A variable or property name with an hyphen is indeed wrong in javascript (Jquery).
However, you can access the "problematic" property like this :
var nameList = msg.RESPONSE.DATA["NAME-LIST"];
I would recommend to rename the property(ies)
without hyphen if you control the content of this response

How to strip out all html tags from string [duplicate]

This question already has answers here:
Strip HTML from Text JavaScript
(44 answers)
Closed 8 years ago.
Here is the code I have:
I want to make sure the user doesn't put any html tags in the "Add Responsibilities" field. So for example, if the user writes this:
<div>Test</div>
Then it would put this into the responsibility field:
Test
I think it's something to do with this command but I can't get it working within my code:
$("#resp_input").html( $("#resp_input").text() );
You may use this code:
$('#responsibilities').text($("<div>" + eachline + "</div>").text() );
see this update

Categories

Resources