Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryTutorials and Answers

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Answers To Questions About JavaScript

At Willmaster.com we receive lots of questions. Here are a few about JavaScript with the answer they were responded to.

Here are the answers to some JavaScript questions we have received.

Question:

If I am validating a form AND preventing multiple clicks, is the following code correct?

<input 
   type="text" 
   onClick="return count()" 
   onClick="ValidateAll()">
   

Thanks. Russell

Answer:

Only one onclick attribute may be used.

The use of several onclick attributes can be simulated by including one of the onclick values in the function of the other.

In your example, the count() function could include the line:

ValidateAll();

For example:

function count() {
ValidateAll();
// function count() line
// function count() line
// function count() line
}

Then only the

onClick="return count()"

attribute is specified in the INPUT field:

<input 
   type="text" 
   onClick="return count()">
   

Question:

The tutorial in Possibilities Issue # 80: "Putting Form Confirmation Pages Into Popups" is great. When using radio buttons and checkboxes, the form works okay but the JavaScript line

constructURL('content11',document.myform.content11.value);

sends the value of the field whether or not the field was checked. How can I have the value of the field sent only when it's been checked? Wilhelm

Answer:

As you noticed, radio buttons and checkboxes need somewhat different handling to retrieve their values. Each radio button and checkbox must first be tested to see whether or not it is checked. Examples:

if(document.FormName.CheckName.checked == true) {
constructURL('CheckName',document.FormName.CheckName.value);
}
if(document.FormName.RadioName[0].checked == true) {
constructURL('RadioName',document.FormName.RadioName.value);
}
if(document.FormName.RadioName[1].checked == true) {
constructURL('RadioName',document.FormName.RadioName.value);
}

Replace every occurrance of CheckName with the checkbox field name and every occurrance of RadioName with your radio button field names. Also, replace every occurrance of FormName with the name you gave your form.

Question:

How do I use radio-buttons to activate selective fields on a form using perl/cgi?

For example, if there are two choices with a submit -- no and yes. The "yes" option is associated with a text input field and "no" has nothing associated to it. If I select "no", it should deactivate the text box and not allow the user to type into it. If I select "yes" the text box should be active to take input. Srinivas

Answer:

This is probably best handled with JavaScript. Whenever a form field becomes "in focus" or is "blurred," or when the submit button is clicked, your JavaScript can check which radio button is checked and, if appropriate, blank the text field.

The reason CGI is not suitable is because the form must be submitted before the program can do anything with it. What you need, in this case, is something that will do the checking before the form is submitted. JavaScript is good for that.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC