Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

javascript - how to make these two components appear on the same line? (textbox label and the textbox)

this is my html file

 <div id="radioHeader">
    <div id="radioHeader" onclick="radioClicked()">

      <div class="radio form-check form-check-inline component"> Mode of Transaction<span
          style="color:red;">*</span>
        <div class="radiogq">
          <input type="radio" name="mode" value="cheque" onclick="" checked> Cheque
          <input type="radio" name="mode" value="bank"> Bank Transaction
        </div>
      </div>
      <div>
        <p id="idc"></p><input class="textb" type="text" id="fname" class="col-form-label input" placeholder="Registration Id"
          name="fname" size="100">

      </div>
    </div>
  </div>

this is my js file from where I am adding the value in the textbox, and I want them to be in the same line. this textbox label will chance as per the change in the radio button

  function radioClicked() {
  let shapeChoice = document.querySelector('input[name="mode"]:checked').value;

  switch (shapeChoice) {
    case 'cheque':
      document.getElementById("idc").innerHTML = "Enter your Cheque Id"
      break;

    case 'bank':
      document.getElementById("idc").innerHTML = "Enter your Transaction Id"
      break;



    default:
      doucment.getElementById("idc").innerHTML = "Default"
  }
};

radioClicked();
question from:https://stackoverflow.com/questions/65831654/how-to-make-these-two-components-appear-on-the-same-line-textbox-label-and-the

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use CSS, one of the ways is float:left

function radioClicked() {
  let shapeChoice = document.querySelector('input[name="mode"]:checked').value;

  switch (shapeChoice) {
    case 'cheque':
      document.getElementById("idc").innerHTML = "Enter your Cheque Id"
      break;

    case 'bank':
      document.getElementById("idc").innerHTML = "Enter your Transaction Id"
      break;



    default:
      doucment.getElementById("idc").innerHTML = "Default"
  }
};

radioClicked();
.cs1 {
    float:left;
}
<div id="radioHeader">


        <div class="radio form-check form-check-inline component" "> Mode of Transaction<span
            style="color:red;">*</span></div>



    <div id="radioHeader" onclick="radioClicked()">

        <div class="cs1 radiogq">
            <input type="radio" name="mode" value="cheque" onclick="" checked> Cheque
            <input type="radio" name="mode" value="bank"> Bank Transaction
        </div>
        
        
        
    </div>

    <div class='cs1'> &nbsp;&nbsp;</div>

            <div class='cs1' style="position:relative;top:2px;" id=idc></div>

    <div class='cs1'> &nbsp;&nbsp;</div>            
            
        <div class='cs1'>

            <input class="textb" type="text" id="fname" class="col-form-label input" placeholder="Registration Id"
                name="fname" style="width:200px;max-width:100%:">

        </div>
  
    </div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...