Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Javascript problem to submit a form in Safari or Firefox



Apple has a great article with examples for AJAX: <http:// developer.apple.com/internet/webcontent/xmlhttpreq.html>. Also since AJAZ is buzzword du jour, there will be many other resources. I wrote a very simple ajax form that does exactly what you want here: <http://search.businessweek.com/AdvancedSearch? searchType=advanced&sortBy=relevance&skin=autoMake&make=Ferrari&model=F4 30+> The Find More Reviews section uses Ajax to populate the Model dropdown based on the selected Make.

I mocked up a simple html page with your js code in the head & a single form:

<form method="get" name="membersSearch">
<select id="s_talent_cat" name="s_talent_cat">
<option label="Test 1" value="test1">Test 1</option>
<option label="Test 2" value="test2">Test 2</option>
<option label="Test 3" value="test3">Test 3</option>
</select>
</form>

Changing the item did indeed cause the reload of the page passing the selected item, so maybe something else in your html is off? If you want, send me the full html page off list & I can check it out.

Niels


On Mar 20, 2006, at 3:15 PM, Louis Philip Morin wrote:

I can say the form is not being submitted, which pointed me to the fact that the event onchange did not get picked up by my javascript. The script only forces a submit of the form, and nothing else. Since this doesn't work, Mac users have to manually hit the submit button, which reloads the page with the updated dropdown. I'm keenly aware that this isn't the best solution, and thank you for pointing to me an alternative. Though I'm not familiar with AJAX, I guess I'll take a look at it. Any pointers on a good exemple of what I would need? I'll be doing my own research of course, but it would still help.

Here's the code, hope it comes through :

function forms_onload()
{
  var forms = document.forms;
  var i, j, elm, form;
  for(i = 0; i < forms.length; i++)
  {
    form = forms[i];
    if (typeof(form.onLoad) == "function") form.onLoad();
    for (j = 0; j < form.elements.length; j++)
    {
      elm = form.elements[j];
      if (typeof(elm.onLoad) == "function") elm.onLoad();
    }
  }
  return true;
}

//
// If element exist than bind function func to element on event.
// Example: check_and_bind ('document.NewRecord1.Delete1','onclick',page_NewRecord1_Delete1_OnCli ck);
//


function check_and_bind(element,event,func) {
var htmlElement = eval(element);
if (htmlElement) {
if (typeof(htmlElement)=="object" && !htmlElement.tagName && htmlElement.length > 0)
{
for (var i=0; i < htmlElement.length; i++)
eval(element+"["+i+'].'+event+'='+func);
}else eval(element+'.'+event+'='+func);
}
}


function page_membersSearch_s_talent_cat_OnChange()
{
    var result;
    document.forms["membersSearch"].submit();
    return result;
}

function bind_events() {
if (document.forms["membersSearch"]) check_and_bind ('document.forms ["membersSearch"].s_talent_cat','onchange',page_membersSearch_s_talent _cat_OnChange);
forms_onload();
}


window.onload = bind_events;



_______________________________________________ Do not post admin requests to the list. They will be ignored. Web-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/web-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Javascript problem to submit a form in Safari or Firefox (From: "Louis Philip Morin" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.