Jump to content

checkbox problem


robert_gsfame

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.