making the element of an array containing double quotes [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 days ago.
Improve this question
How do you make this the whole lot,
<input type="text"/> <input type="range" min="-50" max="50" step="10" value={val} onChange={e => setVal(e.target.value)}/> {val}
<br></br>
the element of an array? The problem is it contains double quotes but the element is surrounded by double quotes.
Any help would be greatly appreciated.
Thanks

You can use single quotes for an array.
var a = ['<input type="text"/> <input type="range" min="-50" max="50" step="10" value={val} onChange={e => setVal(e.target.value)}/>{val}<br></br>']

Related

How can I make first number of phone number cannot be zero? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
My html like this :
<input type="number" />
I had validation number, so user only input number. I want the first digit to be non-zero
How can I do it?
You can use text input with a pattern attribute:
<form action="/action_page.php">
Phone Number: <input type="text" name="phone_number" pattern="[1-9][0-9]+" title="Phone number without a leading zero" required="required">
<input type="submit">
</form>
and to use with number you can use this:
<input type="number" oninput="this.value = this.value.replace(/^0/g, '');" >

Adding more balance via a html input to a javascript variable? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Photo of the website
I have a school project and I need to make a website where I can add more balance to my account. But I can't figure it out.
I would like to make an HTML number input and then that input needs to add up with my existing balance. But I can't make it work
This is the code I have:
<fieldset>
<legend>Opwaarderen</legend>
<input type="number" id="opwaarderen">
<input type="submit" onclick="opwaarderen()">
</fieldset
But how can I make the Javascript function? So that the input will add up to my already existing balance.
This will help
var currentCredit=0;
$("#a").click(()=>
{
alert(currentCredit+=Number($("#opwaarderen").val()));
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<fieldset>
<legend>Opwaarderen</legend>
<input type="number" id="opwaarderen">
<input type="submit" id="a">
</fieldset>

How to remove double quote use onkeyup attr inline? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I tried
<input type="text" name="first_name"
onkeyup="value=value.replace(/[\-\'\.\,\/\`\:\~\!\#\#\$\%\^\&\*\(\)\_\+\=\;\|\{\}\[\]\<\>\?]/g,'')">
it works for almost all special chars, but when I add a double-quote filter like
<input type="text" name="first_name" in first
onkeyup="value=value.replace(/[\"\-\'\.\,\/\`\:\~\!\#\#\$\%\^\&\*\(\)\_\+\=\;\|\{\}\[\]\<\>\?]/g,'')">
it seems to not allow to do like that. I want to custom remove the mark I want.
You can put your code in an external function instead of placing it inline. It's just that the " interferes with the html attributes' " and break the code.
document.querySelector(".no-special-chars").addEventListener("keyup", function(){
this.value = this.value.replace(/[\"\-\'\.\,\/\`\:\~\!\#\#\$\%\^\&\*\(\)\_\+\=\;\|\{\}\[\]\<\>\?]/g,'');
});//keyup()
<input class="no-special-chars" type="text" name="first_name" />

Dynamic price amount from input [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a simple form including number input. Now, I want to dynamically add the total price, whenever someone changes the number. Could someone direct me on what to do please? I want it do be done without pressing submit.
<form>
<p class='ticket'>VIP ticket ($200):</p><input type="number" name="vip" min="0" max="20">
</form>
<p>Total price: </p>
Changing your html a little:
<p class='ticket'>VIP ticket ($200):</p><input type="number" name="vip" id="vip" min="0" max="20" />
<p>Total price: $<span id="total">0</span></p>
I've used a <span id="total"></span> to change the total value easily, and added id="vip" to your number input.
var ticketValue = 200;
$("#vip").on("change", function() {
$("#total").html($(this).val() * ticketValue);
});
Fiddle

auto update form with javascript [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want the text i type in
<input type="text" name="text1">
will automatically be updated in
<input type="text" name="text2">
by using JavaScript.
Anyone know how to solve it?
Thanks in advance
You can use the onkeyup event and populate the second <input> with the text of the first one, like this:
var inp1 = document.getElementsByName('text1')[0],
inp2 = document.getElementsByName('text2')[0];
inp1.addEventListener('keyup', function(e) {
inp2.value = this.value;
});
<p>Input 1: <input type="text" name="text1" placeholder="write something here..."></p>
<p>Input 2: <input type="text" name="text2" placeholder="ant it will show up here..."></p>
Test it using the "Run code snippet" button.

Categories

Resources