The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> onChange little help
Mr Me
post Nov 15 2009, 06:55 AM
Post #1





Group: Members
Posts: 3
Joined: 15-November 09
Member No.: 10,339



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:)

This post has been edited by Mr Me: Nov 15 2009, 07:51 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Nov 15 2009, 07:09 AM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



Depends on what you mean with change. Replace the whole form with another one? Possible, yes. Easily done, no.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Mr Me
post Nov 15 2009, 07:22 AM
Post #3





Group: Members
Posts: 3
Joined: 15-November 09
Member No.: 10,339



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;">


This post has been edited by Mr Me: Nov 15 2009, 07:24 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Nov 15 2009, 08:26 AM
Post #4


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Mr Me
post Nov 17 2009, 04:59 AM
Post #5





Group: Members
Posts: 3
Joined: 15-November 09
Member No.: 10,339



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Nov 17 2009, 05:26 AM
Post #6


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 25th April 2024 - 01:58 AM