JQuery enabling a textbox with a button event query - javascript

I have a tiny issue if anybody can help... I am trying to implement a form, so when the page loads the textbox is disabled. If the user wishes to amend information they first have to press a button which will enable the text box.
<input id="text" type="text" disabled="disabled">
<br />
<button>Enable</button
So I have a basic textbox which is disabled. Then an event that should enable the textbox...
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("#text").attr("disabled","false");
});
});
</script>
I can get this working when the textbox is not initially disabled and I want to disable it, though I can not get it working the other way round - when it is disabled and I want to enable it.
Can anyone point me in the right direction?

Hi i have created a jsfiddle for you see the working example...
you should use removeAttr instead of attr
code:-
$(document).ready(function(){
$("button").click(function(){
$("#text").removeAttr("disabled");
});
});
link:-http://jsfiddle.net/L7S37/15/

You are giving boolean value as String
Use this
$("#text").attr("disabled",false);
instead of
$("#text").attr("disabled","false");
DEMO

Or you can use this, Even the last answer by Mr Soni is correct.
$(document).ready(function(){
$("button").click(function(){
$("#text").prop('disabled', false);
});
});

Related

How to Automatically Click Button on a Webpage

I'm completely new to scripting and i'm having an awful time trying to create a script so that it automatically clicks an "Add to Cart" button on the webpage once I visit it. An example on the website is the item "https://www.therealreal.com/products/women/outerwear/jackets/chanel-jacket-931420". Ive tried using the following script
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js"
type="text/javascript">/script>
<script type="text/javascript">
$(function(){
setTimeout(function() {
$("add-to-cart-button").trigger('click');
},1);
});
</script>
But there was no luck. If someone could help me create a script that would automatically click the add to cart button once I visit any item on the website I would be extremely grateful and would even be willing to pay for this script. Oh also im on a mac if it makes a difference.
i think if you follow the idea that i will show, you will catch the solution
consider that you have two buttons one called "Call set time out" and another is your desired button "Add to cart"
and on "Call set time out" click event you want to call "Add to Cart" button event so you should do the following
the html will be
<input type="button" id = "Call-set-time-out" value= "Call set time out" />
<input type="button" id = "add-to-cart-button" value= "Add to cart"/>
and the jquery script will be
$( "#Call-set-time-out" ).click(function() {
$("#add-to-cart-button").trigger('click');
});
$( "#add-to-cart-button" ).click(function() {
alert( "add-to-cart-button .click() event called." );
});
i hope this will help you and good luck for you journey in Jquery world
Try this:
If add-to-cart-button is ID:
$("#add-to-cart-button").trigger('click');
If add-to-cart-button is Class:
$(".add-to-cart-button").trigger('click');
I think $("#add-to-cart-button").click(); will work for you based on if add-to-cart-button is id of that button.
Hi try the below code this should help
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".add-to-cart-button").trigger('click');
});
</script>
Happy Coding :)

Radio button not working in wordpress 7

<script type="text/javascript">
$(function(){
$('input.check1').click(function(){
$('#show1').show();$('#show2').hide();
});
$('input.check2').click(function(){
$('#show2').show();$('#show1').hide();
});
});
</script>
This is the Javascript code that I'm trying to use in one of my Wordpress 7.1 pages to show and hide a 'div' part that contains a table, using radio buttons. Below is code for the radio button:
<input type="radio" name="chec" class="check1" checked="checked">Option 1
<input type="radio" name="chec" class="check2">Option 2
But it is not working. I don't know what to do, maybe the Javascript is not triggering?
Try this
<script type="text/javascript">
jQuery(function(){
$('.check1').click(function(){
$('#show1').show();
$('#show2').hide();
});
$('.check2').click(function(){
$('#show2').show();
$('#show1').hide();
});
});
</script>
Also make sure you have the script source in your header.
replace all '$' sign by 'jQuery'
As wordpress by default uses jQuery=noconflict

Javascript onclick not working on radio button

I have a problem with javascript. I have downloaded a rating star plugin , this one to be exact: http://www.fyneworks.com/jquery/star-rating/#tab-Testing
I have multiple things to rate on one page, so i thought i could use an onclick to send it to a function, that sends it to my database with ajax. The problem is, when a rating star is clicked nothing happens, ive tried it on a regular submit button and the function gets executed.
Here is the code :
<script type="text/javascript">
function postform(){
alert('Thing is clicked');
};
</script>
And the star is actually a radio button:
<input name="adv1" type="radio" class="star {split:4}" value="0.50" onclick="postform()"/>
I can't see what is wrong with the code, because when i test it on a regular button like this :
<input type="submit" value="testbutton" onclick="postform()"/>
It gives me the alert Thing is Clicked.
Somehow the star doesn't like the onclick stuff..
Ive tested it in IE, Chrome and FF, nothing ever happens
could someone help me out here?
Thanks alot!
Edit:
As requested by Lukas , i have this in my head :
<script type='text/javascript' src='jquery.min.js'></script>
<script src='jquery.MetaData.js' type="text/javascript"></script>
<script src='jquery.rating.js' type="text/javascript"></script>
That library is handling the onclick event of the radio button for you, so you cannot handle it by adding an attribute onclick to the input element.
According to their documentation you need to put some code like this in a script:
$('.auto-submit-star').rating({
callback: function(value, link){
alert(value);
}
});
Then add the class auto-submit-star to the class list of your radio button:
<input name="adv1" type="radio" class="auto-submit-star {split:4}" value="0.50" onclick="postform()"/>

Popup for form fields in zend application

I have created a Zend based php application.
I am looking for a simple way to create a popup or hoover-over help that I can use to to provide user help for the fields that the user should enter.
I guess I need javascript, and for the Zend form elements some decorator. But I have not been able to figure out how it should work. Maybe I need some CSS as well?
Does anyone have an example.
kind regards,
Vincent
you may use the jquery plugin for validation, which would prevent the form from submitting until first level checks have been passed. You find further information on the documentation page of jquery. But never trust those checks. You should always validate user input in the backend
http://docs.jquery.com/Plugins/Validation
or you use this, based on jquery
<!DOCTYPE html>
<html>
<head>
<title>Form Info</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(':input.form-input').live('focus', function(){ //get input field
$(this)
.closest("div") //get up to div element
.find(".form-info") //and search for corresponding form-info class to that input field
.show(); //show it
}).live('blur', function(){
//once you leave the input field you might to some things
//...
//or just remove the element
$(this)
.closest("div") //get up to div element
.find(".form-info") //and search for corresponding form-info class to that input field
.hide(); //hide it
});
});
</script>
</head>
<body>
<div>
<input type="text" name="blub" value="" class="form-input" />
<span class="form-info" style="display:none;">my info to the customer</span>
</div>
</body>
</html>
I think you are looking for a tool tip for your controls.
Check this out jQuery Tooltip Plugin Demo
or this jQuery tools: tool tip

Can't bind JQuery Datepicker with asp:TextBox in sharepoint

I have the next trouble.
I am creating the web part in sharepoint. I need a Jquery datepicker.
When i try to bind it with the html textbox it works.
But when i try to bind it with the Asp:textbox it doesn't work.
Does anyone have any ideas?
Thanks. I will appreciate any help.
<script type="text/javascript">
$(document).ready(function() {
$('#tbDateOfPurchase').datepicker();
});
</script>
<asp:TextBox ID="tbDateOfPurchase" runat="server"></asp:TextBox> //doesn't work
<input id="tbDateOfPurchase" type="text" /> //works
This should work:
<script type="text/javascript">
$(document).ready(function() {
$('input[id$=_tbDateOfPurchase]').datepicker();
});
</script>
Like #redsquare noted it is the server side ID of the Textbox transforming into something else altogether on the client that is causing this.
The above code selects all the input elements that has a client id ending with _tbDateOfPurchase using Attribute Ends With Selector [name$=value]
You need to change the id in your jquery selector as the id at design time is not the rendered to client id. Check your html and see what the rendered id is.

Categories

Resources