This question already has answers here:
jQuery selector to get form by name
(4 answers)
Closed 8 years ago.
I have multiple forms on a page. How do I find a form by its name? I think in pure javascript it is something like document.forms['FormName'] .
I want to do a form.submit. But I want to be able to select a form by its name.
You can add an attribute selector to get the form you want:
$('form[name="foo"]')...
No jQuery required -- just use the built-in JavaScript submit() method:
document.forms['FormName'].submit();
Give your form an ID or class attribute. In the case of an ID:
$("#formName").function()
Your HTML:
<form id="formName">
Where function is what you plan on doing...
Related
This question already has answers here:
Selecting multiple classes with jQuery
(4 answers)
Closed 3 years ago.
I'm a beginner and I'm wondering if there is a way to remove multiple attributes once without coding for each one.
For an example, please look at my code sample below.
$(".select-us").attr("disabled",true);
$(".select-as").attr("disabled",true);
$(".select-eu").attr("disabled",true);
$(".select-oc").attr("disabled",true);
I just want to know if there is any simpler way to do this. Thanks for your time.
$(".select-us, .select-as, .select-eu, .select-oc").attr("disabled", true);
Please wrap your multiple form elements in fieldset and disable/ enable this only
<fieldset id='fset' disabled={true}>
...
can disable and enable with jquery like this
$("#fset").attr('disabled', true)
Add a new class to every element like "select-all" and do:
$(".select-all").attr("disabled",true);
This question already has answers here:
How to select JSF components using jQuery?
(4 answers)
Closed 5 years ago.
In my JSF application,one of the html element having the below ID.
FrmOffer:rptOffer:0:j_idt325:0:j_idt355:0:j_idt356:0:j_idt560:0:j_idt632
When I try to select the element using below Jquery lines,
Option 1:
$('#FrmOffer:rptOffer:0:j_idt325:0:j_idt355:0:j_idt356:0:j_idt560:0:j_idt632');
This returns :
Uncaught Error: Syntax error, unrecognised expression: unsupported pseudo: rptOffer
Option 2:
$('#FrmOffer\\:rptOffer\\:0\\:j_idt325\\:0\\:j_idt355\\:0\\:j_idt356\\:0\\:j_idt560:0\\:j_idt632');
This returns:
[]
Can anyone advice how to select the element ?
That way you gonna suffer.
In jsf you can reffer to elements concatenating their parent element's name, if all the elements have an Id:
<h:form id="formId">
<h:inputText id="emailAddresses" value="#{emailAddresses.emailAddressesStr}"/>
var input = document.getElementById('formId:emailAddress');
Maybe that answered question could help you How can I know the id of a JSF component so I can use in Javascript
We can use the native javascript selector instead of jquery.
Below is my code:
document.getElementById('FrmOffer:rptOffer:0:j_idt325:0:j_idt355:0:j_idt356:0:j_idt560:0:j_idt632');
This question already has answers here:
jQuery : select all element with custom attribute [duplicate]
(2 answers)
Closed 6 years ago.
Is there a way to grab a whole element by one of its data attributes via javascript or jQuery? Say i have a link somewhere on a website like this
Google
Since the link above doesn't have any id or class i cannot grab it by that. I need to get it by its data-source attribute. So say i could somehow with jQuery get the value of a attribute with the name of data-source. How would i do that ?
$('[data-source="google"]')
This will select all elements which data-source attribute equals to google.
See Attribute Equals Selector [name=”value”].
This question already has answers here:
How can I get the elements without a particular attribute by jQuery
(7 answers)
Closed 9 years ago.
I'm trying to use jquery to grab all select elements which do not have the "multiple" attribute set. I tried with the :not() but I can't get it quite right.
$(document).ready(function() {
$('select:not(multiple)').select2();
});
You forgot the attribute selector. What you're looking for there is "a <select> that is not a <multiple>"
$("select:not([multiple])").select2();
$('select:not([multiple])').select2();
or
$('select').not('[multiple]').select2();
This question already has answers here:
Getting Textarea Value with jQuery
(5 answers)
Closed 9 years ago.
I have a textarea in which I am populating a database record. I want to access the same value in textarea in jquery.
<textarea id="contact_address1"><%= #contact[:address1] %></textarea>
How do I do it? Pleasse help!
What you are looking for is jQuery's val() function:
$( "textarea#contact_address1").val();
Take a look: http://api.jquery.com/val/
Try
$("#contant_address1").text();
and let be sure that the id of your textarea should be "contant_address1".