Using of Onchage function to get Value in Js

Let’s create a simple example of a blog where we use the onchange event to get the value of an input field and display it.

Step 1:- Create a page

<div class="col-md-12">
<select name="project_name" id="project_name" class="w-100 p-2">
 <option value="" class="form-controll text-dark" disabled
 selected>Select Project</option>
@foreach (App\Http\Controllers\Api\ProjectApiController::getvalueall($slug_id) as $project)
<option data-project-id="{{ $project['id'] }}"
value="{{ $project['project_name'] }}">
{{ $project['project_name'] }}
</option>
@endforeach
 </select>
<input type="hidden" id="selectedProjectId" name="selectedProjectId">
</div>

Step 2:- Create a script

 document.getElementById('project_name').addEventListener('change', function() {
                var selectedOption = this.options[this.selectedIndex];
                var selectedProjectId = selectedOption.getAttribute('data-project-id');

                console.log('selectedProjectId me hai:'+selectedProjectId);
                $('#selectedProjectId').val(selectedProjectId);

            });

Result:-

Related Posts

Strategic DevOps Career Growth and High Salary Skills

Introduction The digital landscape is shifting rapidly. As companies across the globe transition to cloud-native infrastructures, the demand for professionals who can bridge the gap between development…

Read More

Top DevOps Certifications: Dominate Kubernetes, Cloud, And Automation

Introduction The cloud infrastructure world is moving faster than ever, and the demand for production-ready engineering talent is breaking records. Teams everywhere are desperately trying to bridge…

Read More

Streamlining Distributed Pipelines with DataOps Multi-Cloud Data Management

Introduction Modern business operations generate massive amounts of information every single second. To store, process, and analyze this information, organizations no longer rely on a single data…

Read More

Ultimate DataOps Automation Tools Guide: Build and Orchestrate Scalable Pipelines

Introduction Modern enterprises run on data, yet managing the underlying infrastructure remains a massive operational challenge. Historically, data workflows were handled manually. Data engineers wrote custom scripts,…

Read More

Accelerate Your Pipeline: Implementing Real-Time DataOps

Introduction Real-time DataOps is a critical evolution in how modern organizations manage the constant flow of information. By integrating automation, continuous testing, and real-time processing, businesses can…

Read More

Calculate Your Canada PR Points: The Complete Guide to Boosting Your CRS Score

Introduction Canada uses an objective, merit-based points system to select the most qualified candidates from around the world. To assess your chances, you need to use a…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x