Is it possible create a javascript string that, when manually copied and pasted to another web page, will paste information across multiple input fields at the same time?
For instance, suppose a webpage has two input fields. I cannot edit the webpage html, but I can type into the input fields. I can also paste information in, using Ctrl-V or the like.
I have another webpage, which I can edit. The javascript for my webpage creates a string such as "Input for in1 here \t Input for in2 here". That string is presented through window.prompt(myString). I copy myString from the prompt (Ctrl-C), switch to the other webpage with input fields, and paste the string (Ctrl-V). How can I format my string so it pastes across both input fields?
Is it possible to format the string (myString in the example here), so that it will do this?
Obviously "\t" won't work for this. Same for "\n", etc.
Basically, I'm trying to create a helper for data entry. One web page would have the helper javascript. The other page (not in the same domain) would have multiple data input fields.
The data input page does not have an API hook.
Are you saying you would have a prefilled value in the prompt of:
"Input for in1 here Input for in2 here"
So for example if were looking for First and Last name
"Chris Johnson"
You could use substr() and indexOf() to find the space:
var firstInput = str.substr(0,str.indexOf(' '));
var secondInput = str.substr(str.indexOf(' ')+1);
Heres a fiddle
http://jsfiddle.net/1v2tn8p4/
After doing more research, it appears this is possible in some limited circumstances by using a bookmarklet.
For my question above, once the id of the input fields is found, I can use bookmarklet code to auto-fill in the values of those input fields.
Related
I am modifying a pdf as fillable. I have changed the spacing between the letters in the fields. as one number into a single cell. How to do this with JavaScript?
The following code didn't work either
var field = this.getField("field1");
var textField = field.getArray()[0];
textField.textFont.textState.charSpacing = 1.5;
How to do this?
You would use comb fields, and you set the distance between characters via the field length and the charLimit property.
You also could set the richText property for the field. However, programmatically dealing with richtext fields is a bit messy. Therefore, comb fields are preferred in such a situation.
I'm currently working on the following example found on http://www.webslesson.info/2017/07/live-add-edit-delete-datatables-records-using-php-ajax.html (entire code has been listed on this page) - everything works well for me apart from NewLine/Carriage return.
Whenever I press 'enter' key in the First Name or Last Name field, in order to add a new line, it basically won't recognize it.
In the source page file I added the code listed below after the: function fetch data() - please see the link: http://jsbin.com/yufovobinu/edit?html,output
but seems like it didn't help and carriage return/new line is still not recognized in Last Name field. I'm using Last Name field as a generic example, but it will happen to any text i would input to that field.
Additionally I'm including a video to visualise what happens when i type text in 'Last Name' field and then hit on 'enter' key and in order to insert data to mysql database (it sends data without new lines and returns it without new lines ): http://www.filedropper.com/issue
Please help! Thanks in advance!
$(document).ready(function() {
$('#user_data').keyup(function() {
$('#data2').html($(this).val().replace(/\r?\n/g, '<br />'));
Ok now I understood what are you trying to do exactly. You don't need at all the keyup event, also you can send the data by ajax as it is, and store it in the database with the new line character unchanged in the text.
For displaying correctly the stored values when you print the table you have to output from PHP:
echo nl2br(htmlentities($row['columnName']));
Where htmlentities prevents other HTML tags from being executed (XSS vulnerability) and then replaces in a smart way all kind of new lines (\r, \r\n, \n) with a <br> tag using the PHP's native optimized function nl2br.
Hey I'm trying to create an input field in javascript with a Rails back-end.
I would like to make the input field take only currency amounts. so
$1.00
$100.24
How could i pull this off. Currently a person can put in multiple decimal points and so on.
Hopefully this question is not too vague.
Bind this function to the onchange event of your text field. This will parse the value of the field as a float and remove any number after 2 decimals.
You can also use input type="number" to prevent strings as input.
Needless to say, this will require server-side validation. The user can disable Javascript and input type fairly easily: never expect this to work if these data will get back to your server.
function check(e){
e.value = parseFloat(e.value).toFixed(2)
}
working jsfiddle: here.
input: 123456 - result: 123.456
input: 12,3456 - result: 12,34
I'm developing a portlet for WebSphere Portal 6.1, with JSP/JSTL, pure javascript, no AJAX frameworks, with a JSP that shows a send feedback form and, when submitted, redirects to another JSP to show the user the success of the operation.
I use javascript to get the values of the form fields by using document.getElementById() function. For example:
var valorAsunto = document.getElementById("asunto").value;
where "asunto" is the ID of a text field in my form. Also my form has the following structure:
<form name="formularioCorreo" id="formularioCorreo" method="post" action="<portlet:renderURL><portlet:param name="nextTask" value="sendFeedback"/></portlet:renderURL>">
That works OK, but I'm having trouble when trying to build the <portlet:renderURL> tag from that javascript values: when I try to concatenate a string for the renderURL and then reassign to form action like this:
var valorAction = '<portlet:renderURL><portlet:param name="nextTask" value="sendFeedback"/><portlet:param name="asunto" value="'+valorAsunto+'"/></portlet:renderURL>';
document.formularioCorreo.action = valorAction;
document.formularioCorreo.submit();
The resulting string, when application is deployed, has the structure:
/wps/myportal/<portletpath>/!ut/p/c5/<a very long random sequence of
numbers and letters>/
So one can't figure out where the parameter values are, but if I print the assigned values it shows something like:
asunto: '+valorAsunto+'
instead of
asunto: this is a sample subject
I've been trying to use some other ways to concatenate the string; for instance with a StringBuffer, as shown on http://www.java2s.com/Tutorial/JavaScript/0120__String/StringBufferbasedonarray.htm
and also javascript functions like encodeURI()/decodeURI(), replace(), etc. but I just can't get either the URL with the right parameter values or the URL encoded in the structure shown above (the one with the long sequence of chars).
Sometimes I manage to get the right parameter values, by manually replacing in the valorAction assignation all the "<" for "<" and all the ">" for ">" before the concatenation, and then doing the following:
var valorAction = valorAction.replace(/</g,"<").replace(/>/g,">");
Then I get the following string:
<portlet:renderURL><portlet:param name="nextTask" value="sendFeedback"/><portlet:param name="asunto" value="this is a sample subject"/></portlet:renderURL>
which is OK, but when it has to redirect to the results page it shows an error like this
Error 404: EJPEI0088E: The resource <portlet:renderURL><portlet:param
name="nextTask" value="sendFeedback"/><portlet:param name="asunto"
value="this is a sample subject"/></portlet:renderURL> could not be
found.
Does someone know how to transform that string to the right format to be rendered?
Does someone know any other way to "inject" that parameter values to the renderURL?
I'd like to know also if it is possible to pass that parameter values from javascript to JSP so I could put that values in a HashMap of parameters to use with the PortletURLHelper.generateSinglePortletRenderURL() method, in case the former is not possible.
Thank you.
Update 1:
In my doView() I use the following, in order to make the redirection:
String targetJsp = "/_Feedback/jsp/html/FeedbackPortletView.jsp";
String nextTask = request.getParameter("nextTask");
//(... I have omitted code to conditionally select targetJsp value, according to nextTask value ...)
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(targetJsp);
rd.include(request, response);
This is just a new JSP inside my portlet, not a different portal page. I do use request.getParameter() to get the values for my form fields from my doview():
String subjectFeedback = request.getParameter("asunto");
String bodyFeedback = request.getParameter("mensaje");
String emailFeedback = request.getParameter("emailFeedback");
I don't see the need to include hidden fields if my form has the fields named above. In fact, what I'm trying to do is to pass the values the user entered in these fields as request parameters, but the values I get by this means are the following:
subjectFeedback: "'+valorAsunto+'"
bodyFeedback: "'+valorMensaje+'"
emailFeedback: "'+valorEmailFeedback+'"
I get the above values when using concatenation by "+"; when I use StringBuffer I get the following values:
subjectFeedback: "'); buffer.append(valorAsunto); buffer.append('"
bodyFeedback: "'); buffer.append(valorMensaje); buffer.append('"
emailFeedback: "'); buffer.append(valorEmailFeedback); buffer.append('"
Does someone know any other way to "inject" that parameter values to the renderURL?
There are two IBM guides on that topic.
Portal 6.1 and 7.0 Advanced URL Generation Helper classes
How to create a link to a portlet (Standard API) that passes parameters to that portlet
How are you redirecting to the other page? Is it a different portal page or just a new JSP page inside your portlet?
You don't need to inject any parameters to the render URL. Have a form whose action targets to a renderURL. Now to pass information to your portlet's doView() method, you can have hidden fields in the form ,then populate them using JavaScript and then submit the form. In the doView() method, you can use request.getParameter() to get the parameters.
Well, sometimes the most obvious things happen to be the way to the solutions.
I was too busy trying to find elaborated causes for that situation that I did not checked for this at all:
My form fields were correctly identified by different id, but they weren't set their name properties.
With the help of a work partner we could figure out that, so assigning the same value of id for name on each form field did the trick.
So, I ended up skipping that reassigning action thing, because the field values are being set as request parameters, as it should be.
Thanks for the help.
I have an HTML form that a user can add an arbitrary amount of input fields to through jQuery. The user is also able to remove any input field from any position. My current implementation is that each new input box has an id of "field[i]" so when the form is posted it is processed in Python as field1, field2 field3, ...field[n]
i = 0
while self.request.get("field" + str(i)):
temp = self.request.get("field" + str(i))
someList.append(temp)
i += 1
(Assume the JavaScript handles removing of deleted elements and sorts the field names prior to post for simplicity)
This approach is working for me, but is there a better way to handle this situation? I feel like this is a very brute force method.
Platform information: Python 2.5.4; JavaScript; DHTML; jquery; Google App Engine
Edit: It appears that self.request.get_all() was the solution: GAE Doc
You could serialize the data with javascript and pass it in as json. Then you would just have a dictionary to work with in python. You would need something like simplejson, of course