Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Old 10-06-2004, 05:16 AM Java Script
frik's Avatar
Average Talker

Posts: 26
Location: SOuth Africa
Trades: 0
I want to create an onload function. This function must reset the values in a form to "All".I came across this script. The problem that I have it clears all the values to blank.
}
function Reset() {
document.forms[0].elements[0].value = "";
document.forms[0].elements[1].value = "";
document.forms[0].elements[2].value = "";
document.forms[0].elements[3].value = "";
document.forms[0].elements[4].value = "";
document.forms[0].elements[5].value = "";
document.forms[0].elements[6].value = "";
document.forms[0].elements[7].value = "";
document.forms[0].elements[0].focus();
}

When I change the "" to "All" it only changes the first fields value to "All". The first field is a text field and the rest of the fields are option select fields. Is there a way that I can change the values of the select fields to All using the above script ?
frik is offline
Reply With Quote
View Public Profile Visit frik's homepage!
 
 
Register now for full access!
Old 10-06-2004, 09:02 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
frik,

Do you have "All" as valid options in the select structures?
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 10-06-2004, 01:55 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
It's a bit different with option selects, you can't just set a value with a string like that. You have to set the selectedIndex property the index of your "All" item within the select box. IE:

HTML Code:
<select name="myitem">
    <option value="All">All</option>
    <option value="bleh">Bleh</option>
    <option value="bleh">Bleh</option>
</select>
In that example, the index of "All" is 0 (indicies always start at zero, so the first "bleh" would be index 1). To change it, I'd use:
Code:
document.forms[0].elements[0].selectedIndex = 0;
Hope that helps.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Java Script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40383 seconds with 12 queries