0

I have an input field in the blade.

<div id="id1">
<input id ="text1"  data-readOnly="true" data-max=300 value= 34/>
</div>

Script:

 channel.bind('App\\Events\\ValueChange', function(data){
      target = data.id;
      value = data.value;
});

I need to bind the value = data.value; from the event to the attribute value in the Input field in the blade file.

How could I do this? Could someone please help.

Thanks.

6
  • I'm not quite sure what you're doing there. Could you add some more details to your question? Commented May 21, 2021 at 12:21
  • What’s the problem? If you’re listening to broadcast events using Echo then you can receive the new value in the payload and update your input like you’ve demonstrated. Commented May 21, 2021 at 12:28
  • I want to know, how to bind the values triggered from the event to the input field value attribute, For ex, I used static value 34, but the value should be returned from the Event. How to bind the value? Commented May 21, 2021 at 12:32
  • As has already been answered, get the element, and alter it's value with getElementById Commented May 21, 2021 at 14:04
  • @JustCarty, In the blade fiel, do I need to use the below to bind the value `<input value = "{{ value }}"/> ? Commented May 21, 2021 at 14:22

1 Answer 1

1

This can be done by

channel.bind('App\\Events\\ValueChange', function(data) {
    target = data.id;
    value = data.value;

    document.getElementById('text1').value = value;
});
Sign up to request clarification or add additional context in comments.

5 Comments

how to bind that value from the script to the view in the input field?
@KovidaK I'm not sure how this doesn't answer the question. When you say "bind" I imagine you want the value to update. That will happen when your event updates.
@Mua Rachmaan, after adding document.getElementById('text1').value = value;, I could not see any changes in the value atrribute in the input field.
@JustCarty, If` <input value = 20>` and when I trigger the value through event document.getElementById('text1').value = value; , then 20 should be replaced by the value triggered by the Event, Correct? . If I pass event(eventname(45)) in the tinker. 20 should be replaced by 45 in the browser. But still Its 20.
@KovidaK then you should probably ask another question, I think your call back is not being called. This has to do with wither pusher or laravel echo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.