Hi,
Here I have an array returned that is returned in responseText from the server. Based on the output that is returned by the server I have to dynamically create a checkbox. -
function StateChanged() {
-
if(xmlHttp.readyState == 4) {
-
xyz=xmlHttp.responseText;
-
if(xyz!="false") {
-
alert("true");
-
Here I have to add a function to create a checkbox
-
}
-
}
-
}
-
Somebody please help me??
I was trying to use document.createElement() but it did not work.
Thanks
37 3302
you probably didn't append the created element to the document tree?
now am able to create a checkbox if a button is clicked. I wanted to check whether that particular checkbox if clicked another javascript function has to be evoked, am not able to figure out how to do that...
something like - document.getElementById(checkbox_id).addEventListener("click", callback_function, false);
-
// "change" instead of "click" should work too
-
// does not work in IE, workarounds available
Is there a possibility to add a text next to the dynamically created checkbox
And also onclick of the checkbox can we find is the checkbox been checked or unchecked
Can we pass arguments to the callback function in the eventlistener
not directly, you have three options: - use a closure. the parameter must be known at closure creation time
- function parent_function(elem, param)
-
{
-
var temp = function() { callback_with_param(param); }
-
elem.addEventListener("click", temp, false);
-
}
- use a property of the used element
- function callback()
-
{
-
var my_var = this.param;
-
// do cool stuff here using my_var
-
}
-
-
function myFunc(elem, para);
-
{
-
elem.param = para;
-
elem.addEventListener("click", callback, false);
-
}
- use an anonymous function. this event can not be removed!
- elem.addEventListener("click", function() { yourFunc(param); }, false);
I have dynamically added many checkboxes to the form and each of the checkboxes have different name,id and value. When the form is submitted how can I retrieve only those checkboxes which have been checked? The number of checkboxes in the form will vary everytime.
I will have something like this if i try to print all the posted values in the form
[red] => on [blue] => on
I want the red and blue, for my further processing
as far as I know, only the selected checkboxes will show up in the submitted data.
you can also filter off empty (i.e. all values that evaluate as false) values by - // PHP
-
$array = array_filter($_POST);
am trying to use both attachEvent and addEventListener but attchEvent is not working in IE -
if(document.getElementById('chk').addEventListener) {
-
document.getElementById('chk').addEventListener("click",function() { abc(colors); },false);
-
} else if(document.getElementById('chk').attachEvent) {
-
alert("here");
-
document.getElementById('chk').attachEvent('onClick', function() { abc(colors); });
-
} else {
-
alert("Your browser does not support any handlers");
-
}
-
Can somebody tell me what is the problem?
try (Javascript is case sensitive) - document.getElementById('chk').attachEvent('onclick', function() { abc(colors); });
otherwise you can use various cross browser functions ( e.g. addEvent() ) available via google
I have tried onclick also but even that did not work
maybe you should then use one of the addEvent() functions, they're working.
possibly attachEvent() doesn't like the anonymous function...?
attachEvent itself worked, thanks
does the -
var div=document.getElementById("div_id");
-
var example=document.createElement('input');
-
example.type='submit';
-
example.name='submit';
-
example.value='submit;
-
div.appendChild(example);
-
not work in IE because its working in mozilla but not in IE.
I'm not sure if IE creates attributes via element.value = "value"; , you still could try the DOM methods setAttribute() or createAttribute() (at least they work for me)
You have an end quote missing on line 5. Always check the error console.
actually the end quote is not the problem, I removed the element.value=value but still its not working
Well, it would've been a problem if it was missing. When you say it's not working, what exactly do you mean? Does it not show up? Does it not submit the form when clicked?
It does not submit the form when clicked
Have you set the action of the form and is the div inside a form?
yes I have, its working for mozilla but not in IE
Post the HTML code or at least some test code demonstrating the problem.
-
var div=document.getElementById("div_id");
-
var example=document.createElement('input');
-
example.type='submit';
-
example.name='submit';
-
example.value='submit';
-
div.appendChild(example);
-
-
var test=document.getElementById('mydiv');
-
var br=document.createElement('br');
-
test.appendChild(br);
-
var check=document.createElement('input');
-
-
check.type='checkbox';
-
check.id='check';
-
check.name='Testmode';
- check.value='on';
-
-
var text='Testmode';
-
test.appendChild(check);
-
test.appendChild(document.createTextNode(text));
-
var bre=document.createElement('br');
-
test.appendChild(bre);
-
var brea=document.createElement('br');
-
-
test.appendChild(brea);
-
var submit=document.createElement('input');
-
submit.type='submit';
-
submit.name='submit';
-
submit.id='submit';
-
-
submit.value='submit';
-
test.appendChild(submit);
-
That's the JavaScript code. We already have that. What about the HTML code and where and how this JavaScript code is called? You could, of course, just post a link instead if possible.
Am calling this function as soon as the response is returned form the server.
But not able to figure out why its not working in IE.
You still haven't posted the HTML code.
-
<input id="chkbx" type="checkbox" value="on" name="example"/>
-
Change the color?
-
<br/>
-
<br/>
-
Colors
-
<br/>
-
<br/>
-
<input id="red" type="checkbox" name="colors[]" value="red"/>
-
red
-
<br/>
-
<input id="blue" type="checkbox" name="colors[]" value="blue"/>
-
blue
-
<br/>
-
<input id="green" type="checkbox" name="colors[]" value="green"/>
-
green
-
<br/>
-
</div>
-
<br/>
-
<input id="check" type="checkbox" name="Testmode" value="on"/>
-
Testmode
-
<br/>
-
<br/>
-
<input id="submit" type="submit" name="submit" value="submit"/>
-
<br/>
-
I have figured out that the problem is due to the usage of two different div's can you tell me how to use insertbefore to satisfy my requirement??
the usage of one div the problem is that
->first there is a text box based on the value entered in the textbox and clicked ajax is used to get the response,based on the response
->if the response is true then some more checkboxes is created and then another dummy checkbox and then submit is created dynamically
->if the response is false then dummy checkbox and submit is created
If i do not use 2 div's then the checkboxes created when the response is true is appended after the dummy and submit button but actually it has to be created before the dummy and submit button
How do I achieve this with insertbefore??
Before I answer that, can you answer this: if you already have a submit button, why do you create another identical one?
I do not have a submit button before am creating it dynamically later
Then what about the code you posted in #30?
I create that dynamically after the response is returned from the ajax
OK, when I asked for the HTML code earlier, I meant the HTML code before any changes.
I think we're going round in circles, so the best thing would be for you to post a link to your site, so that we can see all of the code.
Sorry that cannot be done because its confidential...
what do you want me to post?
Either PM me the link or attach the files here (removing sensitive/confidential info).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Terry |
last post by:
I have a number of input boxes used to display totals based on
selected items for each row in a table. There are more than a few
rows that are identical, except for the form field name. I have...
|
by: Sileesh |
last post by:
Hi
I have datagrid with 8 items. Out of which 2 items are checkboxes. Data is
binded dynamically to the datagrid
Based on some values from the database I have to check or uncheck the
checkbox...
|
by: ted benedict |
last post by:
hi everybody, i hope this is the right place to discuss this weird
behaviour. i am getting dynamically generated text or xml from the
server side using xmlhttprequest. if the server side data is...
|
by: bradb |
last post by:
Hello,
I have a textbox with an empty span element (place holder) next to it.
When the user adds some text to the text box, I create a checkbox in
the empty span element. When I create the...
|
by: stellstarin |
last post by:
I have a html where fields are created and added dynamically on the
client side. I use the
AppendChild() call to create fields dynamically.
On submit i try to get the value for all the...
|
by: sydney.luu |
last post by:
Hello,
I would greatly appreciate if someone can show me how to dynamically
build a Repeater
with unknown number of columns at design time. I have looked various
threads in this
newsgroup,...
|
by: sydney.luu |
last post by:
Hello All,
I am programmatically building a table on my web page with one row and
two columns. The first column contains a web server checkbox
dynamically created and the second column simply...
|
by: Leena P |
last post by:
i want to basically take some information for the product and let the user
enter the the material required to make this product
1.first page test.php
which takes product code and displays...
|
by: ssmith147 |
last post by:
Hi,
I'm somewhat familiar with access and vb programming (I can read someone else's code, for the most part), but I'm still very green when it comes to creating solutions for my own needs.
I'm...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |