I'm using smarty for work with html and faced one problems: I have table of different elements (few select and many input). I need to check the values of all elements in the table. With input no problem ($('input[type="text"]')), but how to check in one time select and input values.the problem is that the smart does not provide any additional options for {html_options}. May be there is some AND structure for jQuery selectors?
I see two possible routes here:
Extend your selector with add, e.g.
$('input[type="text"]').add('select').doSomething()
Use a common class for all input and select elements, e.g.
$('.my_input_class').doSomething()
Of course this assumes that you are using common properties/methods on your selection afterwards. For instance, you'd be able to call val() to retrieve the values.
If you want to add the same functionality to two selectors you can this approach..
$('input[type=text] , select').addClass('classname')
You can use a comma to add the same functionality to multiple selectors..
Related
I recently saw a html page, that i thought the id of several html tags was the same, then I realized the ids are unique but it raises the question that what could have happened if the page actually used several tags
As i have heard id attribute of every html tag(if it has one) must be unique,
now i wonder what happens if it is not the case??
what possible errors can it cause?
does different browsers show different reactions for this issue?
does javascript and jquery codes that use duplicated ids run on both tags or what?
Duplicate ids can have various different effects. Which you experience will depend on the method you use to try to access them (and possibly also from browser to browser).
You'll affect all of them
You'll affect the first one
You'll affect the last one
You'll get a collection instead of an element, try to treat it like an element and get an error
Duplicate ids are not allowed in HTML. Don't make trouble for yourself. Use classes for groups and ids for unique identifiers.
Change them as soon as possible, to save a lot of headache in the future. For elements with same property use classes
About your queries,
Now i wonder what happens if it is not the case??
Well, the HTML is not a valid one anymore. Now a days it doesn't hurt much but still not preferred.
What possible errors can it cause?
Errors are little bit hard to predict. But with jQuery you are going to get many.
Does different browsers show different reactions for this issue?
Not sure.
Does javascript and jquery codes that use duplicated ids run on both tags or what?
jQuery will give you trouble. Consider a case where you have two input fields with same ID.
and you try to select second one with out noticing. jQuery('yourID').val() and you'll be selecting the firs value instead. Like this there are a lot of possibilities.
As you said, HTML id, per specs, must be unique. If one where to put duplicated id, the js behavior relative to those ids will be unpredicatable, and could even change between 2 calls.
Any js call on one id (jquery or not) will point to one of the id but without guarentee that :
It will be the same every call
It will have the same order between 2 page refresh
It will have the same behavior beween 2 different browser
It will have the same behavior betwween 2 time the same browser
The problems that could emerge depend on how toghtly the js code is coupled to the underlying element DOM structure anw could mostly point to a undefined exception and stop the js execution.
I need to create a specific <option> list on a form, depending on which option is selected by the user on the previuos <select> list. In this case, as part of a school ERP, when user selects course the system should load on the next field only the subjects related to this course.
This can be done by ajax, using the 'change' method, posting on real-time course ID, and giving back as the result of the query, the list of related subjects wich is loaded on its <select> list.
Is making this by having a separate file instead of trying another options the best practice to solve this cases? I mean, if the best way to do this is by having an specific file for every list that must be dinamically generated, then I'll make it this way, but I feel that having a php file for every single dynamic list that should be generated on real-time maybe is not the most efficient way to do this (got many form fields that should behave this way).
One PHP file will do.
Use this tutorial to learn about URL parameters:
http://html.net/tutorials/php/lesson10.php
Combine with this tutorial on how to retrieve data from a database:
http://html.net/tutorials/php/lesson20.php
The idea here is, using AJAX, instead of fetching your list like this:
http://example.com/list/thing1.php, http://example.com/list/thing2.php
You use a single PHP file, like this:
http://example.com/list.php?foo=thing1, http://example.com/list.php?foo=thing2
So instead of having a php file for every single dynamic list you can have one file that loads and format the specific data you need dynamically.
I am looking best solution in PHP for a search form which has multiple fields and person can also choose operation on that field. Here is how it will work for example. Also allow me to set what operations are possible on field without hard-coding. There will be many fields on page i am explaining on few on them.
Scenario examples :
Lets field "age" there can be three scenario. age can be greater than
or equal to or less than given field. So on page for a field person
will be able to select operation type from drop-down
"equal,greater,lesser" and then specify value.
Similarly for subject it can have following scenarios. subject equals
selected, or in multiple selected subjects, or not in selected
subjects.
I don't wanna hard-code solution for each field, i want something that's more flexible with which i can add or remove fields later without changing major part of code.
Was able to resolve it with collaborated code between PHP and Javascript. Created array in PHP with name of field, then what type of operations it support and other optined needed.
Then in jQuery hide display and restrict field options based on options that i output from PHP array.
I am working on php and now trying to learning Zend, I am trying to collect the age (Year/month) using zend_form. So I want to put 2 text boxes in the same DD wrapper.
Can any one help me please.
Thank you
You could create a composite form element that comprises your two text fields. Then create custom decorator for that element to handle the aggregation. Then add the standard DtDd wrapper.
See this post by MWOP for an example: Creating composite elements
You can't place many input boxes in single element's decorator (with some exceptions like radioboxes or multicheckboxes). Instead that, you must to remove decorator Zend_Form_Decorator_DtDdWrapper from both elements and place them in new Zend_Form_DisplayGroup. Then You can set Zend_Form_Decorator_DtDdWrapper to that DisplayGroup
i would like to use multiple filter options for all columns with using select form object.
When a columns filter selected, other select object options may filled to this selection.
Clearly, i want to filter jqrid columns as same excel filter feature.
I use php for server side.
Thank your very much for your help and suggestions already now.
What you want to implement should be combination of the usage of Toolbar Searching (see this demo as an example and the usage of 'change' custom event handle as dataEvents inside of the searchoptions. Inside of your 'change' handle you can make an ajax request to the server and then rebuild <select> element of the second drop-down list.
You can find more examples used the same technique with editoptions. Both work based on the same idea. The technique is not simple, but it works. I recommend you to read this thread.