robert_gsfame Posted May 22, 2010 Share Posted May 22, 2010 i have checkbox in form 1 and i use this javascript code function test(){ var mytext=document.form1.elements.length; alert(mytext);} html code <form name=form1><input type=checkbox></form> <input type=button value=show onclick=test()> i cannot get any alert from this....which part is wrong thx Link to comment https://forums.phpfreaks.com/topic/202578-checkbox-problem/ Share on other sites More sharing options...
ghostcoder Posted May 22, 2010 Share Posted May 22, 2010 I'd start by putting quotes around form values. name = 'form1' onlick='test();' etc... You can also put an alert above the var mytext line, just to make sure the function is being called when you click the button. alert('infunction'); Link to comment https://forums.phpfreaks.com/topic/202578-checkbox-problem/#findComment-1062030 Share on other sites More sharing options...
Ang3l0fDeath Posted May 23, 2010 Share Posted May 23, 2010 Yep best to use Quotes around a function onclick like event. <input type=button value=show onclick="test();"> Additionally you could add data into your function. like onclick="test('data')" A good use of inputting data is to tell test a location/place like an element ID which is useful if you want to test specific check-box fields, if you want to test multi check-box fields at once, i suggest running it through a for() - loop by getElementByTagName('input').[x] - x being a nubmber, generally for(x=0; getElementByTagName('input')>x; i++){/*Add a if function that only evaluates check-boxs instead of all input fields now. Example If(getElementByTagName('input').type==='checkbox'){ //Do your stuff here to check your multi checkbox field// }*/} <input type=button value=show onclick="test('');"> Sorry about running on with all the extra info. Just trying to spread ideas. Link to comment https://forums.phpfreaks.com/topic/202578-checkbox-problem/#findComment-1062173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.