-1
I need a hand here !
<script>
window.onload = function() {
var oTextbox = document.getElementById('myTextBox');
for (var i = 0; i < document.oTextbox.length; i++) {
document.oTextbox[i].onfocus = function() {
oTextbox.value = this.alt;
};
for (var i = 0; i < document.images.length; i++) {
document.images[i].onclick = function() {
oTextbox.value = this.alt;
};
}
};
</script>
I took this script right here on the stack at script link , and use with an input and various images works perfectly ! but when using the php script in foreach, it creates several inputs but all with the same name, I imagine it is possible to click or set on Focus in the input and click on the image the same can, pass the values to another selected field!
my foreach!
<?php foreach($data["category"] as $categ):?>
<label><?=$categ->name;?></label>
<input type="text" name="img_ent" id="myTextBox" value="Imagen entrada"
class="form-control" placeholder="Imagen Entrada">
<?php endforeach; ?>
Explaining better !
I took the script that I click on the image it automatically already puts the name of the image in the input ok, so everything well works, what I did was to input the loop foreach with php, It’s okay too, it generates several inputs according to my database example 5 ... Dae comes the problem when generating these 5 inputs I click on the image and it does exactly what it does without the loop, it just adds the text in the first input even though I click on the second input it adds to the first one the same way! Dae thought that how to make on Focus the other inputs because Dae by clicking on the input and selecting by clicking on the image it passed the values to the other input. I can’t imagine if it’s possible...
How are you applying the
foreach
in your code?– Valdeir Psr
There’s a problem with that code: the first
for
makes count of Ids, which is a bad practice in HTML. An ID should be unique on the page, therefore it should not even be counted. Another thing is that your question does not explain clearly what you want and makes confusion: "click or set on Focus in the input and click on the image the same can, pass the values to another selected field"...– Sam
explaining mlehor recast question!
– Carlos Coelho
as I said I click on an image it will pro input first but if I click on input 2 instead of going to the second it sends the text pro first
– Carlos Coelho
var oTextbox = Document.getElementById('myTextBox')!
– Carlos Coelho
i have 200 images the amount of imagen does not inport what inport and input in case!
– Carlos Coelho
I believe that you should do this var first = Document.getElementById("textbox1"). value; var Second = Document.getElementById("textbox2"). value;
– Carlos Coelho
If I’m not mistaken when clicking on the input it has the focus but if you click on something else it loses its focus. The best thing to do is to post all the code so we can test
– user60252
@The problem is that the question has a huge text and says nothing. It’s a confusion of words "click on it, lose focus on that other, click on the image, click on the input, throw the value back and forth"... I had to vote to close for lack of clarity
– Sam
Very obvious, what’s not obvious is
pois dae ao clicar no input e selecionar clicando na imagen
– user60252
@dvd the question is clear, you q is sleepy and seeing things :D
– user60252
@Leocaracciolo rsrs... clear as water.
– Sam
https://jsfiddle.net/carloscoelho/5xm84f70/2/
– Carlos Coelho