Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RachidLaasri's avatar

This becomes so hard to follow, can you please explain what you are trying to do?

theUnforgiven's avatar

@Ruffles this is what I have:

$('.mobile').click(function(){ // it's #mobile in your example.
            var number =  $(this).data('mobile');
            var appendString = '<input type="text" name="to" class="form-control" disabled value="' + number + '" />';
            $(".toField").append(appendString);
        });

then the button:

                            <button type="button" data-toggle="modal" data-target=".bs-example-modal-lg" class="btn btn-link mobile" title="Click to send SMS" data-mobile="{!! $client->mobile !!}">{!! $client->mobile !!}</button>
mstnorris's avatar

Have you checked the source code? Does it show anything in the data-mobile attribute?

theUnforgiven's avatar

Yes if I do an alert(number) from this var number = $(this).data('mobile'); it does show the number.

theUnforgiven's avatar

Added an extra div like so:

<div class="col-lg-6">
        <div class="toField">

        </div>
</div>

But no it shows two if I click this first one then close the modal and click the second one it shows both rather than just the one that's been clicked.

davorminchorov's avatar

From the code I read in your previous posts, you want to add multiple numbers in 1 input separated by commas, correct?

If that's correct, why are you appending multiple input fields for every button click? Shouldn't you add the value to the already created input field?

theUnforgiven's avatar

No not by separated commas now, that was going to happen, but now just click on a mobile number and it pre-populates the 'to' field with the number you've clicked on.

davorminchorov's avatar

Ok then, you don't need to create new inputs every time you click on a button. Go back to selecting the input by ID and just set the value to it.

mstnorris's avatar

I'm just messing. I'm a little lost now though :(

1 like
davorminchorov's avatar
Level 53

Yeah but I was thinking more like:

$('.mobile').click(function(){
            var number =  $(this).data('mobile');
            $("#toField").val(number);
});
1 like
theUnforgiven's avatar

Then in my modal the input would be:

<input type="text" name="to" class="form-control" id="toField" disabled>

Right, just clarity on this so I'm clear on whats happening?

davorminchorov's avatar

You select every button with the class of mobile and when you click the selected button, you pick up the number from the data-mobile attribute and you add that to the input value in your modal form with the ID of toField.

1 like
mstnorris's avatar

Yes as you only have one toField and multiple buttons.

1 like
bashy's avatar

You always get there in the end :P good job lads!

1 like
Previous

Please or to participate in this conversation.