javascript add text to string sent to DB - javascript

I am using appery.
I want the number in a text input to be sent to a database, which it is. Problem is that I need to add the short text 'Tel:' before the actual number. So the string in the database will sa Tel: XXX(the number).
I have tried now for two days and really can't get it to work even if it seems like an easy task. All it does is that is sends the number. (trying prepend, but obviously doing it wrong)
Any help would be very appreciated!

If you are using Appery try this,
"tel:" + Apperyio(name of your text component in string).val();

You can try this
var number = "tel:" + document.getElementByID("Input_Field_ID").value;
now sent this number (variable) to Database

Related

String from api response cant display break line, but hard code string can display break line

Good day,
I am using Angular 8 as my frontend, and java api service as my backend.
I need to retrieve some String from backend, and the String will having \n in between, for example:
"Instructions:\n1. Key in 122<16 digit \nreload pin># to reload.\n2. Press SEND/CALL from
In my .ts file, I am setting this String value as follow:
this.str = this.apiRes.responseMsg1;
console.log("this.str : " + this.str);
This will give me Instructions:\n1. Key in 122<16 digit \nreload pin># to reload.\n2. Press SEND/CALL, thus when I use it to display in html, it will just display as 1 line.
If I hard code this String to a String variable, for example:
this.str = "Instructions:\n1. Key in 122<16 digit \nreload pin># to reload.\n2. Press SEND/CALL from";
console.log("this.str : " + this.str);
It will give me :
Instructions:
1. Key in 122<16 digit
reload pin># to reload.
2. Press SEND/CALL from
Which is what I want.
I am not really familiar with Angular, I am trying to find this answer in google, but cant get any related result.
May I know why is this happen? And any way I can display the api message accordingly?
HTML ignores \n line breaks. You basically have two options to fix this:
Replace the line breaks with <br> elements.
Add a line of css white-space: pre-wrap; to your HTML element which is displaying your string.

Use .replace() with "

I am currently working on getting data from an API, and I want to remove some characters from what it returns.
What I get back is {"usd":323.67}, but the currency and price may change depending on the input.
I want to remove the {}, usd (or other currency), "" and :. I searched, and found .replace() could be a good solution, if you replace the character with nothing. But when I use .replace(""", "");, I of course get an error. When I do, .replace("{}", "");, it doesn't replace the {} with nothing either. And because I use a constant for the currency, because the user can choose, the currency it not always the same, so I thought it could use .replace(${currency}`, ""), but that also doesn't work.
What should I do to remove these things from my string?
Thanks in advance!
As others commented, parse your data as JSON and then get the value using your currency variable, something like this (not sure about what framework you are using, so the currency replacement may vary from what's shown here):
data = {"usd":323.67};
value = data.${currency};
You have to find all numbers in string and then concat them with '.' symbol
const getValue = (str) => str.match(/\d+/g).join('.')
console.log(getValue('{"usd":323.67}'))
console.log(getValue('{"rub":323,67p}'))
console.log(getValue('"euro":333-00'))

Newline does not show the entire text in vaadin-text-field

I have a string which is returned by a JAVA API as follows.
String:
var text = "Enjoy True Value Tuesday!\nExclusive Bhangra Class tomorrow at 7am.\nAlso get flat discount Rs.2500\/- on all memberships.\nFirst come First book.Limited 10 ";
When I set the text of the vaadin-text-area to this string it does not show the full text, as shown in the following image.
I also have tried to change the '\n' to
as suggested here. But it did not solve the problem.
Can anyone please let me know what is the problem here?
Thanks

Why <a> tag replaces spaces with %2520? how to solve the issue?

In this case, I suppose explaining the problem as a scenario would be the best way to explain it.
I have a search box in a page called A.html, parameters that are passed to this page should be replaced with the value of its search box. The problem is that, when I pass the parameters the spaces get replaced by %2520 therefore wrong value will be added to the search box. I need to solve it.
Link
Following address will be put into the address bar: www.example.com/a.html?value=Here%2520and%2520there
This value will be replaced with the value of the search box: Here%2520and%2520there. I need to have this value "Here and There" in my search box. (without %2520)
What seems to have happened here is that the URL was double encoded (see below); while I can't explain exactly why that happens, it may be because your URL is not properly URL encoded:
Link
It should be:
Link
Or:
Link
Double encoding goes like this:
" " regular space
"%20" percent encoded, " " -> "%20"
"%2520" percent encoded, "%" -> "%25"
Update
The reason I couldn't explain the double encoding is because the question was missing exactly how the passed value was added to the search box. The most likely scenario is that the search box is populated with a percent encoded value. To fix that, you have to decode the value first, i.e.
searchBox.value = decodeURIComponent('Here%20and%20there');
See also: decodeURIComponent()
As has been mentioned, serving this data as a URL requires spaces and other non-ascii characters to be URL encoded. Without this, the browser would not be able to properly parse the URI.
You can make changes to solicit the raw data without encoding it (keep spaces intact), but this will be of no use if you are appending to a URL. If you aren't, feel free to paste the code relating to whatever you are trying to do with the data.

unable to retrive + characters using php and ajax

Hello friends facing a problem with AJAX and PHP ???
Let me tell you what i did ...!
I created 2 pages
one page (AJAX_view.php) with a drop down with all the blood group in short code like (b+, b-) and i placed my ajax code on the same page. to asynchronously search for the blood groups available in database (MySql).
Now the another page (search.php) has all the php code and the query to retrieve the data from database..
Now the real problem is from the 1st page i passed the string in url to the another page using the code
xmlhttp.open("POST","search.php?q="+str,true);
xmlhttp.send();
and the str here is 'B+' without quotes
and it doesnt reads the "+" , what it reads is only B... this only happens in the case of "+ " while if i pass the string str as "A-" its give the result without any problem or error and returns result from database
but there are certain blood group like B+ ,AB+ , O+ and there is no result show for them.
$q=$_GET['q'];
this is how i retrieve the string on search page..
$select_query="SELECT * FROM blood_donate WHERE blood_group='$q'";
$res=mysql_query($select_query);
this is how i select data from database??
please help
You need to encode +, otherwise it'll be treated as space (). Use encodeURIComponent on str for this.
xmlhttp.open("POST","search.php?q="+encodeURIComponent(str),true);
if str is A+ without encodeURIComponent it'd generate url search.php?q=A+. This makes $_GET['q']='A ' at the PHP end. (note the space)
With encodeURIComponent it'd be search.php?q=A%2B which yields $_GET['q']='A+'.

Categories

Resources