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.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Problem with blank form values in Safari

    Hi List

    I am having a problem Ajax.Updater that only seems to occur with Safari.

    The application is a dynamic "drop-down" based on categories and subcategories. You select the primary category and the page shows you the correct sub-categories, in a standard <SELECT> construction.

    In Safari, on the screen it works fine, but the "subcategory" value is empty on the SUBMITted page.

    This is my javascript:

    Code:
    function ajaxhandler() {
    
    var thevalue = document.getElementById("pcategory").value;
    if (thevalue != ' ') {
    	new Ajax.Updater('subcatdiv', 'sq-subcatdisplay.lasso',{method:'post', parameters: {xcategory: thevalue}  });
    	}
    }
    Here is the primary category bit, invoking the js function, this [] stuff is actually lasso code but should be fairly easy to follow.

    Code:
    <select name="pcategory" id="pcategory"  size="1" onchange="ajaxhandler();">
    <option [if: $subcategory==''] selected="selected" [/if] value="">Please Select</option>
    [records]
        <option [if: (field: 'CategoryID')==$pcategory] selected="selected" [/if] value="[field: 'categoryid']">[field: 'title']</option>
    [/records]
    </select>
    This is the subcategory bit:

    Code:
    <td colspan="3">
    	<div name="subcatdiv" id="subcatdiv">
    	Please Select the Category
    	</div>
    </td>
    the meat of this is the 'sq-subcatdisplay.lasso' page, it receives the xcategory parameter each time and generates a select statement, something like:

    Code:
    <select name="subcategory">
    <option value="one">First</option>
    <option value="two">Second</option>
    <option value="three">Third</option>
    </select>
    I hope this all makes sense, I really have no idea why it doesn't work so any pointers appreciated.

  • #2
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    [solved]

    I have put in a work around which fixed this.

    It seems Safari does know the new value of the form element, whilst its on the screen, it just doesn't know it when the form is submitted. I have put in a line of javascript before the form is submitted to set the value of a hidden element to the value of the element updated by the ajax updated element.

    So instead of just submitting the form, I do this:

    Code:
    ajaxfix() ;
    document.updateform.submit() ;
    This is my ajaxfix() which could be just one line:
    Code:
    {
    var testvar = document.getElementById('ajaxsubcat').value ;
    document.getElementById('subcategory').value = testvar ;
    }

    So now my select uses "ajaxsubcat" not subcategory, so the effect is this:

    Code:
    <div id="ajaxdiv">
    <select name="ajaxsubcat">
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
    </select>
    </div>
    <input type="hidden" name="subcategory" id="subcategory" value="0" />
    Please note this is not the full code, just a technique.


  •  

    Posting Permissions

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