SitePoint Sponsor

User Tag List

Page 4 of 5 FirstFirst 12345 LastLast
Results 76 to 100 of 112
  1. #76
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    I know about the arrays. But what I do not know which is the array
    Code:
    var links = form1.getElementsByTagName("a");
    The links variable is the array.

    Quote Originally Posted by newtomysql View Post
    and what this array consists of
    It consists of elements, HTML elements, which you can tell from the above code are anchor elements.

    and what value can I get from this array?
    The value or benefit that you can get from the array, is that it contains all of the links within the form, which allows you to easily process them.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  2. #77
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    When I run this after submitting the form it shows me the length is 0? Why ya?
    function validateForm()
    {
    var form1= document.getElementById('form1');
    var links = form1.getElementsByTagName("a");
    alert("Length:"+links.length);
    for (var i = 0; i < links.length; i++) {

    alert("Links :"+links[0]);

    }

  3. #78
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    When I run this after submitting the form it shows me the length is 0? Why ya?
    It's either because there are no links in there, or that the the form variable is undefined. Please link to a test page that demonstrates the problem.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #79
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Here is the link Untitled Document. Just select a drop down list value and then press submit button. Thank you.

  5. #80
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Here is the link Untitled Document. Just select a drop down list value and then press submit button. Thank you.
    It looks like your HTML code is causing the problem.

    Code:
    <table> 
    <form action="/tm/addAssign.php" method="post" name="form1" id=form1 onSubmit="return validateForm();"> 
    <tr>
    The form tag is in an invalid location, so web browsers automatically close off the form.

    You should be able to get away with it though by putting the entire table within the form.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #81
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Ok done is working now. But the problem as below. I have tried links[0],links[1] and links[2] all showing the same value that is the full link.

    for (var i = 0; i < links.length; i++) {

    alert("Links :"+links[2]);

    }

  7. #82
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Ok done is working now. But the problem as below. I have tried links[0],links[1] and links[2] all showing the same value that is the full link.

    for (var i = 0; i < links.length; i++) {

    alert("Links :"+links[2]);

    }
    I really do think that you are doing yourself a dis-service by assuming that you know how to access arrays. That link I provided a few posts ago takes you through learning a lot about them.

    Anyway, you are using an absolute index number, which will always give you the same item from the array. You should instead be making use of the i variable from the loop.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #83
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Ok this gives me the right value now alert("Links :"+links[i].value);. So once I find a empty one I should return false. How best to point which select is empty.

  9. #84
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Ok this gives me the right value now alert("Links :"+links[i].value);. So once I find a empty one I should return false. How best to point which select is empty.
    The value property of a link will not result in anything useful.

    Let's keep it simple. You can use innerHTML to get the text content of the link.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #85
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Done is working too with innerHTML. So now how to point exactly which select is not selected with a value? Is it just an alert or any other way you have.

  11. #86
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Done is working too with innerHTML. So now how to point exactly which select is not selected with a value? Is it just an alert or any other way you have.
    You could apply a class name to the appropriate link, such as "incomplete" so that you can then style its presentation appropriately.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  12. #87
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I have done accordingly ready.I only need your help how to apply the class.

    var rtValue=true;
    for (var i = 0; i < links.length; i++) {

    alert("Links :"+links[i].innerHTML);
    if(links[i].innerHTML=="Select")
    {
    links[i].innerHTML="Incomplete";
    rtValue=false;
    }
    }
    return rtValue;

  13. #88
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    I have done accordingly ready.
    I think that it's a mistake for you to change the text of the link, because it will become a problem the next time you look for ones that still need to be selected.

    Quote Originally Posted by newtomysql View Post
    I only need your help how to apply the class.
    The className property is used to apply a class name.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  14. #89
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    So how to overcome my problem with the change of the text on the link?

  15. #90
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    So how to overcome my problem with the change of the text on the link?
    Simple - don't change the text on the link.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  16. #91
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    If I dont change the text then where to put the text "Incomplete" with the new class? Thank you.

  17. #92
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    If I dont change the text then where to put the text "Incomplete" with the new class? Thank you.
    The name "incomplete" is what you set to the class name of the element.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  18. #93
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I have set in my css as below. So will this be correct links[i].class=inComplete?

    a.inComplete
    {
    color:red;
    font-family: Calibri;
    font-size:12px;

    }

  19. #94
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    I have set in my css as below. So will this be correct links[i].class=inComplete?
    There are at lest three problems there.

    1. className is the method that is used to set the class on an element.
    2. It should be a string that is assigned, instead of what you have there.
    3. lowercase class names are the norm
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  20. #95
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Please correct me.

    links[i].className="incomplete".

  21. #96
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Please correct me.

    links[i].className="incomplete".
    That seems to be about right.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  22. #97
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Ok it works well now once I submit it becomes red color to highlight those not selected. I got one question why when I get the value of drop drop on change my drop down list is separate far away from the label "Layout*". The link is here Untitled Document

  23. #98
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Ok it works well now once I submit it becomes red color to highlight those not selected. I got one question why when I get the value of drop drop on change my drop down list is separate far away from the label "Layout*". The link is here Untitled Document
    That has to do with the table layout of your page. Your select is currently in the right-hand column, the same column as the Revert button.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  24. #99
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Ok I guess for that I will spilt into two tables will best. I got another query. How best can I check that none of the select value are same before submitting? Is it buy running two different for loop is it? Any thing simpler you know of ?

  25. #100
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Ok I guess for that I will spilt into two tables will best. I got another query. How best can I check that none of the select value are same before submitting? Is it buy running two different for loop is it? Any thing simpler you know of ?
    Use a hash-table to store the already entered values.


    Code javascript:
    var hash = [];
    ...
    var value = 'foo';
    if (hash[value] === true) {
        alert('Haha! A duplicate!!');
    }
    hash[value] = true;


    That way, you end up with an array that looks something like this:

    Code:
    [
        foo: true,
        urble: true,
        burble: true,
        wurble: true
    ]
    So if someone sys "wurble" to you again, you can tell that it's already happened.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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