I would like to trigger a tel:12345 HREF using only Javascript, not with an anchor. I simply want to grab the value of an input field and use JS to prompt the user to call the number typed in. My trigger will be a button located next to the field.
Suggestions?
Use:
window.open('tel:12345');
<button onclick="myFunction()">
Call
</button>
function myFunction(){
var a = document.getElementById('input').value;
window.location.href = 'tel:' + a;
}
You can also view the live version on my website:
https://www.theharnishes.com/phone.html
Here we make a button and assign a function to it that bassically select the input, get the value, and the window.location.href will have the value of the input and it'll sent the url to call any number.
Js call making is very simple.
Using our : onclick function , Location , and tel
We can do this in any tag,
window . location ('tel:number')
Click me to call 199
Related
I have a quick question concerning JavaScript and CSS.
I'd like to have a popup box that allows you to enter a color (any main primary color that is recognized by CSS). After the user enters a color, I'd like it to alter the body element inside my external stylesheet to change the background color of the page. I know that I will need to use a combination of these attributes within CSS but I am not sure the syntax of how to relate it to the external CSS and the correct way to combine here.
From W3Schools:
function myFunction() {
var person = prompt("Please enter your name", "Harry Potter");
if (person != null) {
document.getElementById("demo").innerHTML =
"Hello " + person + "! How are you today?";
}
}
Also from W3Schools:
onclick="this.parentElement.style.display='none';"
Now, my main question I suppose is how to take the part where it says "display='none';" to actually take the input of the popup box and insert it in the onclick to achieve my goal (would it be something like this.parentElement.style.backgroundcolor='" + usercolorinput + "';")
Thanks in advance.
Here is how I would do it.
Change color on user input
function changeColor(element) {
document.body.style.backgroundColor = element.value;
}
<h4> Type #333, or pink below </h4>
<input oninput="changeColor(this)"/>
How it works:
The <input-element> can fire a number of events, based on your input. In this case I've used the oninput event, which is triggered every time you type something in the <input>, to call a function, called changeColor.
The input also sends the element itself when calling the function, as an argument. Therefore in my changeColor function, I have access to the element that triggered it.
Inside the function, I read the value of the input and then select the body of the page and set it's backgroundColor as the value of the input.
Or using a button
Or you can use a button, like you asked.
function changeColor() {
// get the input element value
var inputValue = document.getElementById("colorInput").value;
// apply the value as a backgroundColor on body
document.body.style.backgroundColor = inputValue;
}
<h4> Type #333, or pink below and press "Change color" </h4>
<input id="colorInput"/>
<button onclick="changeColor()"> Change color </button>
How it works:
In this case changeColor function is called by the button click.
Inside that function we get the value of the input, by getting the input via it's id attribute and reading it's value.
Then I use that value to apply backgroundColor to the body as I did in the above example
First create your function which return the display value after on click event.
function changeDisplay{
var value="block";
return value;
}
Then call it in click function
onclick="this.parentElement.style.display=changeDisplay()";
Note:- the way to change the background color at concept it is the same but you need to add this function to another event like text change in input text or select option from select box or the way you want in your script or web page
I have a text field that should be filled before custom saving through HTML custom button.
When a user fills this field and tries to save through custom button, the text inside this field is null even if the user fills it.
Any suggestions Please?
Many Thanks for replying to my query. Actually, I am calling the below function from custom HTML button and I saw the result from alert message as NULL value until I leave the text box. Once I click some other Field then I am getting right value and saving the record successfully. I have posted my code below please have a look and suggest me how I can achieve it. So how to get the text value if a user doesn't leave the text box and click on the Save button?
function createRecord() {
var oDescription = Xrm.Page.getAttribute("new_description").getValue();
if (oDescription != null) {
var callentity = {};
var activityId;
var currentUserId = Xrm.Page.context.getUserId();
var oLeadId = Xrm.Page.getAttribute("new_lead").getValue()[0].id;
callentity.Subject = "Call Activity";
callentity.Description = oDescription ;
XrmSvcToolkit.createRecord({....Some more functions here...
})
}
HTML Button code for calling above function
<input id="SaveCall" onclick="parent.createRecord()" type="button" value="Save Phonecall"></p>
Xrm.Page.getAttribute(arg).getValue(val) won't return a value until focus is lost from the arg attribute (as you've found out).
Some options you could try:
document.getElementById('new_description_i')[0].value
Removing focus from "new_description" on click of your button.
I want to make a WhatsApp share button for my Android app. All is set, the only problem is that I can get the textarea value only when I click on a button:
<button onclick="GetValue ();">Get the value of the textarea!</button>
I want to GetValue(); without the onclick.
This is my WhatsApp code:
Share
I want the textarea value in the data-text attribute and I am using it like above but it doesn’t work.
This is my textarea:
<textarea id="input_output" style="width:95%;" rows="10" wrap="soft">Enter Text Here..
</textarea>
Is there any way to get the value without clicking the button?
This is my function:
GetValue () {
var area = document.getElementById ("input_output");
alert (area.value);
}
Using javascript
document.getElementById("input_output").value
Using jQuery
$('#input_output').val();
EDIT:
Probably misunderstood, but it's very hard to understand your question.
As a javascript click event always fires before the "href" sets in, you can set the value when the link is clicked.
$('a').click(function(){
$(this).attr('data-text', $('#input_output').val());
return true;
});
JSFIDDLE
I am having trouble letting a user enter their name into a text box and when they click continue it changes another input value for testing reeaons its a textbox but when I put it in my website when its working the input it will be changing will be a hidden value
current javascript
function enterUsername(){
document.getElementById("ign").value = 'test';
};
Your function is only in the local scope. Make it global like this:
enterUsername = function(){...
JSFIDDLE
I need a javascript variable to be whatever is entered into a textbox when a button is pressed.
Basically, if somebody enters "bubbles" into the textbox and then clicks the button that says submit, I need "var Item" to be bubbles. How to I make that function?
I want an if statement if possible, so something like
var Item = getElementById(whatever the id of the textbox content it)
function Thing() {
if {
getElementById(whatever the id of the textbox content it) = bubbles;
document.open(P2.html);
}
you can get the value like this:
<script>
function getValue(){
var value = document.getElementBydId("textbox").value;
}
</script>
<textarea id="texbox"></textarea>
<button onclick="getValue()">