/    Sign up×
Community /Pin to ProfileBookmark

I have a few scripts in a PHP suite that use some simple JavaScript functions, but a couple of them don’t work in Firefox.

I only use JavaScript occasionally, so I forget even the simplest stuff. Does anyone know of a simple, step by step, easy to follow, cross browser DOM reference guide?

OR

Specifically, I need to know how to read data in textboxes, checkboxes, radio buttons, selects and textareas, and then how to write data in the same, or in the case of the select, just select an option. (*see below for form code)

I tried the little tutorial at w3schools.com, but they use methods that look a tad more complicated than I suspect they need to be, and they also reference the form and its elements by their numbers rather than by their names, which is a pain somewhere a little lower than my neck.

And can someone please tell me when I should use name=”somename” and when I should use id=”somename” (and when, as seems common, I should use both)?

Any help, as always, greatly appreciated.

Thanks
CTB

PS. As I am a self confessed simpleton when it come to JavaScript, if anyone wants to try to give me some examples, please relate them to the elements in this form.

<form id=”myform” name=”myform” action=”someaction.php” target=”_top”>
<input type=”text” name=”myname” value=”Chester The Bear”><br />
<input type=”checkbox” name=”mycheckbox” value=”Y” checked><br />
<input type=”radio” name=”radio” value=”V1″><br />
<input type=”radio” name=”radio” value=”V2″ checked “><br />
<textarea name=”mytextarea”>Some very boring text here</textarea><br />
<select name=”myselect”>
<option value=”1″>First Line</option>
<option value=”2″>Second Line</option>
</select>
<input type=”submit” value=”Submit This”>
<form>

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@balloonbuffoonFeb 23.2005 — To make the contents of a form element a variable:
<i>
</i>var VARIABLE_NAME = document.myform.FORM_ELEMENT_NAME.value;

and to write:
<i>
</i>function write() {
document.myform.FORM_ELEMENT_NAME.value = "WHAT YOU WANT TO WRITE";
}

and to write you just call thwe function: (for example w/ button)
<i>
</i>&lt;form&gt;
&lt;input type="button" onClick="write()" value=" Write "&gt;
&lt;/form&gt;


-Steve
Copy linkTweet thisAlerts:
@chestertbauthorFeb 24.2005 — Thanks BalloonBuffoon,

I appreciate you taking the time to assist.

That covers reading and writing the contents of a text box, but what about textareas, checkboxes and radio buttons?

And what about selecting an option in a select box?

Thanks

CTB
Copy linkTweet thisAlerts:
@balloonbuffoonFeb 24.2005 — Ok, for text areas, it would be the same as textboxes. For checkboxes (to see if its checked):
<i>
</i>if (document.FORM_NAME.CHECKBOX_NAME.checked) {
WHATEVER
}

and to make a checkbox checked
<i>
</i>document.FORM_NAME.CHECKBOX_NAME.checked=true;

and to make a checkbox unchecked:
<i>
</i>document.FORM_NAME.CHECKBOX_NAME.checked=false;

and select option in select box:
<i>
</i>&lt;form name=form&gt;
&lt;select name=select&gt;
&lt;option value=1&gt;1&lt;/option&gt;
&lt;option value=2&gt;2&lt;/option&gt;
&lt;option value=3&gt;3&lt;/option&gt;
&lt;option value=4&gt;4&lt;/option&gt;
&lt;option value=5&gt;5&lt;/option&gt;
&lt;/select&gt;&lt;br&gt;
&lt;a href="" onClick="select.value='3'"&gt;CLICK&lt;/a&gt;
&lt;/form&gt;

You need to make sure to give values to each option and change the 3 to whatever value of whatever option you want to select.

Radio buttons I'm not sure, maybe someone else does? I'd like to learn that, too! (I use drop-downs instead of radios, always.)

-Steve
Copy linkTweet thisAlerts:
@chestertbauthorFeb 24.2005 — Thanks BalloonBuffoon... awesome!

Works fine in IE.

I'll check it in Firefox later.

I do not understand why JavaScript Totorials or Reference Guides are not set out like that!

Much appreciated.

CTB
Copy linkTweet thisAlerts:
@balloonbuffoonFeb 24.2005 — No problem.

It always seems that people have problems with javascript books and such being too complicated and not showing the easiest way. I wonder why they do that? hmmm....

-Steve
Copy linkTweet thisAlerts:
@chestertbauthorFeb 24.2005 — For the <select>...

If I want to change the currently selected item external to the select options list, would I use the following...

function selectit()

{

document.FORM_NAME.SELECT_NAME.select.value = "something that matches one of my values"

}

?

Thanks

CTB
×

Success!

Help @chestertb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...