Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 52
  1. #31
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Quote Originally Posted by Johnny87auxsm View Post
    One thing i noticed is if you have one error within your code the whole javascript doesn't seem to work!! , can be a huge PITA...
    Yes. But if you learn to use a debugger, 90% of that frustration will quickly go away, because it will *TELL* you where your errors are.

    I recommend using CHROME. You can debug in any browser, but I find the Chrome browser the easiest to use. It also will even tell you about errors that occurred before it is turned on.

    Just use Chrome to display your pages and hit the F12 key to bring up the debugger. Look in the CONSOLE tab to see your errors. When you see an error, click on the right side (where the filename and line number are displayed) and it shows you the JS source code where it found the error.

    That's just step 1. Gain a tiny bit more experience and then learn to set breakpoints and inspect variables.

    Spend an hour or two learning how to use the debugger and you will save dozens if not hundreds of hours down the road.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  2. #32
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    ??? "in another checkbox"? You sure you don't mean in another textbox?

    Why is that hard?

    To make a textbox non-editable, just use html.
    Code:
    <input name="whatever" readonly="readonly" />
    Surely by now you know how to copy a value from one field to another?

    You know how to read field values. I assume you know how to change them?
    read only sure, but im confused once i enter field into a textbox how to make it occur in another? Do i use "onblur () " using the first textbox?

    I have this so far but the logic is hella wrong ><

    Code:
    function parent(){
    	
    	if(document.getElementById("parent").length > 1)  {
    		document.getElementById("printname").value = "NOT SURE!?";
    This is the textbox i fill in first with whatever input
    Code:
    		<td><input type="text" size="30" id="parent" name="parent" onblur="parent()" /> </td> </tr>
    And here is where the data above should appear in this textbox -.-
    Code:
    <input type="text" size="30" id="printname" name="printname" />

  3. #33
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I did this previously using radio buttons but how do i populate data from one textbox to another ? Basically the below code is if "US" uni staff is checked or other academic staff checked or uni academic checked them populate data in the institute field with " University of Western Sydney" , never done it with textboxes though?

    Code:
    if(document.getElementById("US").checked == true || document.getElementById("OUS").checked == true || document.getElementById("UA").checked == true){
    		document.getElementById("institute").value = "University of Western Sydney";

  4. #34
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    This code makes no sense at all:
    Code:
    if(document.getElementById("parent").length > 1)  {
    		document.getElementById("printname").value = "NOT SURE!?";
    document.getElementById("parent") will return a reference to your <input type="text"> object, right?

    But an object DOES NOT HAVE A LENGTH property, unless it is a collection or array.

    Don't you mean you want to check the length of the *VALUE* of that object?

    But even then, why? If the user changes it to a blank field, shouldn't you copy that blank value to the other field?

    KEEP IT SIMPLE:
    Code:
    <form ...>
        ...
    
        <input type="text" size="30" name="parent"
               onchange="this.form.printname.value=this.value;" />
        ...
        <input type="text" size="30" name="printname" readonly="readonly" />
    
        ....
    </form>
    Yes, you could use onblur instead of onchange, but why? If the user made no changes, why bother to change the other field?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  5. #35
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    This code makes no sense at all:
    Code:
    if(document.getElementById("parent").length > 1)  {
    		document.getElementById("printname").value = "NOT SURE!?";
    document.getElementById("parent") will return a reference to your <input type="text"> object, right?

    But an object DOES NOT HAVE A LENGTH property, unless it is a collection or array.

    Don't you mean you want to check the length of the *VALUE* of that object?

    But even then, why? If the user changes it to a blank field, shouldn't you copy that blank value to the other field?

    KEEP IT SIMPLE:
    Code:
    <form ...>
        ...
    
        <input type="text" size="30" name="parent"
               onchange="this.form.printname.value=this.value;" />
        ...
        <input type="text" size="30" name="printname" readonly="readonly" />
    
        ....
    </form>
    Yes, you could use onblur instead of onchange, but why? If the user made no changes, why bother to change the other field?
    Sorry im confused i need to do it using javascript.. can't just do it using onchange

  6. #36
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    If you have many such fields in your form that need copying in the same manner, get smart about it:
    Code:
    <form ...>
        <input name="foo" onchange="copy(this)"/>
        <input name="zam" onchange="copy(this)"/>
        <input name="wak" onchange="copy(this)"/>
        ...
        <input name="printfoo" readonly="readonly" />
        <input name="printzam" readonly="readonly" />
        <input name="printwak" readonly="readonly" />
        ...
    </form>
    <script type="text/javascript">
    function copy(what)
    {
        form["print" + what.name].value = what.value;
    }
    </script>
    </body>
    </html>
    Notice where the JavaScript is? *NOT* in the <head>?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  7. #37
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Dammit why can't i edit my posts
    This is what it states
    "Non-editable value displayed in appropriate input device, based on value entered in a7 which is just the first textbox"

  8. #38
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Quote Originally Posted by Johnny87auxsm View Post
    Sorry im confused i need to do it using javascript.. can't just do it using onchange
    Yes, you really are confused.

    What in the heck do you think this is:
    Code:
        this.form.printname.value=this.value;
    It ain't chopped liver and onions, last I checked. Oh, and it's not HTML.

    Sure, you could write
    Code:
        <input name="name" onchange="clonename()"/>
        ...
    <script type="text/javascript">
    function clonename()
    {
        var form = document.forms[0];
        form.printname.value = form.print.value;
    }
    </script>
    but NOW what the heck do you think
    Code:
        clonename( )
    is? It's exactly the same non-chopped-liver.

    *ANYTHING* you put in "..." after an onchange= or onblur= or any other onXXXX= *MUST* be JavaScript code. Period.
    Last edited by Old Pedant; 05-02-2013 at 03:54 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  9. #39
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Quote Originally Posted by Johnny87auxsm View Post
    Dammit why can't i edit my posts
    See the Announcement at the top of the forum.
    This is what it states
    "Non-editable value displayed in appropriate input device, based on value entered in a7 which is just the first textbox"
    So then why are you copying the field "name" instead of the field "a7"??

    Once again, if you don't show us your HTML, it's really tough to guess what the JavaScript could or should be.

    Oh, and quite possibly your instructor does *NOT* want the stuff copied into readonly form fields. Possibly he/she wants it copied into a <div> or <span>? But that's a question you should be asking the instructor.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  10. #40
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Explain this to me , i kind of get it just confused with function (what) ?

    Code:
    <form ...>
        <input name="foo" onchange="copy(this)"/>
        <input name="zam" onchange="copy(this)"/>
        <input name="wak" onchange="copy(this)"/>
        ...
        <input name="printfoo" readonly="readonly" />
        <input name="printzam" readonly="readonly" />
        <input name="printwak" readonly="readonly" />
        ...
    </form>
    <script type="text/javascript">
    function copy(what)
    {
        form["print" + what.name].value = what.value;
    }
    </script>
    </body>
    </html>

  11. #41
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    HTML where i type into this text box first is
    Code:
    		<input type="text" size="30" id="parent" name="parent" />
    Then this box should appear with whatever i entered in the text box above ^
    Code:
    		<input type="text" size="30" id="printname" name="printname" />

  12. #42
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    copy(this) -- the this is a reference to the element containing the onchange. So in each case this refers to the <input> where it is being called from.

    function copy(what) -- the what *receives* the value that the fuction was called with. So when it was called from name="foo", then what *IS* a reference to the "foo" <input> . When called from name="wak", then what *IS* a reference to the "wak" <input>. In other words, you could have hundreds of uses of copy(this) and then *inside* that actual function what would refer to the correct one.

    Note that this is a magic keyword in JavaScript. It always means "the current object". what is just an arbitrary variable name that I picked. You would change all occurrences of what to peanutButterBrickle and it would work the same.

    Inside the copy( ) function:
    -- form["anystring"] is another way of writing form.anystring
    but the advantage is that then "anystring" really *can* be any string that you create
    -- In this case, the string I am creating is "print" followed by the name of the <input> field that was changed!
    -- So if I changed "zam", then "print" + what.name becomes "print" + "zam" which of course becomes just "printzam"
    -- And so, effectively, I am copying form.zam.value to form.printname.value
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  13. #43
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Quote Originally Posted by Johnny87auxsm View Post
    HTML where i type into this text box first is
    Code:
    		<input type="text" size="30" id="parent" name="parent" />
    Then this box should appear with whatever i entered in the text box above ^
    Code:
    		<input type="text" size="30" id="printname" name="printname" />
    Why do you insist on giving useless id's to your form fields?

    Okay, so then:
    [code]
    Code:
    <form>
    ...
    	<input type="text" size="30" name="parent" 
                   onchange="this.form.printname.value=this.value;" />
    	<input type="text" size="30" name="printname" />
    ...
    </form>
    Note that the fields *MUST* be inside of a <form>...</form>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  14. #44
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    But I still don't see what this has to do with the a7 element you mentioned. You have never shown us that field. Or the rest of the form. Or or or ...

    Does it cost you money to copy/paste your HTML here?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  15. #45
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I changed it so it suits my actual HTML , form["print" + what.name].value = what.value;

    Do i put the name of the first textbox or 2nd textbox where it says what.name]

    Code:
    <form ...>
        <input name="parent" id="parent
     onchange="copy(this)"/>
    
        ...
        <input name="printName" id="printName" readonly="readonly" />
    
        ...
    </form>
    
    <script type="text/javascript">
    function copy(what)
    {
        form["print" + what.name].value = what.value;
    }
    </script>
    </body>
    </html>


 
Page 3 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •