Copy my addresses in different fields in javascript - javascript

i have in my jsp different addresses, I can choose to copy to my fields. I wanted to know if anyone has sample code in javascript to provide me, thank you.
http://www.freeimagehosting.net/image.php?87514f7c3e.jpg
Different editable fields . A list of address, when I select an address, I want to automatically informs my fields

I think it's time to learn basic JavaScript/HTML DOM :) Here are some tutorials:
W3Schools JavaScript tutorial
W3Schools HTML DOM tutorial
Essential JavaScript - tutorial
To start, you need to give HTML elements of interest an ID:
<input type="text" id="address">
<input type="text" id="otherAddress">
You can grab a specific element using document.getElementById():
var addressElement = document.getElementById('address');
var otherAddressElement = document.getElementById('otherAddress');
You can get the value by value attribute:
var addressValue = addressElement.value;
You can set the value by the same attribute:
otherAddressElement.value = addressValue;

Related

How to make multi choose autocomplate and how to send data?

Hi i use w3schools autocomplate tutorial. Link https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_autocomplete
I want to make multi choose. For example ; France and England for Country. Actually i saw multi choose example on Javascript but i need a variables. When i click send button my query executed so i need variables.
How can i do it ? and how can send value from input area to sql query ?
Image
It is difficult to understand what you're looking for in the way you phrased the question, but I will try answer based on how I understood the question.
First, I would add hidden input to contain array values under input ID: #myInput.
Try the following:
<input id="countries" type="hidden" value="countries[]" />
<input type="button" value="add" onclick="addCountry">
As you see, I bind click event to the button so function would be:
function addCountry(){
const countries = document.querySelector('#countries');
const country = document.querySelector("#myInput");
countries.value = [...countries.value, country.value];}
So, when you submit form, you will be able to get this from a PHP file
with []
$countries = $_POST['countries'];
Alternatively you can use $_GET instead.

Selecting form field on a html page

I'm trying to prepare my first Greasmonkey script (with no experience in javascript/websites technologies) and I have problem with selecting field on a page. It is:
<input data-testid="user/fullName" autocomplete="name" class="form-control u-text-normal">
I've tested:
document.querySelectorAll("input.form-control");
document.querySelectorAll("input.form-control.u-text-normal");
document.getElementById("user/fullName").value
but non of them is returning what I need... and what I need is possibility to fill that form field with the script. Could you help, please?
EDIT:
The methods given in the following answers I try to run in the browser console and they do not return me any element. Maybe someone could try to run it and tell me what I'm doing wrong? The website is a shopping cart on the pizza site :) But to see it you need to add pizza to cart ("Do koszyka") for a minimum of 20 zł and then go to payment ("Do kasy"). Then the first field "Imie i nazwisko" is what I would like to fill at the beginning.
If you need to get a single element, give the html element an id example:
<html>
<input id='id_here'data-testid="user/fullName" autocomplete="name" class="form-control u-text-normal">
</html>
then get the element using
document.getElementById('id_here');
For multiple elements that share the same class you could use the query selector
document.querySelector('.form-control')
Is this what you wanted?
var example = document.querySelector('.form-control').value;
document.write(example);
<input data-testid="user/fullName" autocomplete="name" class="form-control u-text-normal" value="test">
If you only want to select this element, use the most specific thing, in this case data-testid:
var x = document.querySelectorAll("[data-testid='user/fullName']")
console.log(x[0].value)
to select the element (here we select with the class and the data property to be the most accurate) =>
var element = document.querySelector('.form-control[data-testid="user/fullName"]');
After if you want add some value in this input =>
element.value = "My_value";
Regards
You can add 'id' or select your field by querySelector
let input = document.querySelector('[data-testid="user/fullName"]')
input.value='abc';
myField.value += '123';
<input id="myField" data-testid="user/fullName" autocomplete="name" class="form-control u-text-normal">
Update
I try my method and it works pizza site which you mention in your question update:
But it looks like that console 'see' dom input element after you find it using right click> inspect element - strange

Insert the value retrieved from localstorage to the input field

I am using localStorage where in I am able to store in previous page and retrive it in this page. (Checked it using alert).
name12=localStorage.getItem("content");
Now my requirement is to display it into the input field and make it non-editable.
Please help me out with it. I have tried different things but I am not able to get it right.
Used onblur="localStorage.setItem(this.name, this.value) in the input tag
and also tried to use
if name_2.value = name12; in script tag
To make a field uneditable, you can use the html attribute disabled on the input field. http://www.w3schools.com/tags/att_input_disabled.asp
To set a default value for a field, you can use the html attribute value. In your case since the value is dynamic, you probably want do not want to do that inline in the html. One possible solution is to set the value attribute through javascript like below.
<script type="text/javascript">
var name2 = document.getElementById("name_2");
name2.value = localStorage.getItem("content");;
</script>
Set the value of an input field
You have to assign the value to input using javascript.
<input username" id="name_2" type="text" placeholder="name" name="name_2" required="required" autofocus="autofocus">
<script>
var n = "5"; // read from storage here
var inpt = document.getElementById("name_2");
inpt.value = n;
inpt.disabled = true;
</script>
There are many places to find this information. Try reading the jquery documentation when you get stuck. For example, here is a page that describes how to set the value of an input element. StackOverflow also has many questions about this topic. A quick google search brings up this question about setting the value of input elements. We can also find SO questions about disabling input elements easily, like this one.
I encourage that you attempt to use more resources to find what you need before bringing your questions here.
Based on the answers to the questions I linked, we can set the input and then disable it to keep the value from changing:
$('#input').val(name12);
$('#input').prop('disabled', true);

How to accept name and number inputs and add them to the document/webpage

I've made a document in Word that I'd like people to add their names to, as well as their number of years experience teaching. I've saved it as a web page and posted it here:
http://epicforum.net/TS
...but the operative part is really just this:
http://epicforum.net/TSTest
It's similar to a petition, in that names are appended to the bottom of the document, but it needs more functionality than that, because I want to take the sum of the Years Experience fields and insert that sum in the document itself (i.e. "We, the undersigned, who represent "XXX" years of experience..." etc.). Once people hit the "Add my name as a signatory" button, it takes their name and Years Experience and inputs them in the next available empty row, then adds the next person's info on the next line, etc. Once they hit "Submit", the info is not editable. I don't need high security - nobody will care enough about this document to do anything malicious - but I want to avoid a user error like deleting someone's name who previously signed.
I found and edited HTML that would create the two fields to get input:
<form action="action_page.php">
Add my name as a signatory:<br>
<input type="text" name="FLName" value="Name">
<br>
Years Experience:<br>
<input type="number" name="YrsExp" value="Years Experience">
<br><br>
<input type="submit" value="Submit">
</form>
...but I don't know how to take the input fields and fill the empty lines in the doc with it, nor do I know how to limit the number input to positive number choices, and summing the total YrsExp in the doc isn't something that any posts I could find have addressed. Making it prettier (tabbing the input fields over to align with the text) is, I assume, pretty straightforward(?).
I'd prefer to have it be a separate popup window that takes the input, and found this code that supposedly did that:
<script>
window.onload=function()
{
var el=document.getElementById('button');
el.onclick=function(){
var my_text=prompt('Enter text here');
if(my_text) alert(my_text); // for example I've made an alert
}
}
</script>
...but that didn't create a popup window, and I'm not sure how to pass the input into the doc.
I don't know how to ask this so it's not a "code this for me" question, since the situation is pretty specific.
Where would I look to figure out how to do any of this?
I don't recommend using word to create a webpage .This is because word is sometimes pretty simple only for static pages.This means no stunning effects,no responsive design but mainly there is no interactivity(popups forms etc.)
the code for the alert should be:
<script>
window.onload=function()
{
var el=document.getElementById('button');
el.onclick=function(){
var my_text=prompt('Enter text here');
if(my_text) {alert(my_text); // for example I've made an alert
}
}
</script>
Now if you want to have a form that the user will enter something you can do it like this:
html
<input type="text" id="years">
<button onclick="experience()">Alert</button>
javascript
<script>
function experience(){
var user_input=document.getElementById('years');
alert("You have "+user_input.value+" years of experience");
}
</script>
Also.If you want to save each submitted value you will need a server side language such as PHP.Also the submitted values can't be saved in the original doc file.So you had better create a new .php file or .html file from the beginning.Here is a good site I found about php and forms submission
http://www.html-form-guide.com/php-form/php-form-tutorial.html

Javascript to get sharepoint form field value to a variable

I want to copy the content of a sharepoint form field to a variable using Javascript.
Eg. I have a field named "Language" in my sharepoint edit form. Now I just want to get the value of that field to a varaible x.
Please help.
BR
It depends on the type (e.g. user, lookup, multilookup, text, note, etc.) of field. I am using jQuery in my custom list forms and the name of the field for any given content type will be added to the id of the corresponding html control with the text 'Field' appended to it. However, like any typical asp.net control, the id of the html form control rendered to the client will reflect its control hierarchy so you have to account for that when searching for a field. anyhow, the following works for me if i need to reference fields in my custom forms. ** notice the +Field which implies that the name of the field is concatenated with 'Field'
var $titleField = $('input[id*=TitleField]');
var $lookupField = $('select[id*=Name_Of_Field+Field]')
var $multiLookUpCandidate = $('select[id*=Name_Of_Field+Field][id*=SelectCandidate]')
var $multiLookUpResult = $('select[id*=Name_Of_Field+Field][id*=SelectResult]')
var $note = $('textarea[id*=Name_Of_Field+Field]');
You can pick up on the trend by viewing source and seaching for your contenttype/sitecolumn field name. You will find it in an html form control id. use that information to learn how to reference other field types.
Without posting your code its very difficult to understand what you want to do.... to get a value from a form you can do the following :
HTML
<form id="myform">
<input id="myinput" type="text" value="something" />
</form>
JavaScript:
var myinputval = document.getElementById("myinput").value;
myinputval would be "something" in this example
Demo : http://jsfiddle.net/Qk6FZ/
This might help:
http://depressedpress.com/2012/09/24/obtaining-a-javascript-reference-to-a-sharepoint-field/
Using that function you'd get the reference using something like:
var LanguageFld = getFieldRef("Language");
Once you have the refernece it's easy to get the value:
var CurValue = LanguageFld.value;
Hope this helps!

Categories