I am trying to re-enable a text field that gets automatically filled in and disabled on the website we use for ticketing. It is currently possible to inspect element, and enable manually to field to enter anything you want. I'd like to remove that step. I am trying to make a (very) simple chrome extension that will detect when the field has been disabled and switch it back on, but I'm having no luck.
I've tried several iterations, with no success. Here's what I've got at the
moment.
var subject = document.getElementById('title_fs');
subject.onchange = function() {fix()}
function fix(){
subject.setAttribute("enabled", true)}
I also tried
var subject = document.getElementById('title_fs');
subject.addEventListener("change", {subject.setAttribute("disabled", false)});
The most success I've had so far was accidentally disabling the field as soon as the page loaded. Any suggestions?
Simply remove the attribute
document.getElementById('title_fs').removeAttribute('disabled');
document.getElementById('removeDisabled').addEventListener('click', function() {
document.getElementById('title_fs').removeAttribute('disabled');
});
<textarea disabled="true" id="title_fs">Foobar</textarea>
<button id="removeDisabled">Remove Disabled</button>
element.disabled = true/false
function func() {
var elem = document.getElementById('someId');
elem.disabled = !elem.disabled;
};
<input type="text" id="someId" />
<button onclick="func();">click</button>
Related
I use the following button.
<input type="button" id="attractionsSection" value="Warsztaty" onclick="location.href='#Url.Action("AddAttractions","ReservationDetails")'" disabled="disabled" />
In js script i check wheather some condition is true and then I set property disabled of button.
if(Model.stagesConfirmation[4]==true)
{
<script>
$(function () {
console.log('Test1');
document.getElementById('attractionsSection').disabled = 'true';
console.log(document.getElementById('attractionsSection'));
console.log('Test2');
});
</script>
}
I use console log to test wheather this condition is passed and that is OK. I set disabled and button still remains active. This console.log
console.log(document.getElementById('attractionsSection'));
shows me the following thing
<input type="button" id="attractionsSection" value="Warsztaty" onclick="location.href='#Url.Action("AddAttractions","ReservationDetails")'"/>
So it is not disabled. How to solve, what can be the problem?
See this answer. You need to use element.removeAttribute("disabled"); or element.disabled = false;
You don't say disabled=true you just say disabled. Check here for documentation on the disabled attribute.
You could say disabled="foobar" and it will still disable the button. To prove that, play around with this.
I need to create moving stripe(I don't know how to name it) on my website. Something like this:
|--#---------|
And the # can be moved by the user from one side to another and when the bar is clicked it sends the value but it can't be done with manual requests so the user chooses the value to send. I just need some tips how I can do this. I think it can be done by flash but I don't even know what should I internet search keywords should be used to find more info about it.
As Wainage suggested, an <input> with type range is perhaps a simple solution. See an example below.
document.addEventListener('DOMContentLoaded', function() {
var slider = document.getElementById('rangeValue');
var output = document.getElementById('valueOutput');
function updateOutput() {
output.innerHTML = slider.value;
}
//set the value initially
updateOutput();
//subscribe to any change/drag - not supported by IE
slider.addEventListener('input', updateOutput);
//use change event for updates when drag is ended
slider.addEventListener('change', updateOutput);
});
<input id="rangeValue" type="range" name="rangeValue" value="3" max="10" />
<div>Value: <span id="valueOutput"></span></div>
Say I visit a website which has the following code:
<input type="text" name="enter">
<input type="submit" name="button">
<a id="confirm">Confirm</a>
I need a script which I can run in the Chrome console to press the <a> element then type the text 'hello' into the input field and then click submit. I need this process to repeat every minute.
I have tried using this code.. but it doesn't do anything.
window.setInterval(function() {
document.querySelector("#confirm").click();
document.querySelector(".enter").value = "Hello";
document.querySelector(".button").click();
}, 1000);
If the inputs are placed in a form try this, in this case if you need to access by the name and not the class:
window.setInterval(function() {
var form = document.forms[0];
document.querySelector("#confirm").click();
form.querySelector('input[name=enter]').value ="Hello";
form.querySelector('input[name=button]').click();
}, 1000);
Otherwise your script above will work if the inputs have these correct class names
Instead try using trigger as:
$(document).ready(function() {
var event = JQuery.Event("click");
$('#confirm').click(function() {
$('.enter').value("Hello");
$('.button').trigger(event);
});
$('#confirm').trigger(event);
});
Now just put the code inside your window.setInterval() function.
Hi I want to simulate a user clicking on an input box.
script is:
function prepareToScan(){
$("fireRegAdd").focus();
$('fireRegAdd').keypress();
}
and HTML is
<h2>Add a visitor to today's fire register</h2>
<input type="button" onmousedown="prepareToScan()" value="Add Visitor">
<input id="fireRegAdd" name="fireRegAdd">
</div>
I have a barcode scanner which puts the code into the input box but only when it's been "clicked". I've tried .focus() but it needs two scans to get the scan to work. The on focus is not the same as actually clicking in the box. Does any one know how to do that?
thanks
So I've found that if I add in an alert it set it correctly :
function prepareToScan(){
alert("ready to scan");
$("fireRegAdd").focus();
$('fireRegAdd').keypress();
}
but I don't really want an alert box
I've added a demo of the code. When you click on the button I want there to be a blinking cursor in the input box.
function prepareToScan(){
$("#fireRegAdd").focus();
$('#fireRegAdd').click();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div>
<h2>Add a visitor to today's fire register</h2>
<input type="button" value ="Add Visitor" onmousedown="prepareToScan()"/>
<input id="fireRegAdd" name="fireRegAdd" value="" />
</div>
I've discovered that it's virtually impossible to focus on an input box so that the curso blinks. I tried everything including manipulating the cursor position and using a click event.
I did however solve my problem. Barcode scanners act like keyboards. So I wrote some code which detects keyboard input. It checks for incoming keys. If it receives more than 3 in 250 ms it assumes that it is coming from the scanner. Works a treat. It'd be easy to modify to adjust for different applications. Here's the javascript code I ended up with. To make it work you need a div with id="barcode" Hope someone finds it useful.
var chars = [];
var pressed = false;
window.addEvent( 'keydown', function( evt ){
//console.log(evt.key);
chars.push(evt.key);
setTimeout(function(){
if (chars.length >= 3) {
var barcode = chars.join("");
$("barcode").value= barcode;
}
chars = [];
pressed = false;
},250);
});
I have written some simple javascript to change the content of an iframe according to the input of a field. After hours of attempts, I have managed to get it working; however I didn't really understand why I should put the "return true" and "return false" at the end of my search function. Thank you in advance!
function search(){
var course=document.getElementById("field");
if(course.value!=""){
if(course.value!="Course code (e.g. COMP1004)"){
var target=document.getElementById("frame");
target.src=course.value + ".php";
return false;
}
}else{
return true;
}
}
<input id="field" name="field" type="text"></input>
<input id="searchButton" name="searchButton" type="button"value="Search"onclick="search()"></input>
You don't really need to, since you are calling the function without expecting any value. And even if you write onclick = return search() you have no default action to prevent, since your input has type="button"
When you trigger a javascript function using onclick (depending on the browser), the actual functionality of the click can be prevented by returning false. So if you click on a button and return true (or nothing) the actual click will be triggered and e.g. load a new page. If you return false, the original function of the button will not be called ...