This becomes so hard to follow, can you please explain what you are trying to do?
@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>
Have you checked the source code? Does it show anything in the data-mobile attribute?
Yes if I do an alert(number) from this var number = $(this).data('mobile'); it does show the number.
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.
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?
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.
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.
Does that apply same for the button?
http://cl.ly/2O0Q1C103Z0S adding back to ID's doesn't quite work
@bashy you'll be pleased to know we've hit 40! ;)
@mstnorris don't give @bashy ammo! lol
I'm just messing. I'm a little lost now though :(
Yeah but I was thinking more like:
$('.mobile').click(function(){
var number = $(this).data('mobile');
$("#toField").val(number);
});
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?
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.
Yes as you only have one toField and multiple buttons.
We got there in the end, special thanks to @Ruffles @mstnorris and of course @bashy
You always get there in the end :P good job lads!
Please or to participate in this conversation.