I'm trying to create a gym membership database and it needs to store pictures taken with the webcam of the customer. I have the cam working and once you take the picture you can use the below code to 'echo' the url of the file.
The below code loads a URL:
<script type="text/javascript">
function getSnap(linky){
alert(linky);
}
</script>
My question is how can I get it so the above code is automatically populated into a text field?
Any help would be appreciated :)
You would need to select the input field by either id or class and set the value to the returned URL. In the below case, we use ID, so it would be whatever is the ID tag of the input is.
<script type="text/javascript">
function getSnap(linky){
var elem = document.getElementById("myInput");
elem.value = linky;
}
</script>
<input id="myInput" />
Say you have a input called #example, you then place this instead of the alert
var example = document.getElementById('example');
example.value = linky; // set the value of an input
example.src = linky; // set the source of an image
example.innerHTML = linky; // Set as content of a div/block-element
example.href= linky; // set target for a anchor
Give your text field an ID (ex URL) and use document.getElementById('URL').value = linky;
Related
I am new to JavaScript. I am getting result from label from another javascript. Now I want to send it to the input type hidden. Please help on how to do it
Below is the code that I am getting result from javascript
<label id="result"></label>
here i want to change the year input value to the above label id=result value. Please help
<script type="text/javascript">
var post_title = new Date();
document.getElementById("post_title").value=(post_title.getFullYear());
</script>
<input type="hidden" name="post_title" id="post_title" class="form-control"/>
I would suggest bringing your <script> element all the way to the bottom of your HTML so that the rest of the HTML loads and you can avoid any errors where the element does not exist (As #Lain said in the comments)
We can get the inner value of the <label> using
var label = document.getElementById("result");
var labelValue = label.innerHTML; //What this does is it returns a string of all HTML and text inside this element, in this case it would just be the value
//Then using the rest of your code, set the post_title to the label value
var post_title = document.getElementById("post_title");
post_title.value = labelValue;
All of the above belongs inside of your script tags, in case that wasn't clear
Let me know if that works or if that's what you're looking for
I have a form where the user can dynamically add or remove sets of fields. For each set of fields, when the user enters/changes a value in the upc[] text input I want to make an Ajax query and populate the corresponding desc[] text input. I can capture the change event, but have not been able to read or modify the dynamically create desc[] field:
This snippet does not have the Ajax call as for now I just want to know I can set desc[x].val(). I have tried to associate the dynamic field with a parent element that existed when the DOM was created...but still no luck.
$(document).on('change', '.upcScan', function(){
var upcIdx = $(this).index('.upcScan');
var upcVal = $(this).val();
alert ("The current index is "+upcIdx+" and the value is "+upcVal);
var descName = "desc["+upcIdx+"]";
var descVal = $("#addClient input[name='"+descName+"']").val();
alert("desc field is "+descName+" and value is "+descVal);
});
The code above returns null. If I try to set the val nothing happens.
What am I missing?
So I am trying to get a user's first name so that I can display it on my chatting app. I have the user's information. I can get the user by playing around with res.render(). In jade I can do something like #{user.firstName} to have it printed out but I am not sure how I can use this data in jQuery.
Check if you can build an element as follwed:
case 1
<input id='user-first_name' type='hidden' value='#{user.firstName}' />
// Then you can use the value of input field as.
var firstName = $('#user-first_name').val()
case 2
you can directly write a script tag where you will initialize some window variables as :
<script>
window.user_first_name = #{user.firstName}
</script>
case 3
Also you can try assigning that value to data field of any html element(html tag) as followed :
<element data-first_name='#{user.firstName}'>
// Now you can use a jquery selector for selecting that element and you
// will be able to retrieve that value using data function
var firstName = $(element_selector).data('first_name');
I need to update a html 5 datalist via ajax.
Html code is here.
<body>
<input type="text" id="bar" list="fruit" onkeyup="jsfun()" />
<datalist id="fruit"></datalist>
</body>
A pseudo code of JavaScript.
function jsfun(){
//1- Get the last word from input field ("bar").
var skw1 = document.getElementById("searchBar").value;
var skw2 = skw1.split(" ");
var skw = skw2[skw2.length-1];
//2- Use Ajax to send data on server and get data result back
/*
* here goes other javascript content for ajax
*/
xmlhttp.open("GET","searchopt.php?skw="+skw,true);
xmlhttp.send();
//3- use javascript to update the datalist with those result which Ajax get.
}
see the below url here first write mang then remove it and write bann
it give a suggestion
then remove it and know write mango bann this time it can not give any suggestion.why but the suggestion is prensent in database.it give suggestion only for first word.
http://iws.uphero.com/qwe.html
Ok... here's the issue. Datalist by default matches what is in the text box with the allowed options. The options ARE changing properly via AJAX. What isn't changing is that "mango bann" isn't equal to "mango" OR "bann".
As a workaround, you could use your AJAX function to overwrite the text box once a second word was entered. For example:
var skw1 = document.getElementById("searchBar").value;
var skw2 = skw1.split(" ");
var skw = skw2[skw2.length-1];
document.getElementById("searchBar").value = skw;
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!