Setting textbox to readonly not working in Javascript [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have tried the following codes to set a textbox property to readonly but none of them is working. Can anyone tell me how to do it?
document.getElementById("phone_numbers").disabled=true;
document.getElementById("phone_numbers").readonly=true;
document.getElementById("phone_numbers").readOnly=true;
document.getElementById("phone_numbers").readOnly=readOnly;
document.getElementById("phone_numbers").readOnly=readonly;
document.getElementById("phone_numbers").readonly=readonly;
document.getElementById("phone_numbers").readonly=readOnly;
document.getElementById("phone_numbers").setAttribute('readonly', 'readonly');
document.getElementById("phone_numbers").setAttribute("readonly", "true");
EDIT
While I was editing my question to write more detail I realized what the problem was. I made a silly mistake. This was my original HTML code.
<input name="phone_numbers">
And I changed it to
<input id="phone_numbers">
And it worked!
By the way following are the functions that are actually working.
document.getElementById("phone_numbers").disabled=true;
document.getElementById("phone_numbers").readOnly=true;
document.getElementById("phone_numbers").setAttribute('readonly', 'readonly');
document.getElementById("phone_numbers").setAttribute("readonly", "true");

Your third line worked for me: JSFiddle
HTML
<input id="phone_numbers" type="textbox"></input>
Javascript
document.getElementById("phone_numbers").readOnly=true;

If the textbox is server side, then use document.getElementById("<%= phone_numbers.ClientId %>") to access it.

Related

Jquery .click() causes code to break [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Adding this line of code $("#locate-me-button").click(loadLocation()); breaks my entire JavaScript code file even if I don't click the #locate-me-button element. When this line is commented out the entire file works perfectly again. Why would that be?
You are invoking the function as passing its return value to event handler, just pass the function reference to .click()
$("#locate-me-button").click(loadLocation);
//^ () is removed
The another way (at least for case that you have parameter):
$("#locate-me-button").click(function(){
loadLocation();
});

I want to remove this line from my html code [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
This is the image of my html code.
I want to get rid of the line boxed in red.Please help me.That line does not show in the actual code, but when the page is opened on a browser i.e in (google chrome) and selected "view source code" it shows the line.I want to get rid of it.Please help me, reply me a.s.a.p..Thank you.
Definitely adware. Check out: http://www.malwarekillers.com/tag/remove-track-breaking-news/
As #Tanuel said, this is either from malware or a browser extension since it seems that you didn't put it in the source code.
Go to Dev Tools in Chrome (Ctrl+Shift+i) and look at Network and check what scripts are being loaded on the page.
Also, take your time to explore the Elements tab and to find out how that line is being added to the code.
This is a bad post but I can feel the frustration in your question and the answer is probably just this:
<script>
$(document).on('pageload',function()
{
document.getElementsByTagName('script')[0]='';
});
</script>
Add it to the bottom of your page.

Angular JS ng-click content not showing on live site [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have products displayed using this code:
<a ng-click="setSelection(product);" class="btn btn-sm">Full details</a>
http://plnkr.co/edit/zhsY6TAjONewyInGiwUC?p=preview
Everything works fine locally on various browsers, but now I have uploaded the content to the website, nothing is displaying when I click on 'full details'.
http://gammafightwear.co.uk/gamma-website/products-long-sleeved.html
Can anyone shed any light on why this might be?
Many thanks
I get a 404 when I click on that button.
GET http://gammafightwear.co.uk/gamma-website/includes/products/ESSCOT.html 404 (Not Found)

Why jquery event doesn't handle? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have wrote following code example:
html:
<input type="checkbox" name="terminal" class="all" data-terminal-id="9800" >
javascript:
function checkRightBarVisibility(){
if(this.checked){
alert('checked');
}
}
$('input[name=terminal]').change(checkRightBarVisibility);
http://jsfiddle.net/o9ovnkxv/6/
This code works as expected.
But in my real code I have same javascipt code but I don't see alert.
I have not ideas how can it possible.
debug information:
bigger picture(http://i.stack.imgur.com/ADXB5.jpg)
Please help me to find the mistake.
P.S.
full code is very huge thus I didn't post it.
update:
I tried following in debug:
I wrote following row:
$('input[name=terminal]').change(checkRightBarVisibility);
After it I have seen alert 1 time.
But only one time.
If your inputs are being added dynamically then you should use delegation:
$('body').on("change", 'input[name=terminal]', checkRightBarVisibility);
(In jQuery, how to attach events to dynamic html elements?)

IE8 JQuery error [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm working on this website: link
Everything works in the modern browsers, but in IE8 if I click on a plus sign in the left menu, I get an error.
The error is in the 52. line of this js: js
content = $(link).parent();
Error is
Object doesn't support property or method
From seeing your script,
togglemenu($(this));
function togglemenu(link){
content = $(link).parent();
...
...
}
you can directly have
content = link.parent();
Well content is not defined anywhere that I can see, maybe that is the problem?
Try this-:
$(link).closest('your closest parent')
Documentation=http://api.jquery.com/closest/

Categories

Resources