Changing Input Type, length and value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Boyd Reilly

    #1

    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="makei nputbox;"
    width="200" style="width:20 0">
    <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="MySingleL ineTextBox"
    SIZE=50 MAXLENGTH=75 VALUE="">

    </select>
    </form>
    <script language="JavaS cript">

    <!--
    function makeinputbox {
    document.frm1.M ySingleLineText Box.TYPE='numer ic';
    document.frm1.M ySingleLineText Box.SIZE=5;
    document.frm1.M ySingleLineText Box.MAXLENGTH=5 ;
    document.frm1.M ySingleLineText Box.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





  • HikksNotAtHome

    #2
    Re: Changing Input Type, length and value

    In article <4000cd7d$0$674 4$61fed72c@news .rcn.com>, "Boyd Reilly"
    <spammeplease@s pammersanonymou s.com> writes:
    [color=blue]
    ><script language="JavaS cript">[/color]

    use type="text/javascript" instead.
    [color=blue]
    >
    ><!--
    >function makeinputbox {
    >document.frm1. MySingleLineTex tBox.TYPE='nume ric';[/color]

    You can't programatically change the type of an input. Its a read only value.
    But I have never heard of a type="numeric".
    [color=blue]
    >document.frm1. MySingleLineTex tBox.SIZE=5;[/color]

    document.frm1.m ySingleLineText Box.size = 5;

    Javascript is case sensitive.
    [color=blue]
    >document.frm1. MySingleLineTex tBox.MAXLENGTH= 5;[/color]

    Should be:

    document.frm1.M ySingleLineText Box.maxLength=5 ;
    [color=blue]
    >document.frm1. MySingleLineTex tBox.value=1.00 ;[/color]

    document.frm1.M ySingleLineText Box.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
    [color=blue]
    >}
    >// -->
    >
    ></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 .[/color]

    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.javas cript archives on how to validate a Number and how to validate a
    Date (its not easy).

    Hope this helps.
    --
    Randy

    Comment

    • Boyd Reilly

      #3
      Re: Changing Input Type, length and value

      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="JavaS cript"> 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 " <hikksnotathome @aol.com> wrote in message
      news:2004011100 4641.07578.0000 2522@mb-m25.aol.com...[color=blue]
      > In article <4000cd7d$0$674 4$61fed72c@news .rcn.com>, "Boyd Reilly"
      > <spammeplease@s pammersanonymou s.com> writes:
      >[color=green]
      > ><script language="JavaS cript">[/color]
      >
      > use type="text/javascript" instead.
      >[color=green]
      > >
      > ><!--
      > >function makeinputbox {
      > >document.frm1. MySingleLineTex tBox.TYPE='nume ric';[/color]
      >
      > You can't programatically change the type of an input. Its a read only[/color]
      value.[color=blue]
      > But I have never heard of a type="numeric".
      >[color=green]
      > >document.frm1. MySingleLineTex tBox.SIZE=5;[/color]
      >
      > document.frm1.m ySingleLineText Box.size = 5;
      >
      > Javascript is case sensitive.
      >[color=green]
      > >document.frm1. MySingleLineTex tBox.MAXLENGTH= 5;[/color]
      >
      > Should be:
      >
      > document.frm1.M ySingleLineText Box.maxLength=5 ;
      >[color=green]
      > >document.frm1. MySingleLineTex tBox.value=1.00 ;[/color]
      >
      > document.frm1.M ySingleLineText Box.value="1.00 ";
      >
      > as you have it written, its setting it to the number 1.00, which it[/color]
      displays as[color=blue]
      > 1, quote it and make it a string, it displays as 1.00
      >[color=green]
      > >}
      > >// -->
      > >
      > ></script>
      > >
      > >The only thing that happens is that the value gets set to 1, not 1.00.[/color][/color]
      The[color=blue][color=green]
      > >input bo still keeps all of its original characteristics .[/color]
      >
      > The case is what was causing it not to work, as the properties you are[/color]
      trying[color=blue]
      > 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[/color]
      the[color=blue]
      > type of text that you will accept and thats a different story. Search the
      > comp.lang.javas cript archives on how to validate a Number and how to[/color]
      validate a[color=blue]
      > Date (its not easy).
      >
      > Hope this helps.
      > --
      > Randy[/color]


      Comment

      • Richard Cornford

        #4
        Re: Changing Input Type, length and value

        "Boyd Reilly" <spammeplease@s pammersanonymou s.com> wrote in message
        news:4000ed64$0 $6736$61fed72c@ news.rcn.com...[color=blue]
        >Thanks for he help. If you haven't already noticed, I'm a bit
        >new to java scripting.[/color]

        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.javas cript 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.
        [color=blue]
        >If you could, please explain the
        >difference between <script language="JavaS cript"> and[/color]

        Randy actually wrote - type="text/javascript" - rather than:-
        [color=blue]
        ><script language="text/javascript">.[/color]

        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).
        [color=blue]
        >Also, I have been learning java scripting, mostly, through example.[/color]

        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.
        [color=blue]
        >You say type is read-only. Is there a way to change
        >it to a date or numeric type format?[/color]

        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.
        [color=blue]
        >Basically, I want to restrict users to only a numbers or a date
        >format.[/color]

        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).
        [color=blue]
        >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.[/color]

        And Randy wrote:-

        <snip>[color=blue][color=green]
        >>.... You are wanting to limit the type of text that
        >>you will accept and thats a different story. Search the
        >>comp.lang.jav ascript archives on how to validate a Number[/color]
        >and how to validate a Date (its not easy).[/color]
        <snip>

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

        Richard.


        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: Changing Input Type, length and value

          hikksnotathome@ aol.com (HikksNotAtHome ) writes:
          [color=blue]
          > You can't programatically change the type of an input. Its a read only value.[/color]

          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.creat Element("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.
          [color=blue]
          > But I have never heard of a type="numeric".[/color]

          It doesn't exist in HTML.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • HikksNotAtHome

            #6
            Re: Changing Input Type, length and value

            In article <brpaguwv.fsf@h otpop.com>, Lasse Reichstein Nielsen <lrn@hotpop.com >
            writes:
            [color=blue]
            >hikksnotathome @aol.com (HikksNotAtHome ) writes:
            >[color=green]
            >> You can't programatically change the type of an input. Its a read only[/color]
            >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.creat Element("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.[/color]

            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.
            [color=blue][color=green]
            >> But I have never heard of a type="numeric".[/color]
            >
            >It doesn't exist in HTML.[/color]

            I already knew that.
            --
            Randy

            Comment

            • Jim Ley

              #7
              Re: Changing Input Type, length and value

              On Sun, 11 Jan 2004 20:14:08 +0100, Lasse Reichstein Nielsen
              <lrn@hotpop.com > wrote:
              [color=blue]
              >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.[/color]

              document.implem entation.hasFea ture("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.javas cript FAQ - http://jibbering.com/faq/

              Comment

              Working...