Re: [WSG] How to send two values to javascript
Still fighting with this. Since I've taken the variables out of the javascript it is called like this But firebug keeps showing the error as missing ) after argument list showSubcategory2(document.getElementById() I'm looking forward to getting the book next week but this is driving me up the wall. Related question why is it bad web standards to use onchange and the like. Up until know everything I've seen online makes that type of use normal. Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Kit Grose wrote: The issue is that selects themselves don't have values. You notice the value is on the option tag, not the select. So you can't just get the .value of the element with ID 'subcategory'; you need to get the value of the currently selected item OF that select box. That can be done as an inline declaration, but shouldn't be. The best bet is to get both values within the showSubcategory2 function. Remove both parameters to the showSubcategory2 function and calculate them in the function: HTML: onchange="showSubcategory2()"> JavaScript: function showSubcategory2() { var categorySelect = document.getElementById('category'); var subcategorySelect = document.getElementById('subcategory'); var category = categorySelect.options[categorySelect.selectedIndex].value; var subcategory = subcategorySelect.options[subcategorySelect.selectedIndex].value; xmlHttp = GetXmlHttpObject(); if (xmlHttp == null) { alert ("Browser does not support HTTP Request"); return; } var url = "getsubcategory2.php"; url = url + "?category2="+category; url = url + "&subcategory2="+subcategory; url = url + "&sid="+Math.random(); xmlHttp.onreadystatechange = stateChanged; xmlHttp.open("GET", url, true); xmlHttp.send(null); } ...or better yet, remove the onchange attribute from your select tag completely and implement the onchange unobtrusively as I detailed last time. Hope that helps, Kit *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
So here is the current issue. I am able to send a value. When sending two something strange is happening onchange="showSubcategory(document.getElementById('category').value)"> //(this works fine) onchange="showSubcategory2(document.getElementById('category').value,document.getElementById('subcategory').value)"> Here you can see I am grabbing category and subcategory. I then format my url function showSubcategory2(category,subcategory) { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="getsubcategory2.php" url=url+"?category2="+category url=url+"&subcategory2="+subcategory url=url+"&sid="+Math.random() xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) However it shows in firebug as http://yourcomputerconsultant.net/getsubcategory2.php?category2=HUMAN%20RESOURCES&subcategory2=undefined&sid=0.9278353600691835 Two things Human Resources is my subcategory and nothing appears in subcategory2. Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Casey Farrell wrote: Try using single quotes, as in: onchange="showSubcategory(document.getElementById('category').value)"> Michael Horowitz wrote: Having trouble so I went to testing with one element like this onchange="showSubcategory(document.getElementById("category").value)"> and firebug shows a syntax error. I tried it again taking oub the "" onchange="showSubcategory(document.getElementById(category).value)"> and then received the error message this document has not properties. Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Olly Hodgson wrote: On Nov 14, 2007 10:37 PM, Michael Horowitz <[EMAIL PROTECTED]> wrote: I have examples using one value onchange="showSubcategory(this.value)"> from a form to a script. What if I need to send two values one from the current element in the form and one from another element onchange="showSubcategory(this.value, document.getElementById("anotherElement").value);" *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
Now firebug gives the error showSubcategory2(document.getElementById( Code is Code samples I've been able to review I know this will be simple at the end. Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Brian Cummiskey wrote: Michael Horowitz wrote: onchange="showSubcategory2(document.getElementById('category').value,document.getElementById('subcategory').value)"> try this: onchange="showSubcategory2(document.getElementById("category").value, this.options[this.selectedIndex].value);"> *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
The issue is that selects themselves don't have values. You notice the value is on the option tag, not the select. So you can't just get the .value of the element with ID 'subcategory'; you need to get the value of the currently selected item OF that select box. That can be done as an inline declaration, but shouldn't be. The best bet is to get both values within the showSubcategory2 function. Remove both parameters to the showSubcategory2 function and calculate them in the function: HTML: onchange="showSubcategory2()"> JavaScript: function showSubcategory2() { var categorySelect = document.getElementById('category'); var subcategorySelect = document.getElementById('subcategory'); var category = categorySelect.options [categorySelect.selectedIndex].value; var subcategory = subcategorySelect.options [subcategorySelect.selectedIndex].value; xmlHttp = GetXmlHttpObject(); if (xmlHttp == null) { alert ("Browser does not support HTTP Request"); return; } var url = "getsubcategory2.php"; url = url + "?category2="+category; url = url + "&subcategory2="+subcategory; url = url + "&sid="+Math.random(); xmlHttp.onreadystatechange = stateChanged; xmlHttp.open("GET", url, true); xmlHttp.send(null); } ...or better yet, remove the onchange attribute from your select tag completely and implement the onchange unobtrusively as I detailed last time. Hope that helps, Kit *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
Michael Horowitz wrote: onchange="showSubcategory2(document.getElementById('category').value,document.getElementById('subcategory').value)"> try this: *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
It must not be finding the element... does the element you are looking for in the document have id="category"? Michael Horowitz wrote: I've tried single quotes and keep getting the error document.GetElementByID has no properties Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Casey Farrell wrote: Try using single quotes, as in: onchange="showSubcategory(document.getElementById('category').value)"> Michael Horowitz wrote: Having trouble so I went to testing with one element like this onchange="showSubcategory(document.getElementById("category").value)"> and firebug shows a syntax error. I tried it again taking oub the "" onchange="showSubcategory(document.getElementById(category).value)"> and then received the error message this document has not properties. Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Olly Hodgson wrote: On Nov 14, 2007 10:37 PM, Michael Horowitz <[EMAIL PROTECTED]> wrote: I have examples using one value onchange="showSubcategory(this.value)"> from a form to a script. What if I need to send two values one from the current element in the form and one from another element onchange="showSubcategory(this.value, document.getElementById("anotherElement").value);" *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
That solves problem number 1 Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Casey Farrell wrote: It must not be finding the element... does the element you are looking for in the document have id="category"? Michael Horowitz wrote: I've tried single quotes and keep getting the error document.GetElementByID has no properties Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Casey Farrell wrote: Try using single quotes, as in: onchange="showSubcategory(document.getElementById('category').value)"> Michael Horowitz wrote: Having trouble so I went to testing with one element like this onchange="showSubcategory(document.getElementById("category").value)"> and firebug shows a syntax error. I tried it again taking oub the "" onchange="showSubcategory(document.getElementById(category).value)"> and then received the error message this document has not properties. Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Olly Hodgson wrote: On Nov 14, 2007 10:37 PM, Michael Horowitz <[EMAIL PROTECTED]> wrote: I have examples using one value onchange="showSubcategory(this.value)"> from a form to a script. What if I need to send two values one from the current element in the form and one from another element onchange="showSubcategory(this.value, document.getElementById("anotherElement").value);" *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
I think I understand it no need for more explanation. It's too late at night and I am working with twins in the room and a wife at the airport Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Kit Grose wrote: On 15/11/2007, at 3:34 PM, Casey Farrell wrote: Try using single quotes, as in: onchange="showSubcategory(document.getElementById('category').value)"> Michael Horowitz wrote: Even better would be to modify the function itself to get the second value: Then in the JS: function showSubcategory(value1) { // Get value 2 either with var value2 = document.getElementById('secondelement').value; // For input boxes // or var secondSelect = document.getElementById('secondelement'); var value2 = secondSelect.items[secondSelect.selectedIndex].value; // For select menus ...do something } window.onload = function() { document.getElementById('categoryselect').onchange = showSubcategory; } Where 'secondelement' is the ID of your second element. *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
I think you may have something with this secondSelect.items as I am using a select menu. Can you explain where I would put my variable names in here please. Thanks Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Kit Grose wrote: On 15/11/2007, at 3:34 PM, Casey Farrell wrote: Try using single quotes, as in: onchange="showSubcategory(document.getElementById('category').value)"> Michael Horowitz wrote: Even better would be to modify the function itself to get the second value: Then in the JS: function showSubcategory(value1) { // Get value 2 either with var value2 = document.getElementById('secondelement').value; // For input boxes // or var secondSelect = document.getElementById('secondelement'); var value2 = secondSelect.items[secondSelect.selectedIndex].value; // For select menus ...do something } window.onload = function() { document.getElementById('categoryselect').onchange = showSubcategory; } Where 'secondelement' is the ID of your second element. *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
I've tried single quotes and keep getting the error document.GetElementByID has no properties Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Casey Farrell wrote: Try using single quotes, as in: onchange="showSubcategory(document.getElementById('category').value)"> Michael Horowitz wrote: Having trouble so I went to testing with one element like this onchange="showSubcategory(document.getElementById("category").value)"> and firebug shows a syntax error. I tried it again taking oub the "" onchange="showSubcategory(document.getElementById(category).value)"> and then received the error message this document has not properties. Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Olly Hodgson wrote: On Nov 14, 2007 10:37 PM, Michael Horowitz <[EMAIL PROTECTED]> wrote: I have examples using one value onchange="showSubcategory(this.value)"> from a form to a script. What if I need to send two values one from the current element in the form and one from another element onchange="showSubcategory(this.value, document.getElementById("anotherElement").value);" *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
On 15/11/2007, at 3:34 PM, Casey Farrell wrote: Try using single quotes, as in: Michael Horowitz wrote: Even better would be to modify the function itself to get the second value: Then in the JS: function showSubcategory(value1) { // Get value 2 either with var value2 = document.getElementById('secondelement').value; // For input boxes // or var secondSelect = document.getElementById('secondelement'); var value2 = secondSelect.items [secondSelect.selectedIndex].value; // For select menus ...do something } window.onload = function() { document.getElementById('categoryselect').onchange = showSubcategory; } Where 'secondelement' is the ID of your second element. *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
Try using single quotes, as in: onchange="showSubcategory(document.getElementById('category').value)"> Michael Horowitz wrote: Having trouble so I went to testing with one element like this onchange="showSubcategory(document.getElementById("category").value)"> and firebug shows a syntax error. I tried it again taking oub the "" onchange="showSubcategory(document.getElementById(category).value)"> and then received the error message this document has not properties. Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Olly Hodgson wrote: On Nov 14, 2007 10:37 PM, Michael Horowitz <[EMAIL PROTECTED]> wrote: I have examples using one value onchange="showSubcategory(this.value)"> from a form to a script. What if I need to send two values one from the current element in the form and one from another element onchange="showSubcategory(this.value, document.getElementById("anotherElement").value);" *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] *** *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
Having trouble so I went to testing with one element like this onchange="showSubcategory(document.getElementById("category").value)"> and firebug shows a syntax error. I tried it again taking oub the "" onchange="showSubcategory(document.getElementById(category).value)"> and then received the error message this document has not properties. Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Olly Hodgson wrote: On Nov 14, 2007 10:37 PM, Michael Horowitz <[EMAIL PROTECTED]> wrote: I have examples using one value onchange="showSubcategory(this.value)"> from a form to a script. What if I need to send two values one from the current element in the form and one from another element onchange="showSubcategory(this.value, document.getElementById("anotherElement").value);" *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
I just ordered the book. Thanks for the help I test out the solutions given. Michael Horowitz Your Computer Consultant http://yourcomputerconsultant.com 561-394-9079 Olly Hodgson wrote: On Nov 14, 2007 11:11 PM, Olly Hodgson <[EMAIL PROTECTED]> wrote: onchange="showSubcategory(this.value, document.getElementById("anotherElement").value);" While I'm here, two points: Doing anything major using the onchange event isn't a great idea. The reason being it can scupper keyboard users -- some browsers will fire the event when the user's moving through items in the using the cursor keys. Secondly, using inline event handlers is right up there with inline styling. Ideally, you should be keeping everything in a separate script file, in the same way you'd keep your CSS out of the HTML. http://www.onlinetools.org/articles/unobtrusivejavascript/ Cheers, *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
On Nov 14, 2007 11:11 PM, Olly Hodgson <[EMAIL PROTECTED]> wrote: > > onchange="showSubcategory(this.value, > document.getElementById("anotherElement").value);" While I'm here, two points: Doing anything major using the onchange event isn't a great idea. The reason being it can scupper keyboard users -- some browsers will fire the event when the user's moving through items in the using the cursor keys. Secondly, using inline event handlers is right up there with inline styling. Ideally, you should be keeping everything in a separate script file, in the same way you'd keep your CSS out of the HTML. http://www.onlinetools.org/articles/unobtrusivejavascript/ Cheers, -- Olly Hodgson http://thinkdrastic.net/ *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
On Nov 14, 2007 10:37 PM, Michael Horowitz <[EMAIL PROTECTED]> wrote: > I have examples using one value > > onchange="showSubcategory(this.value)"> > > from a form to a script. > > What if I need to send two values one from the current element in the > form and one from another element onchange="showSubcategory(this.value, document.getElementById("anotherElement").value);" -- Olly http://thinkdrastic.net/ *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***
Re: [WSG] How to send two values to javascript
I believe it is as follows; onchange="showSubcategory(name, email, message)" --- if they are the name=name and name=email, etc. or, if you want to parse text, then onchange="showSubcategory("banana", "orange", "apple")" -- So when it arrives at the script it becomes an array starting at [0] to be used how you want. Cheers, Ben On Nov 15, 2007 9:37 AM, Michael Horowitz <[EMAIL PROTECTED]> wrote: > I have examples using one value > > onchange="showSubcategory(this.value)"> > > from a form to a script. > > What if I need to send two values one from the current element in the > form and one from another element > > Thanks > > -- > Michael Horowitz > Your Computer Consultant > http://yourcomputerconsultant.com > 561-394-9079 > > > > *** > List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm > Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm > Help: [EMAIL PROTECTED] > *** > > *** List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm Help: [EMAIL PROTECTED] ***