1

I want to record the minimum and maximum price of the shares of different companies daily. I am trying to use this tag

<input type="number" name="number" placeholder="minprice">

<input type="number" name="number" placeholder="maxprice">

But I want in a single input need to enter both min and max prices of the share on the particular date.

What need to be included or changed?

4
  • Add min and/or max to your input: <input type="number" name="number" min="1" max="5"> Commented Feb 4, 2020 at 9:27
  • What I can understand from your statement is that you want only 1 input field to log some value. So, do you want to first enter the in prices and then max price? If there's only 1 input field then it has to be in some sequence. Commented Feb 4, 2020 at 9:29
  • @AkashAgrawal Exactly. I want to input min price first and followed by the maximum price in the same input field both values separated by some '-' or 'to'. Commented Feb 4, 2020 at 10:10
  • @GirishKallihal, check my solution below. Commented Feb 4, 2020 at 11:15

4 Answers 4

1

You can use min and max.

<form>
<input type="number" name="number" placeholder="minprice" min="5" />
<input type="number" name="number" placeholder="maxprice" max="40" />
<input type="submit" name="Send" /> 
</form>

Sign up to request clarification or add additional context in comments.

Comments

0

You could use HTML min Attribute, your tags should look like this

<input type="number" name="number" placeholder="minprice" min="1" >

<input type="number" name="number" placeholder="maxprice" max="5">

read docs here min and max

Comments

0

You can't have 2 values in one input of type "number". You can put both values in input of type "text" and restrict with javascript on keydown or keyup which symbols can be entered in that input.

I would suggest you keep it on the UI in 2 different inputs so there is less space for user mistakes. And then behind the scenes take both of the values and combine them however you want or need.

4 Comments

Okay. But want to record a) Yesterday's min and max price b) Today's min and max price and want to compare those two values.
Do you want to compare min and max price of the same day? Or today's min price to yesterday's min price and the same with max price?
Do you record separately min and max price into your database?
Yes I am recording the values in the database.
0

You can read the first value minPrice from the input field and clear the value to accept second value maxPrice. Using a counter you'll know which is what.

NOTE: This will work only for first 2 clicks. You can tweak the function as per your requirements.

var btn = document.getElementById("save-btn");
var minPrice, maxPrice;
var count = 0;
btn.onclick = function() {
  var price = document.getElementById("share-price");
  count += 1;
  if (count == 1) {
    minPrice = price.value;
    price.value = '';
    console.log('minPrice', minPrice)
  } else if (count == 2) {
    maxPrice = price.value;
    price.value = '';
    price.setAttribute("disabled", true);
    btn.setAttribute("disabled", true);
    console.log('maxPrice', maxPrice)
  }
}
<input type="number" placeholder="Enter price" id="share-price" />
<button id="save-btn">Save</button>

Comments

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.