how to select a radio button on load??

A

admin

I have a page that has a form named search. On page load I would like
to have the radio button for the category they are searching in to be
selected. How can I do this everything I ahve tried keeps saying
object expected.
 
W

web.dev

I have a page that has a form named search. On page load I would like
to have the radio button for the category they are searching in to be
selected. How can I do this everything I ahve tried keeps saying
object expected.

Here's an example which automatically selects the first radio button.

javascript:

function autoForm()
{
var myForm = document.forms["search"];

myForm.elements["category"][0].checked = true;
}

window.onload = autoForm;

html:

<form name = "search">
<input type = "radio" name = "category"/>category 1
<input type = "radio" name = "category"/>category 2
</form>

Obviously, you'll have to implement the logic on which radio button is
to be selected.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top