473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Changing Input Type, length and value

I have a form that has the user pick the type of question he will answer.
The input field will be a text, numeric or date type. So, after the
question is answered, I need to change the input statement. This resembles
what I am doing:

<form name="frm1">
Step 1 - Choose a File: <select name="selA" OnChange="makeinputbox;"
width="200" style="width:200">
<option value="">Date of Birth</option>
<option value="MASTER">Age</option>
<option value="ADDRESS3">Maiden Name</option>
Step 2 - Insert Value: <INPUT TYPE="text" NAME="MySingleLineTextBox"
SIZE=50 MAXLENGTH=75 VALUE="">

</select>
</form>
<script language="JavaScript">

<!--
function makeinputbox {
document.frm1.MySingleLineTextBox.TYPE='numeric';
document.frm1.MySingleLineTextBox.SIZE=5;
document.frm1.MySingleLineTextBox.MAXLENGTH=5;
document.frm1.MySingleLineTextBox.value=1.00;
}
// -->

</script>

The only thing that happens is that the value gets set to 1, not 1.00. The
input bo still keeps all of its original characteristics.

Any ideas what I need to do?

TIA.

Boyd

Jul 20 '05 #1
6 2440
In article <40**********************@news.rcn.com>, "Boyd Reilly"
<sp**********@spammersanonymous.com> writes:
<script language="JavaScript">
use type="text/javascript" instead.

<!--
function makeinputbox {
document.frm1.MySingleLineTextBox.TYPE='numeric ';
You can't programatically change the type of an input. Its a read only value.
But I have never heard of a type="numeric".
document.frm1.MySingleLineTextBox.SIZE=5;
document.frm1.mySingleLineTextBox.size = 5;

Javascript is case sensitive.
document.frm1.MySingleLineTextBox.MAXLENGTH=5;
Should be:

document.frm1.MySingleLineTextBox.maxLength=5;
document.frm1.MySingleLineTextBox.value=1.00;
document.frm1.MySingleLineTextBox.value="1.00";

as you have it written, its setting it to the number 1.00, which it displays as
1, quote it and make it a string, it displays as 1.00
}
// -->

</script>

The only thing that happens is that the value gets set to 1, not 1.00. The
input bo still keeps all of its original characteristics.


The case is what was causing it not to work, as the properties you are trying
to change are case Sensitive. Other than the type, which is readonly.

But, when you say you want to change it to Numeric, Date or Text. Of those
three, only the text is a valid type of input. You are wanting to limit the
type of text that you will accept and thats a different story. Search the
comp.lang.javascript archives on how to validate a Number and how to validate a
Date (its not easy).

Hope this helps.
--
Randy
Jul 20 '05 #2
Randy:

Thanks for he help. If you haven't already noticed, I'm a bit new to java
scripting. If you could, please explain the difference between <script
language="JavaScript"> and <script language="text/javascript">.

Also, I have been learning java scripting, mostly, through example. You say
type is read-only. Is there a way to change it to a date or numeric type
format? Basically, I want to restrict users to only a numbers or a date
format. I guess if it is really a read-only function I'm going to have to
develop a different method of attacking this problem - suggestions are
welcome.

TIA.

Boyd
"HikksNotAtHome" <hi************@aol.com> wrote in message
news:20***************************@mb-m25.aol.com...
In article <40**********************@news.rcn.com>, "Boyd Reilly"
<sp**********@spammersanonymous.com> writes:
<script language="JavaScript">
use type="text/javascript" instead.

<!--
function makeinputbox {
document.frm1.MySingleLineTextBox.TYPE='numeric ';


You can't programatically change the type of an input. Its a read only

value. But I have never heard of a type="numeric".
document.frm1.MySingleLineTextBox.SIZE=5;
document.frm1.mySingleLineTextBox.size = 5;

Javascript is case sensitive.
document.frm1.MySingleLineTextBox.MAXLENGTH=5;


Should be:

document.frm1.MySingleLineTextBox.maxLength=5;
document.frm1.MySingleLineTextBox.value=1.00;


document.frm1.MySingleLineTextBox.value="1.00";

as you have it written, its setting it to the number 1.00, which it

displays as 1, quote it and make it a string, it displays as 1.00
}
// -->

</script>

The only thing that happens is that the value gets set to 1, not 1.00. Theinput bo still keeps all of its original characteristics.
The case is what was causing it not to work, as the properties you are

trying to change are case Sensitive. Other than the type, which is readonly.

But, when you say you want to change it to Numeric, Date or Text. Of those
three, only the text is a valid type of input. You are wanting to limit the type of text that you will accept and thats a different story. Search the
comp.lang.javascript archives on how to validate a Number and how to validate a Date (its not easy).

Hope this helps.
--
Randy

Jul 20 '05 #3
"Boyd Reilly" <sp**********@spammersanonymous.com> wrote in message
news:40**********************@news.rcn.com...
Thanks for he help. If you haven't already noticed, I'm a bit
new to java scripting.
And Usenet too by the look of it.

JavaScript (one word) is not scripting with Java. Java is a distinct
language (and in most respects a very different language). The name was
probably a mistake as it causes a lot of confusion, but it is too late
now.

There is a longstanding convention on Usenet that messages are formatted
so that only material that is being responded to is quoted and the text
that represents the response appears under the quoted text that is being
responded to. You have quoted the entire message you are responding to
verbatim (and badly line wrapped) and have placed your reply above it. A
practice known as "Top Posting" and strongly discouraged.

It is often proposed that there is a correlation between top posting and
evidence in the top posted text of a failure to read the material that
has been posted over.

Another Usenet convention has technical groups maintaining a frequently
asked questions resource and asking new participants to read it,
preferably prior to posting to the group but ASAP otherwise. The
comp.lang.javascript FAQ is posted to the group on a regular bases
(search for FAQ in subject lines) and is also available online at:-

<URL: http://jibbering.com/faq/ >

Section 2.3 is of immediate relevance, but reading the rest (and linked
resources) will be invaluable for a novice JavaScript author.
If you could, please explain the
difference between <script language="JavaScript"> and
Randy actually wrote - type="text/javascript" - rather than:-
<script language="text/javascript">.
A discrepancy that you probably would have spotted if you had posted
that line directly under a quote of his comment.

The HTML 4.01 SCRIPT element has 7 official attributes defined in its
(loose) DTD. TYPE and LANGUAGE are two of those. The TYPE attribute is
listed as required by the DTD and so it must be present for an HTML 4
document to be valid. If the script language used is JavaScript, and
baring in mind that HTML attribute names are case insensitive, then the
opening script tag must include:-

type="text/javascript"

On the other hand the LANGUAGE attribute is deprecated, which is
intended to indicate that it should no longer be used. And the HTML 4.01
strict DTD does not include the LANGUAGE attribute so a document written
to conform to that DTD could not include it and still be valid.

In practice these are considerations of formal correctness. Most
browsers don't know any other scripting languages and those that do
default to assuming JavaScript in the absence of anything to the
contrary. Browsers are also extremely tolerant of errors and willing to
bend over backwards to make some sort of sense out of whatever rubbish
they are sent, so just writing "<script>" will probably have the desired
result.

However, there is an axiom that goes: be tolerant in what you accept and
strict in what you send. The browsers are tolerant in what they accept
and it is up to the web authors to be strict in what they send. Which
means valid HTML (at least) and so the TYPE attribute in script tags and
only the LANGUAGE attribute if the strict DTD is not used (and even then
preferably no LANGUAGE attribute).

But valid HTML has an advantage of its own when combined with
JavaScript. The script wants to be able to interact with a DOM
constructed from that HTML and there are (more or less) well specified
rules as to what that DOM should be like when it is constructed based on
valid HTML. The browsers might not always manage to hit the desired
target but at least you know that they are all shooting at the same
target.

While a browser receiving invalid HTML will apply various "error
correcting" rules to sort the HTML out into a DOM that makes sense. But
those rules are particular to the individual browsers and not published
or standardised in any way so there can be a lot of variation in the DOM
that results. The last thing a script author want is to encourage more
inconsistency in the DOMs that they will be working with (there is
enough of that already).
Also, I have been learning java scripting, mostly, through example.
Be extremely cautions of example scripts found on the internet
(especially in the form of copy'n'paste collections) you will probably
find considerably more examples that exemplify how *not* to write
scripts than good examples.
You say type is read-only. Is there a way to change
it to a date or numeric type format?
There is no such thing as date or numeric format with INPUT elements.
They accept strings of text, nothing more and nothing less. You can
specify a maximum length for the string but that is it.
Basically, I want to restrict users to only a numbers or a date
format.
No, that is not what you want to do. You want to provide the user with
information about the format you would like, possibly you would also
want to verify that what the user enters is in that format once they
have entered it and prior to sending the information to a server for
back-end processing (baring in mind that all client-side verification
can be subverted so the back-end must always check that its input
conforms to its requirements). That is standard form validation and you
will be able to find hundreds of examples in the archives. Pay
particular attention to Regular Expression based validation code (but
not for all tasks).
I guess if it is really a read-only function I'm going to have to
develop a different method of attacking this problem - suggestions
are welcome.


And Randy wrote:-

<snip>
.... You are wanting to limit the type of text that
you will accept and thats a different story. Search the
comp.lang.javascript archives on how to validate a Number

and how to validate a Date (its not easy).

<snip>

The comp.lang.javascript archives are available at groups.google.com and
google provide more ways of searching them than you will probably find a
use for.

Richard.
Jul 20 '05 #4
hi************@aol.com (HikksNotAtHome) writes:
You can't programatically change the type of an input. Its a read only value.
Not in DOM 2.
<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-6043025>

It is read-only in DOM 1, but since you need to be able to set the type
of a newly created input element (document.creatElement("input")), it
must be writable.

Browser uspport for DOM 2 is a different problem, ofcourse. As usual
IE won't understand it when you change the type after setting it the
first time.
But I have never heard of a type="numeric".


It doesn't exist in HTML.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
In article <br**********@hotpop.com>, Lasse Reichstein Nielsen <lr*@hotpop.com>
writes:
hi************@aol.com (HikksNotAtHome) writes:
You can't programatically change the type of an input. Its a read only

value.

Not in DOM 2.
<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-6043025>

It is read-only in DOM 1, but since you need to be able to set the type
of a newly created input element (document.creatElement("input")), it
must be writable.

Browser uspport for DOM 2 is a different problem, ofcourse. As usual
IE won't understand it when you change the type after setting it the
first time.


And since IE won't allow it to be *changed*, not written, then you can't
programatically change its type. Although I am very open to seeing code that
will allow this to work.
But I have never heard of a type="numeric".


It doesn't exist in HTML.


I already knew that.
--
Randy
Jul 20 '05 #6
On Sun, 11 Jan 2004 20:14:08 +0100, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
Browser uspport for DOM 2 is a different problem, ofcourse. As usual
IE won't understand it when you change the type after setting it the
first time.


document.implementation.hasFeature("DOM 2.0") makes no claim to
supporting DOM 2, so you can't complain it doesn't do something it
claims to.

(Of course the hasFeature test is ridiculous)

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Ryan | last post by:
I've a small bit of javascript on my site that has a from with 2 selection boxes, when you choose an option in the first box, the second one re-populates its list accordingly. But the second...
1
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with...
7
by: Stefan Finzel | last post by:
Hi, is there a way to change the display property on Windows Mobile 2003 SE Mobile/Pocket Internet Explorer? See following example. Please note: visibilty property has the same problem. Is...
4
by: Siah | last post by:
Hi, I wanted to dynamically update pieces of my page in the following fashion. Look at the following html code: <span id='person_23_name'> Mike </span> <span id='person_28_name'> Siah </span>...
13
by: amykimber | last post by:
Hi all, I know I'm doign something really daft, but I can't get this to work... I have a form with a bunch of inputs called ship_owner - why the ? Because I'm submitting this page though php...
2
by: yawnmoth | last post by:
Say I have two input elements and that I wanted to make it so that when the first ones input was what it should be, the focus would automatically be shifted to the next input element. ie....
4
by: gubbachchi | last post by:
Hi all, Please anybody help me solve this problem. I am stuck up with this from past 2 weeks. I am developing an application where, when the user selects date from javascript datepicker and enters...
18
vikas251074
by: vikas251074 | last post by:
I am using ASP In my company, all employees have to sent materials out of premises. Any employee who need to sent material out will use this web application. In the first page, an employee enters...
8
omerbutt
by: omerbutt | last post by:
hi there i have a form with multiple input (type/text ) fields and three inputs(type/file) fields i have to submit the form via ajax because i have multiple forms on this page ,you can say it is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.