SitePoint Sponsor

User Tag List

Results 1 to 24 of 24
  1. #1
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)

    Prototype Library: Error trying to access value of <select> fields

    I have a simple form on which I would like to save its contents via Ajax. Pretty straightforward stuff. However I am using the Protoype library for the first time and having an issue handling values of <select> form fields. When I try to access the value of a field I get the following error message:

    element has no properties
    http://domain.com/scripts/prototype.js
    Line 3517
    I should mention that this works okay for accessing the values of text fields.

    Here is the code where this occurs (slightly simplified). I've bolded the text that represents a <select> form field:

    Code:
    function addToTemplates()
    {
        var url = 'ajax-template-add.php';
        var params = 'identity=' + $F('identity') + '&item=' + $F('item') + '&title=' + $F('title') + '&url=' + $F('url') + 
                     '&listing_type=' + $F('listing_type') + '&cond=' + $F('cond') + '&acct_required=' + $F('acct_required');
    
        var aj = new Ajax.Request(
            url, {
                    method: 'get',
                    parameters: params,
                    onComplete: function(resp)
                                {
                                    getResponse(resp);
                                }
                 }
            );
    }
    If anyone knows what may cause this error I would appreciate your guidance.

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, what's the select box declaration in the form look like?

  3. #3
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure you have an ID on the select elements?

  4. #4
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by SoulScratch View Post
    Are you sure you have an ID on the select elements?
    Yes. Just double checked to be sure.

    Quote Originally Posted by chris_fuel View Post
    Hmm, what's the select box declaration in the form look like?
    Actually, after further playing around, it looks like it isn't specific to all select boxes as a couple of them work. Let me go through each and every element and see which ones draw errors and which ones don't. Then I'll post them here and we'll see if we can spot a pattern or obvious problem.

  5. #5
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by SoulScratch View Post
    Are you sure you have an ID on the select elements?
    After further review I realized I had a typo in the ID on one of the fields I was having an issue with. Once I fixed it that one worked again. Thanks for the suggestion.

    I still have a text field that doesn't work though:

    Code HTML:
    <p id="templatehead">
        <label for="templatename" class="width300">Template Name:</label>
        <input type="text" name="templatename" id="templatename">
    </p>

    This one has an ID and it is correctly spelled in my JavaScript.

  6. #6
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The JS you pasted isn't even looking for the value of this input, no? $F('templatename') ?

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Please link to the updated page so that further investigations may be performed.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by SoulScratch View Post
    The JS you pasted isn't even looking for the value of this input, no? $F('templatename') ?
    My bad. Originally I didn't realize this field was being problematic. Here it is with the field included:

    Code JavaScript:
    function addToTemplates()
    {
        var url    = 'ajax-template-add.php';
        var params = 'identity=' + $F('identity') + '&item=' + $F('item') + '&title=' + $F('title')
                   + '&cond=' + $F('cond') + '&acct_required=' + $F('acct_required') + '&list_price=' + $F('list_price')
                   + '&featured=' + $F('featured') + '&bin=' + $F('bin') + '&shipping=' + $F('shipping') 
                   + '&listing_type=' + $F('listing_type') + '&templatename=' + $F('templatename');
     
        var aj = new Ajax.Request(
            url, {
                    method: 'get',
                    parameters: params,
                    onComplete: function(resp)
                                {
                                    getResponse(resp);
                                }
                 }
            );
    }

    Quote Originally Posted by pmw57 View Post
    Please link to the updated page so that further investigations may be performed.
    I can't link to the page because it is an internal website not publicly available. However if more HTML/JavaScript is needed I might be able to provide that.

  9. #9
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Only thing I could think of off hand is conflicting ids somewhere.

  10. #10
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by chris_fuel View Post
    Only thing I could think of off hand is conflicting ids somewhere.
    I was though that, too, but I confirmed it was unique to that page.

  11. #11
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you getting an error? If so what is it.

  12. #12
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    See the first post.

  13. #13
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wasn't the first post referencing the first error you fixed? The JS looks fine to me, it must be the HTML.

  14. #14
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    That's the error I get for form fields that don't work. It may be an HTML error but I don't see it as the HTML looks perfectly fine.

  15. #15
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you attach the prototype.js script that you're using? I'd just download it but I don't know if you're using the latest version. I want to see what's happening with the code.
    Last edited by chris_fuel; Feb 14, 2008 at 10:56. Reason: Used a period at the end of a question X_x

  16. #16
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    AFAIK, this is the latest version: 1.6.0.2.
    Attached Files Attached Files

  17. #17
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah. I think it's because he's trying to get the elements before the document has loaded.

    http://www.soulscratch.com/playgroun...prototype.html

    Added the proprietary 'Event.observe' used by Prototype, and now it seems to be getting all the elements.

  18. #18
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why would you use GET instead of POST?

    GET is limited to however many characters are valid for a URL in browser X, or does prototype do something different?

  19. #19
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by SoulScratch View Post
    Ah. I think it's because he's trying to get the elements before the document has loaded.
    The action occurs via an action by the user after the page has loaded (i.e. they push a button).

    Quote Originally Posted by jimfraser View Post
    Why would you use GET instead of POST?

    GET is limited to however many characters are valid for a URL in browser X, or does prototype do something different?
    I'm not sending much data and GET makes it easy for me to test the serverside script as well.

    Just tested the script out using document.getElementByID() for that field and that isn't working either so the issue might not be with prototype specifically.

  20. #20
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The action occurs via an action by the user after the page has loaded (i.e. they push a button).
    Are you only setting it on the action the user does? Or in addition to that, after everything is loaded? More code would help.

  21. #21
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    does document.getElementById() work with "templatehead" (the paragraph tag surrounding it)? Also I don't think it would make a difference, but if that's xhtml then input needs to be closed with a /> for begin an empty CDATA element.

  22. #22
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by SoulScratch View Post
    Are you only setting it on the action the user does? Or in addition to that, after everything is loaded?
    Yes and Yes.

    Quote Originally Posted by SoulScratch View Post
    More code would help.
    I'll see if I can post more tomorrow.

    Quote Originally Posted by chris_fuel View Post
    does document.getElementById() work with "templatehead" (the paragraph tag surrounding it)?
    Good question. When I hack at this again tomorrow i'll give that a try.

    Quote Originally Posted by chris_fuel View Post
    Also I don't think it would make a difference, but if that's xhtml then input needs to be closed with a /> for begin an empty CDATA element.
    I used plain old HTML for this.

  23. #23
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh and I'd verify all your tags and quoting as well. I can see a missing missing/incomplete quote/tag throwing everything off.

  24. #24
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Figured it out. The javascript I was using to let the user know something was happening was removing the form field before it could be handled by the remaining code.
    Last edited by stymiee; Feb 21, 2008 at 12:30.


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
  •