How to pass value between parent window and child window - javascript

I am using Jsp, Structs. From a parent window (e.g)parent.jsp, I invokes child.jsp, which has a list of checkbox values. I select more than one values, then put it in a arraylist and send back to parent.jsp and store it in a textarea.
Now If i want to select some more values from child.jsp. When i again invokes child.jsp, the checkboxes i already checked will be checked there and i dont want the empty unchecked boxes.
Could someone help me in this.......If u send some sample code means its very useful.
Thanks in advance.....
Aadhira.

As I understand, when you go to the child.jsp for the second time you need to preserve the checked checkbox values. The only solution i see for this is pass these checked box parameters to the child.jsp form.

Related

If 2 radiobuttons have the same value, open the page with the first one selected

Let's say because of database restrictions 2 radiobuttons have the same value ( I know that it's better without using this ). Is it possible accordingly to this picture:
to select the first of two the same values when opening the page? So in this example "Geen" has the same value as "Dagelijks". When the page opens it should be "Dagelijks" that is pre checked (this depends on the value with this client ID, could also be wekelijks or maandelijks prechecked). Does anyone know if this is possible? Thanks in advance!
Assuming you are using javascript, it is certainly possible. Target the first element, something like this should work:
$('input[value="Geen"]').filter(':visible:first').prop('checked', true);
It can be done by making those radio buttons as default or checked true.

Set List for the input field

I'm passing list from java action class to jsp file through the session variable and i need set that list to the hidden input field and get that list to the jquery function I used following method to do that
I use this code bock for set list to the input field
<c:if test="${not empty sessionScope.myList}">
<c:forEach items="${sessionScope.myList}" var="item" varStatus="itemLoop">
<input class="myClass" type='hidden' value='${item}'/>
</c:forEach>
</c:if>
jquery method
$(document).ready(function () {
$('input.myClass').each(function() {
// do some work
});
}
But problem is its working first time only, my list values are changed by ajax call, but after changing list size and value it's not set the value accordingly.
Fist time created input fields are also there when I set the value second time. I think my method is not the correct way to do this, if any one know the better way to do this please help me
Thank you..!
But problem is its working first time only, my list values are changed by ajax call, but after changing list size and value it's not set the value accordingly fist time created input fields are also there
You need to remove the created elements first:
$("input.myClass").remove();
Or if you know the container of your elements you can do:
var $parent_container = $("your-selector-for-the-container");
$parent_container.empty();
I think my method is not the correct way to do this if any one know the better way to do this please help me
I'm normally not a fan of global variables, but in your case a global variable might be better than keeping this info (your list items) in the DOM.

How to store input type checkbox into json object using either Javascript or jQuery?

I wanted to store all my clicked input accordions(<input type="checkbox">) into json object, I have tried it but it is storing/taking the last input accordion clicked event only, it is not storing/taking all the input clicked accordions that is whatever I click on any accordion(of <input type="checkbox">) that should store into json object using either Javascript or jQuery ?
I am not sure where I am doing wrong ? Please help me regarding this ? Thanks in advance. Sample fiddle.
Because you are doing submitButtonValue[name] = $(this).val(); and the name you are getting it from $(this).attr('name'); on click of checkbox which is same for all the checkboxes. So everytime it replaces the value since object will have only one name contained. I would suggest you to either use different names for each checkbox or find some other way to uniquely store your checkbox values.
A Demo here

Checkbox creation using clone() method of jquery

I my form I have duplicate checkbox like
<input type="checkbox" name="todayDimensionStones[].isIssued" id="isIssued" value="Yes"/>
I am creating another checkbox using above using clone() method using jquery.The checkbox box is created successfully.But when I checked and submit the form containing the newly created checkbox and retrieve the value of newly created checkbox,it seems to be empty ie ''. What I to do solve this problem.If any have an idea ,please share with me
You have to change the attribute name
or you have to add [] at the end of the name.
If you send two inputs with the same name without [] at he end, php gives you the last one only.
If anyone stumbles about this: value attribute is probably missing. Set it manually after cloning:
On the cloned element with some checkboxes do:
$clone.find(':checkbox').each(function() {
$(this).attr('checked','checked')
});
Thats on IE9. See https://bugs.jquery.com/ticket/10550

how do I grab the value of a checkbox using javascript?

I have a javascript that needs to grab the value of a checkbox when its checked and ignore its value when its not checked.
Right now i'm grabbing the value of the checkbox with:
$("input[name='tos']:checked").val()
It works when you check the box and submit the form, but if you uncheck it and resubmit the form the old value of "agree" is given. So i'm wondering how to I grab the value of a checkbox only when its checked?
http://jsfiddle.net/dqy5H/
Here is an example fiddle. Sorry for the bad first response.
Don't forget that unchecked checkboxes don't travel in form submission. Your code is ok, but you may have the old value stored on server side.
A workaround is tht you could have an <input type="hidden"/> that changes its value when you check/uncheck the checkbox, and read this hidden on the server. Or simply, ask if the checkbox arrived to the server, if it didn't it means it was unchecked.
Hope this helps. Cheers
Two things, in order of least to most helpful :)
A checkbox should never return a value of "agree"! I'm hoping you misspoke.
I'm not sure the jQuery selector you used there is actually valid. As the other fellow mentions, it is but it only ever sets the value when it's checked. Oof, my bad. In any case, I'd still recommend giving the checkbox an ID/unique class, and then do:
var checked = $('#toscheckbox').val();
You can add IDs without messing up the form's submission data, and I prefer them - names are so fiddly.
Try giving it an id and calling .is(':checked') like in this article to see if it is checked or not.
http://jquery-howto.blogspot.com/2008/12/how-to-check-if-checkbox-is-checked.html

Categories