PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 13, 2022

[FIXED] How To Fill-Up a particular field of HTML form Based On The Button Clicked

 July 13, 2022     css, html, javascript, static-site, web-deployment     No comments   

Issue

I am making a Static Website with 5 kind of different home aomation service.

These are having different prices.

Whenever they click on "book now" button, A Booking form pops up.

Now, I want to fill up the "service required" field in the form automatically.

For Example if someone's clicking the book now button for "Full Home Automation Package" the "sevice required" will automatically be filled with that name.

How can i do so using html and JavaScript


Solution

You just need to give your button a function where you get your

text content and paste it to your Input, like this:

function MyFunction(){
	var value = document.getElementById("Test").textContent; 
  document.getElementById("test2").value=value;
}
<p id="Test"> Is this what you want ? </p>
<button type="button" onclick="MyFunction()">Click</button><br><br>
<input type = "text" id="test2" name "teste2">



Answered By - Hugo André
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing