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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.