Adding a button beside a input control / Añadir un botón al lado de un control

Hi,
I’d like to add a button at the side of an input text, by example to generate a random password. This input text is associated with a field of the app. There’s any way to do this with scriptcase options? I’ve a trick to do it but is a lot of complicated, is to do it by javascript onLoad form event, but this requires a lot of code and the execution of javascript to this button click event is very complicated.

This trick it’s incredible! When I’ll try it, I will let you know if it works for my purposes!
Dani

It works! I’ve used a similar code as you, but I’ve included the class=“scFormObjectOdd” to the input element. And after that, I’ve included the code to the myFunction() directly in the onApplicationInit event as follows:


?>
<script type="text/javascript">
function myFunction() {
// Make something here...............
}
</script>
<?php

How can I use the value of the textfield? in the function I eg want to show an alert with the text of the field.

So if i use:

[I]onRecord: {test}=’<input type=“text” ><button onclick=“myFunction()”>Click me</button>’;

onScriptInit:[/I]

?> <script type=“text/javascript”> function myFunction() { alert({test}); or alert(’<?php echo $this->test ?>’); or alert(’<?php echo ‘{test}’ ?>’); } </script> <?php
but it’s not any code is working :frowning:

Suggestions

1 - Have you checked if myfunction() is defined as global function when you launch the javascript console when you play the app?
2 - You should consider to add an id=“button” for this button and then, create an onLoad javascript event with the next code (but you can’t apply php code here):


$('#button").click(function() {
***your js only code here***
});

This function part is working fine.

The question was how to use the value in a grid. Let us say i want to write this value in a table. What is the syntax for the reference to it since the field {test} is a textfield AND a button? Should i add an ID aswell?

Maybe an example?

Are you trying to use this code in a grid? This should not work, due the #button id will be repeated.

Yes i want to use this in a GRID. No other way to read the txtfield?

By the moment it’s a functionality I’ve never used, but I can inverstigate it how this can be done. You should capture each row id to perform this via some dom #idfield, but I don’t know which it is.

SOLVED! Try the next:
onRecord:


$sel = trim('id-txt-'.{id});
{text} = "<input type='text' id='$sel'><button onclick=\"foo('$sel')\">Clickme!</button>";

onApplicationInit:


?>

<script type="text/javascript">
    function foo(id) {
   
    console.log($('#'+id));
        alert($('#'+id).val());
    }
</script>
<?php

As you can notice, you force to create an id=“something” that must be unique, and you must use, of course the unique identifier of you grid field to generate the $sel php var to inject to html code. Then, ensure you use the javascript console to test if there’s any error and you can execute manually the foo function by calling by example foo(‘hello’)