Cannot insert HTML value into another - javascript

I'm trying to have the value of an HTML element equal the value of another. Sounds simple enough but when I try various options, it doesn't work
Here's what I'm trying to do:
I tried a few things. First, I made a javascript function that when they info button is pressed, it simply sets the value of the newname textbox to the title and then I was going to use javascript to trim off the extension. As you can see on the page, it simply outputs {{modal_header}}. I believe this is because when the function is being called, the value hasn't been set yet and that's why it's outputting this. I couldn't find out where else to call the function in order for it to work.
To get around that issue, I tried using PHP to retrieve the name. The only thing I could find related to the name was which in stuck in the value property of newname, but this output only the last file in the directory, no matter what file you selected.
I tried a bunch of different little things, but without any luck. You guys have any ideas?
Website: http://box.endurehosting.com/
HTML: http://pastebin.com/dZ5rKGUY

try this code
$(function(){
var title = $("#title").html();
title = title.substr(0, title.indexOf('.'));
$("#newname").val(title);
})

Related

Not able to access an XML Element using .innerHtml with Javascript

this is my first post here so I hope that I do this right. I have searched for a day or so now and I haven't been able to find any direction so far so I guess it's time to ask. I am not able to access an element in my XML file. I can load the XML file, and get it saved into a variable and then in the debugger I can navigate to the information that I want to load into my DOM but when I try to access it using ".innerHtml" it is returning an empty string. I have also tried making sure that I am pointing to the correct node(?) inside of the XML Element by adding the [0] location to the "batch".
Here is my function:
function getBatchNumber(xml){
let batchHTML = document.getElementById('batch');
let batch = xml.getElementsByTagName('DIALOG5');
var test = batch[0];
batchHTML.textContent = test.innerHtml;
//batchHTML.textContent = "3151414";
}
In the debugger when I hover over "test" I can see that innerHtml is in the tree and has the correct number I am after. Then when I hover over innerHtml it is showing me that it has a value of "".
Thank you for any help or insight into this.

How to copy the value of a yform to an other field

In our (hybris) shop some products have a yform to summarize the parts of the product. Is there an easy way to copy the value of the sum field into an other field (automaticly) like the productquantity (no yForm)?
I guess I need javascript, but the id of the sumfield is generatad, so I don't know how to get the sum. Also my Javascript abilities are quite limited...
UPDATE:
To get the value I use this part of code:
copyYFormValueToProductQuantity : function() {
var copyText = document.querySelector('input[id*="sum"]').value
if (copyText > 0 && copyText != null)
{
//do stuff
}
console.log("Copied value: " + copyText)
},
But this line
document.querySelector('input[id*="sum"]').value
returns null. If I use it in the browserconsole, it also returns null. But after I inspected the element it works and returns the value I want to. So I guess I am missing some JS-basics here and the object isn't ready before?
Btw.: I call this function with a keydown-eventlistener.
This can most likely be done from the jsp files. There you have all the data that is needed, so you most likely need to only copy that field where you need it.
We can also help you more if you add some code examples here (what exactly is that yform?). If you struggle to find where in code is that specific yform created/added, it's always worth giving a try to search for the applied classes of the html (search the entire project and see what you find).
As I understand your question, you are saying that you want to copy the value of a yForm field named sum into a non-yForm field named productquantity, and you are asking specifically about how to access the value of a yForm field from JavaScript. If I understand this correctly, you can do so by calling the following JavaScript API:
ORBEON.xforms.Document.getValue("sum");
You can find more about this and other related API on Client-side JavaScript API.

How to store variable and set the variable in field

I'm using Selenium 3.17.0.
I want to type a text from a javascript, but it doesn't work!
I have tried this (this types the text "undefined")
and this (this types the entire script as text)
but nothing works! maybe I'm doing wrong the javascript but I don't know, I'm new in all of this, please help!
btw this is my first post, sorry if I'm doing it wrong.
If I understand your question correctly, you are trying to generate a random string using javascript and then store the value in a variable. Then enter that variable value using type.
you have to use execute script command to run the javascript and target (your javascript) should be return "free text" + Math.floor(Math.random()*100) as shown in the below screenshot.

How can I get combinationId from array of id_attributes

I use the Cart::updateQty() function in my module for prestashop. I'd like also to use the $id_product_attribute parameter, but I'm unable to find the desired value for this when I have array of id_attributes only.
I need behavior similar to the default selecting product attributes on the product page and then adding it to cart, but I'd like to do this on the server side.
What I was able to find out is that when I'm changing a product attributes on the product page, the html input with id="idCombination"
#idCombination
is being filled with a proper value and then it's being POST'ed with ajax to the server. Unfortunately, I cannot work out how the actual searching is being made and how to do this in js or php code.
Any help would be appreciated.
In a default product page these combinations are transferred with a variable $combination within a ProductController.php with a method assignAttributesGroups() and then defined a js variable inside product.tpl via condition
{if isset($combinations) && $combinations}
{addJsDef combinations=$combinations}
{/if}
after that everithing going on in a product.js file which do all switch job and substitute id="idCombination" after each changing.
So you can to repeat a default approach to implement your requirements even though it looks a bit complicated. Also, I think you don't need such a completed $combination variable with all that information and you can add only that what you need. I hope it clarifies you a direction to work.

Focus on a form field with a variable

I have a relatively simple issue I'm trying to resolve and can't seem to find anything about it.
I am working on existing product, after an error modal is closed I need to focus on a given form field, which at this point I will have stored in a variable.
Currently this works:
$("input[field='number']").focus();
I've simplified the variable names. No I have a variable as below;
myField = 'number'
But my attempts to focus on this are failing, I've tried:
$("input[field=myField]").focus();
$("input[field='myField']").focus();
As I said I've had a look around but sadly cannot find what I need. Any help would be greatly appreciated.
Thanks
You are using a variable name instead of its contents.
Try this
$("input[field='" + myField + "']").focus();

Categories

Resources