Help - Search - Members - Calendar
Full Version: onChange little help
HTMLHelp Forums > Web Authoring > Markup (HTML, XHTML, XML)
Mr Me
Is it possible to tell onChange to only change a specific form?

I have 2 forms and currently have this code
CODE
onChange="if(this.value != -1) window.location='diskusjontest.php?id=' + this.value;">


Is there anything I can replace windoe.location='diskusjontest.php etc. with to make it only fill out form2 not form1?

Thanks:)
pandy
Depends on what you mean with change. Replace the whole form with another one? Possible, yes. Easily done, no.
Mr Me
I just want it to fill another set of text into another form on the same page.

As it works now, I have a dropdown box, when I select a value from that, it fills out 3 text boxes with data from a database,
but now I need a second set of boxes and drop down list, the list contains the same data, but when I select a different name in the list I want it to fill that info to the other set of text boxes.

There is no way to make it from this?:

CODE

onChange="if(this.value != -1) window.location='diskusjontest.php?id=' + this.value;">


into something like this:
CODE
onChange="if(this.value != -1) myboxes.location='form2' + this.value;">
pandy
Sure, but not with location as location refers to the document's URL. The form is part of the page. It doesn't have an URL. There are different ways to access a the value of a form control. Maybe you'd better read from the start.

http://www.pageresource.com/jscript/jforms.htm
http://www.quirksmode.org/js/forms.html
Mr Me
Did read through your links, not much that have to do with the onChange command, but I tried changing the location into this:
CODE
onchange="if(this.value != -1) document.forms[0] + this.value;">

to get it to change values in the first form on the page, but not working.


The script I did use worked, but as it used location it does reload the entrire page and thats not what I want.
I have 2 drop down boxes, they fetch data from a database and when you select a name in the drop down it fetch rest of the data ($first $last $phone etc) and those data should be displayed in textboxes on the page (and they do with old script, but thats not working when I put 2 boxes there).
This is so that you can save often used data into the databse and just get them by selecting a name in the drop down.

I just want the onChange command to "understand" that is's should change the form1, instead if reloading the enitre page.
Christian J
QUOTE(Mr Me @ Nov 15 2009, 01:22 PM) *

I have a dropdown box, when I select a value from that, it fills out 3 text boxes with data from a database,

To access a database you must either submit the form or use AJAX. Since the onchange event is used with client-side javascript, that leaves you with AJAX. Or --if you know what data you'll need-- you might "prepare" the data from the database when the page is requested and store it in e.g. javascript arrays on the page until needed by the forms.

QUOTE
onchange="if(this.value != -1) document.forms[0] + this.value;">

You must specify which three(?) form fields in the form document.forms[0] you want to change the values of, specify those three values, and then use the correct operator for changing value.

QUOTE
when you select a name in the drop down it fetch rest of the data ($first $last $phone etc)

Those look like server-side PHP variables.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.