I would like to copy text from a field that is a postcode to another postcode field on selecting "As Above" check box, currently it copies the address fields, not the postcode. The field is using the COMB option spreading the input over 4 boxes, I am thinking this is why my current script wont work on this field, the scrip I am using is
//Set the source and destination vars:
var source = this.getField("Tradingaddress");
var destination = this.getField("Mailingaddress");
//See if destination is empty and if so, insert source value
if(destination.value==''||destination.value==null) {destination.value=source.value}
Any Help appreciated!
Ok so I used the same script as above, but before adding the custom script, i changed the field so it doesn't have a comb, and is just a standard field, added the script and worked, then went back into the properties of both fields and re-added the comb function and re-tested OK!~ :) Thanks for your help ME haha
Related
I am struggling with this and can't get it to work. I am using jQuery to click on a link that will open me a prompt. In this prompt, I want the user to add a URL to link it to some other websites. That works fine, but I can't get the value of the prompt to be shown properly in the input field.
The error I am getting after adding my text in the prompt is the fact
that it outputs it like [Object object].
I do know how to do this in plain JS, but not in jQuery and I need jQuery.
This is my code:
$(".html-button").on("click", function () {
var urls = prompt("Add a link", "http://");
var setText = $("#post-text").val().append('<a href="'+ urls + '"</a>');
// Adding prompt text into my input field
$("#post-text").val(setText);
});
I thought I could do this by using append instead of innerHTML, which I would use in plain JS... Can someone help please?
PS: preferably I would not want to output the anchor already in my input field, but only after submitting the post, but this is a nice to have.
Edit: Fiddle link
You seem to have mixed up some variables here. You are assigning the value of the prompt response to var urls, but then expecting it to be in an undefined var person (guessing you've used the example for this from the W3 Schools Tutorial (https://www.w3schools.com/jsref/met_win_prompt.asp)).
Assuming that your input element has an id of post-text - then you would do this:
$("#post-text").val(urls);
I am working on the assumption here that you're writing the URL into an input field, as you suggest. If you want those a tags in the input field as well then it would be:
$("#post-text").val('<a href="' + urls + '"</a>');
If your intention is to output it as a link somewhere including the HTML 'a' tags so it can be clicked, then you'd need to append it to an appropriate element (not a input field) in the right place in the DOM/on the page.
Lastly, if you want to write the value into the field after the form as been submitted (for whatever reason) you could either store it in a variable and write it on submit, or perhaps in a hidden field. I am unsure why you would want to do this though.
Hope this helps.
I have one Text Box (also called "Text Entry") in my qualtrics survey in which I want participants to write something but I do not want to have the result saved in my data. I do not want to use the password function, therefore I have used JavaScript at the Text Box level.
The code below works to the extent that whatever participants put in the Text Box it will be set to an empty string the moment they hit the Next-Button.
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place Your Javascript Below This Line*/
var currentQuestionID = this.getQuestionInfo().QuestionID
var input = $("QR~"+currentQuestionID);
$('NextButton').onclick = function (event) {
input.value = ""
}
});
The problem: This code only works sometimes. For example when I have two textboxes with the exact same code it only works for the first but not the second one. Similarly for some reason if the textbox is embedded in some other questions it doesn't work either.
Does anybody know how I can make this work either by changing my code or with a completely different solution? Essentially, I just want participants to entry some text which will never be saved in my data and I cannot use the password function.
Solution: One way of solving this would be adding a "Descriptive Text" item in which you can add some simple HTML code:
<p>Please provide your email address:</p><p><br></p>
<input name="nothing" type="textarea">
I don't think JavaScript works well in this case as it can't be guaranteed to run before the page has sent the data.
The best way is to make a dummy HTML "question" which has the appearance of a form but does not save any information.
I tried this out in a test survey by adding a question of type "Descriptive Text", and then in "HTML View" for that question, adding:
<p>This is not a real question, there is just a HTML textarea. </p>
<form id="mydummyform">
<input name="nothing" type="textarea" />
</form>
I found that this sometimes showed the HTML source instead of the form in the survey editor; if it does this, just go to "HTML View" and then "Normal View" and it should resolve correctly. This problem was only in the editor -- it always showed correctly in a preview of the survey.
I am trying to disable a textbox in SharePoint WSS3 and force a specific value (given by another JavaScript function) but I can't seem to find the right way of doing it. I have come across different issues. Let's say I have a normal single line text value named prova and another one named Description. Description is required, prova is not.
First Issue: If the field IS required, even if there is something in the textbox, SharePoint says otherwise and does not allow me to insert the entry.
$(document).ready(function(){
//var value = someFunction(...);
var value = "test";
$("input[title='Description']").attr("disabled", "disabled");
$("input[title='Description']").val(value);
});
Second Issue: If the field IS NOT required SharePoint doesn't say anything but it inserts a blank value instead of the one given.
$(document).ready(function(){
//var value = someFunction(...);
var value = "test";
$("input[title='prova']").attr("disabled", "disabled");
$("input[title='prova']").val(value);
});
I have a feeling that tells me that there is some kind of SharePoint JavaScript function somewhere that listens for KeyUp or something. I have really no idea what to do now...
EDIT: It looks like the problem is related to disabling the textbox, if I comment the line where I disable the textbox it works in both scenarios. Maybe if I catch the insert request I can re-enable the textbox before SharePoint do the actual post. No idea how to do it though...
Your problem really is related to disabling the textbox first. By default disabled textboxes are not contained in the POST request in IE.
See this post: Disabled form inputs do not appear in the request or this one: how to save data by disabled text box?
What you actually want to do is set the readonly attribute of the field, not disable it (readonly="readonly"). The problem with that is that the readonly state sometimes looks the same as the default state, so you also have to add some CSS to make it look greyed out.
So I have two forms, both have a file type input field and I tried
$('.inputfield1').change(function(){
var file = $(this).val();
$('.inputfield2').val(file);
});
but then it doesn't get copied properly and firebug complains about "Security Error" in the error console
what did I do wrong and how can I properly copy the value of a file input field
by the way, the destination form has a target that is set to an iframe (not a different domain)
You can't move the value of one file input to another. Instead, clone the input, place the clone where the original is, and move the original into the hidden form.
$(".inputfield1").change(function(){
var $this = $(this), $clone = $this.clone();
$this.after($clone).appendTo(hiddenform);
});
If you need to copy the file from one input to another, you could use the below method.
$(".inputfield2")[0].files = $(".inputfield1")[0].files;
I know it is a late answer, but I had a similar problem that I just figured out today.
What I did was move the File input to the new location after deleting the current one in the other location. By moving the element, everything stayed intact on all my tests.
$('.inputfield1').change(function() {
$('.otherinputfield').remove();
$('#newform').append($(this));
});
How can I copy the form field values from one set of fields to another using javascript.
The idea here is to have a 'use shipping/billing address' type of button that copies the user information from one block of fields to another identical set of fields.
Right now, I call an action upon click of a button to execute the following javascript:
this.field1.value = this.field2.value;
However that action yields an 'undefined' error in the debugger.
For posterity, this is the solution to the problem:
getField("field2").value = getField("field1").valueAsString;
Also, note that field2 is set to field1 so the order is backwards.
I used the following code to avoid overwriting the value in the second field if it has something in it already:
//Set the source and destination vars:
var source = this.getField("Box1");
var destination = this.getField("Box2");
//See if destination is empty and if so, insert source value
if(destination.value==''||destination.value==null){destination.value=source.value}
I used it on "On Blur" of the source Field, but you could use a button with "Mouse Up" as the trigger. (I found the code on this website. It includes more complicated options for populating multiple fields or even joining values from two source fields into one destination field.)