I am try to create an Adobe InDesign script that will select text, change the selected text to Uppercase and then copy the same text.
I am stuck.
#target "InDesign"
var myDoc = app.activeDocument;
if(app.documents.length != 0){
if(app.selection.length == 1){
try{
//var text = app.selection[0].
var frame1 = page.textFrames[0];
//var frame2 = page.textFrames[1];
frame1.texts.everyItem().select();
//frame1.
app.copy();
}
catch(e){
alert ("Please select text", "Selection");
}
}
else{
alert ("Please select text", "Selection");
}
}
else{
alert("Something wrong");
}
var myDoc = app.activeDocument;
if(app.documents.length != 0){
if(app.selection.length == 1){
try{
//var text = app.selection[0].
//var frame1 = app.selection[0].textBoxes[0].contents;
var frame1 = app.documents[0].pages[0].textFrames[0];
frame1.contents = frame1.contents.toUpperCase();
}
catch(e){
alert ("Exception : " + e, "Exception");
}
}
else{
alert ("Please select text", "Selection");
}
}
else{
alert("Something wrong");
}
Here it is using the selected object:
var myDoc = app.activeDocument;
if(app.documents.length != 0){
if(app.selection.length == 1){
try{
var frame1 = app.selection[0];
frame1.contents = frame1.contents.toUpperCase();
}
catch(e){
alert ("Exception : " + e, "Exception");
}
}
else{
alert ("Please select text", "Selection");
}
}
else{
alert("Something wrong");
}
Copying to clipbaord:
var myDoc = app.activeDocument;
if(app.documents.length != 0){
if(app.selection.length == 1){
try{
var selectedStuff = app.selection[0];
//upperCase the selection right away.
//If a textFrame is selected, everything in the TextFrame gets upperCased.
//If only part of the text is selected, then only part of the text is upperCased.
selectedStuff.contents = selectedStuff.contents.toUpperCase();
///////////////
//app.copy(copies the selected Item, not only Text) so find out what's is selected before you shove it onto the clipboard.
if(selectedStuff instanceof TextFrame){
//The selected item was a textFrame, a TextFrame can't be pasted into Notepad, so lets select all the text in that frame instead.
app.selection = selectedStuff.texts;
}
//Now copy the selection. At this point, only TEXT should be selected, so pasting should always work.
app.copy();
}
catch(e){
alert ("Exception : " + e, "Exception");
}
}
else{
alert ("Please select text", "Selection");
}
}
else{
alert("Something wrong");
}
Related
We have a small issue here .Magento1.9.2.
we had set the minimum order qty in SYS>Inventory
as 1 . After that , all Newly created CONFIGURABLE PRODUCTS are not displaying Size Swatch, QTY button or ADD TO CART button in products page . We had reindex all the data . Still it did not change . We have now set the Minimum Order Quantity back as 0 (zero)
Even after that , the newly created configurable products are not showing Size Swatch or ADD TO CART button .
Qty Button and ADD TO CART button appears for Simple Products .
Please let me know what's to be done ..thanks
Screen Shot enclosed
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
productAddToCartForm.submitLight = function(button, url){
if(this.validator) {
var nv = Validation.methods;
delete Validation.methods['required-entry'];
delete Validation.methods['validate-one-required'];
delete Validation.methods['validate-one-required-by-name'];
// Remove custom datetime validators
for (var methodName in Validation.methods) {
if (methodName.match(/^validate-datetime-.*/i)) {
delete Validation.methods[methodName];
}
}
if (this.validator.validate()) {
if (url) {
this.form.action = url;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm);
//]]>
Hope the info helps . Thanks for all the help in advance.
I've seen all the posts about this issue but I still can't get the enter key to work in Firefox. Here are all my iterations of code and I've obviously changed it a hundred times to try and make it work. I can get it to work in IE, not Firefox. Alternate question: I'm new to xPages. Where do I define a function in an xPage or do I have to make a script library and add it to resources? Thanks all.
Mike
var metaChar = false;
var key = event.keyCode || event.which;
if (key == 13) {
metaChar = true;
event.returnValue = true;
alert("true13");
}
if (key != 13) {
if (metaChar) {
alert("false");
metaChar = false;
} else {
alert("true");
event.returnValue = false;
}
}
/*
var vevent = event.keyCode || event.key // IE does not pass event to the function
if(vevent == window.event){
code = event.keyCode;
}else{
code = event.key;
}
if(code == 13){
event.returnValue = true;
alert("True");
} else {
event.returnValue = false;
return false;
alert("False");
}
*/
var e = event.keyCode || event.which;
charCode = e.keyCode || e.which;
if(charCode == 13){
return true;
alert("True");
} else {
return false;
alert("False");
}
I suspect your issue lies in trying to use event in your javascript. In XPages you need to use a different reference thisEvent, some info at this link under "Getting event information". This is a quirk of the way XPages adds events on page load.
For your situation, I created a simple example XPage, which shows you how to capture the enter key in an eventHandler or using an inline function if you want to go that route. This works for me in Chrome, Firefox and Internet Explorer 11.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:panel id="panel1">
<script type="text/javascript">
var enterKey = function(eventParam) {
var key = eventParam.keyCode || eventParam.which;
console.log("key = " + key);
if (key == 13) {
alert("script function - enter");
return true;
}else{
alert("script function - other character");
return false;
}
}
</script>
<xp:inputText id="button1">
<xp:eventHandler event="onkeypress" submit="false">
<xp:this.script><![CDATA[
var key = thisEvent.keyCode || thisEvent.which;
console.log("key = " + key);
if (key == 13) {
alert("button event script - enter");
return true;
}else {
alert("button event script - other character");
return false;
}
]]>
</xp:this.script>
</xp:eventHandler>
</xp:inputText>
<xp:br />
<xp:br />
<xp:inputText id="button2">
<xp:eventHandler event="onkeypress" submit="false">
<xp:this.script><![CDATA[
enterKey(thisEvent);
]]>
</xp:this.script>
</xp:eventHandler>
</xp:inputText>
</xp:panel>
</xp:view>
I have a form validation script all the validation work. but the fields clear up when the alert about the passwords not matching shows up? how can i avoid that?
<script type="text/javascript">
function formValidator(){
// Make quick references to our fields
var FNAME = document.getElementById('FNAME');
var LNAME = document.getElementById('LNAME');
var EMAIL = document.getElementById('EMAIL');
var GENDER = document.getElementById('GENDER');
var ADDRESS = document.getElementById('ADDRESS');
var CONTACTNO = document.getElementById('CONTACTNO');
var PASSWORD = document.getElementById('PASSWORD');
var PASSWORD2 = document.getElementById('PASSWORD2');
// Check each input in the order that it appears in the form!
if(isAlphabet(FNAME, "Please enter only letters for your first name"))
{
if(isAlphabet(LNAME, "Please enter only letters for last name"))
{
if(emailValidator(EMAIL, "Please enter a valid email address"))
{
if(madeSelection(GENDER, "Please Choose a Gender"))
{
if(isAlphanumeric(ADDRESS, "Numbers and Letters Only for Address"))
{
if(isNumeric(CONTACTNO, "Please enter only numbers for Contact No."))
{
if(lengthRestriction(PASSWORD, 6))
{
if (PASSWORD2 != PASSWORD)
{
alert ("You did not enter the same new password twice. Please re-enter your password.");
return true;
}
}
}
}
}
}
}
}
return false;
}
i think that there is no problem with my other functions?
function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
alert(helperMsg);
elem.focus(); // set the focus to this input
return false;
}
return true;
}
function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function isAlphabet(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function isAlphanumeric(elem, helperMsg){
var alphaExp = /^[0-9a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function lengthRestriction(elem, min){
var uInput = elem.value;
if(uInput.length >= min){
return true;
}else{
alert("Please enter atleast " +min+ " characters");
elem.focus();
return false;
}
}
function madeSelection(elem, helperMsg){
if(elem.value == "Please Choose"){
alert(helperMsg);
elem.focus();
return false;
}else{
return true;
}
}
function emailValidator(elem, helperMsg){
var emailExp = /^[\w\-\.\+]+\#[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(elem.value.match(emailExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
</script>
i guess that i'm doing this part wrong?? but i don't know how to fix it? please help.
if (PASSWORD2 != PASSWORD)
{
alert ("You did not enter the same new password twice. Please re-enter your password.");
return true;
}
Try to do something like:
if (PASSWORD2.value == PASSWORD.value)
{
alert ("You did not enter the same new password twice. Please re-enter your password.");
return true;
}
}
How to check if any of 4 fields I have is filled in? If any of them is filled in, then it's fine, if not, it's not.
$("#sendMsg").click(function(){
var name = $("#name").val();
var email = $("#email").val();
var subject = $("#subject").val();
var message = $("#message").val();
if(name == ""){
$("#errorMsg").show();
return false;
}
if(email == ""){
$("#errorMsg").show();
return false;
}
if(subject == ""){
$("#errorMsg2").show();
return false;
}
if(message == ""){
$("#errorMsg3").show();
return false;
}
});
if (document.getElementById("idfield1") === undefined)
{
// do noting
}
else
{
// do something
}
I am using window.onbeforeunload in my javascript.
This works perfectly in IE but is not triggered in Firefox.
I checked on different links in stackoverflow.... In it I read that window.onbeforeunload is not supported by firefox. Is this true?
If yes, can you please tell me a different way to call app.deleteAccount(key) on close of browser. Here is my javascript. Please look at the deleteFile() and dontDeleteFile() methods.
<script type="text/javascript">
//Event handler for body onload
function confirmDeleteFile(){
var secured =document.r_form.Secure[1].checked;
alert("confirmDeleteFile : "+secured);
if(secured){
var agree=confirm("Are you sure you wish to continue?");
if (agree){
//document.form1.submit();
return true;
}
else
return false ;
}
// submitForm();
return true;
}
function deleteFile() {
alert('inside deleteFile() but outside window.onbeforeunload');
window.onbeforeunload = function(){
var key = DOMAIN+'::' + elem('userName').value;
alert('inside deleteFile()');
app.deleteAccount(key)
alert('Unloading!');
}
}
function dontDeleteFile() {
alert('inside dontDeleteFile() but outside window.onbeforeunload');
window.onbeforeunload = function(){
alert("Not deleting");
}
}
function validateFormOnSubmit(theForm) {
var reason = "";
var userName = theForm.username.value;
var pin = theForm.pin1.value;
var PAM = theForm.pam.value;
var organization = theForm.organization.value;
//reason += validateUsername(theForm.username);
reason += validateEmpty(theForm.pam);
reason += validatePinMatch(theForm.pin1,theForm.pin2);
reason += validatePin(theForm.pin1,theForm.pin2);
if (reason != "") {
if(!confirmDeleteFile()){
return false;
}
alert("Some fields need correction:\n" + reason);
return false;
}
else{
if(!confirmDeleteFile()){
return false;
}
<% String url = request.getServerName().toString();
int port = request.getServerPort();
String contextPath = request.getContextPath();
%>
var servlet = "arcotebank.az"; //AroctEBanking Servlet
var url = BASE_URL + '/' + servlet;
var query = 'lang=en&reqid=1&version=1.1';
query += '&device=' + urlEncode(navigator.userAgent);
query += '&uid=' + urlEncode(userName);
query += '&code=' + urlEncode(PAM);
query += '&pin=' + urlEncode(pin);
query += '&usePin=' + usePin+'&method=arcotOTPEnroll&organization='+organization;
//alert("url=>"+url + '?' + query);
var xml = app.openUrl(url + '?' + query) + '';
//alert("xml=>"+xml);
if(appError()){
alert("applet error");
}
var domain = getDomain(url);
app.provisionAccount(domain, xml);
if(appError()){
alert("applet error");
}
var acc = app.getAccount(DOMAIN + '::' + userName);
if(acc!=null){
<%String formSubmitAction1 =
URLEncoderDecoder.encodeURL(
formAction,
"Action.2FA.Arcot.Navigation.LogoutActionCalled=Y",cm);%>
theForm.action ='<%=formSubmitAction1%>';
var secured =document.r_form.Secure[1].checked;
alert("line 131 "+secured);
if(secured){
deleteFile();
}else{
dontDeleteFile();
}
theForm.submit();
}else{
document.getElementById("error").innerHTML = "Failed to Create ArcotOTP";
}
}
}
function resetForm(){
var form = document.forms[0];
form.username.value = '';
form.pam.value = '';
form.pin1.value = '';
form.pin2.value = '';
}
function validateUsername(fld) {
var error = "";
var illegalChars = /\W/; // allow letters, numbers, and underscores
if (fld.value == "") {
fld.style.background = 'Yellow';
error = "You didn't enter a username.\n";
} else if ((fld.value.length < 5) || (fld.value.length > 15)) {
fld.style.background = 'Yellow';
error = "The username should contain more than 4 characters.\n";
} else if (illegalChars.test(fld.value)) {
fld.style.background = 'Yellow';
error = "The username contains illegal characters.\n";
} else {
fld.style.background = 'White';
}
return error;
}
function validateEmpty(fld) {
var error = "";
if (fld.value.length == 0) {
fld.style.background = 'Yellow';
error = "You didn't enter Personal Assurance Message \n"
} else {
fld.style.background = 'White';
}
return error;
}
function validatePin(pin1,pin2){
var error="";
if(pin1.value!=pin2.value){
pin1.style.background = 'Yellow';
pin2.style.background = 'Yellow';
error += "Pin numbers dont match\n";
//alert("Pin numbers dont match");
}
return error;
}
function validatePinMatch(pin1,pin2){
var error="";
if(pin1.value==""){
//elem('otp').style.background = 'Yellow';
pin1.style.background = 'Yellow';
error += "Pin number cannot be empty\n";
//alert("Pin number cannot be empty");
}
if(pin2.value==""){
//elem('otp').style.background = 'Yellow';
pin2.style.background = 'Yellow';
error += "Confirm Pin number cannot be empty\n";
//alert("Pin number cannot be empty");
}
return error;
}
</script>
Note that in Firefox 4 and later the returned string is not displayed to the user. See Bug 588292.
https://developer.mozilla.org/en/DOM/window.onbeforeunload
Maybe this is what's causing your problem in part. Also the example on the page might be better suited for cross-browser compatibility?
window.onbeforeunload = function (e) {
var e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = 'Any string';
}
// For Safari
return 'Any string';
};
window.onbeforeunload is supported by Firefox and all major browsers. It should be implemented as a function that returns a string, which will be used as the message in the confirmation dialog.