|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||||||
|
||||||||
|
JavaScript question
I got this piece of javascript from someone on this forum and I forgot who it was, sorry and THANKS it has proven to be very useful......until now.
This used to work but I've transfered my code to another server and now it doesn't work, I've been told the only difference is that one of the PHP GLOBAL options has been truned off due to security risk. No biggie, but for some reason my code won't work. Purpose - I'm trying to dynamically create an array from a select menu. Here is the error that I get: "Error: 'document.forms.myform.elements' is null or not an object" I know what is happening (I think) I just don't know how to fix it. I think the value that I'm passing is getting lost some how. I tried to add some output statements to see what was happening and this is what I get for output: IM HERE this is el:[object]: el length:0: SHOW ARRAY Its missing the addtoarray() function which is whats causing me to think that the value being passed (el) is getting lost somehow..... Here is the javascript code: php Code:
Here is the form that is making the function call (mixture of PHP and HTML): php Code:
anybody got any ideas???? |
|
#2
|
|||
|
|||
|
RE: JavaScript question
looks familiar
the errormessage you are getting is not so strange concidering the debug-method you are using. By using document.write after the page is already parsed in the browser you are actually overwriting the original page, so by the time the script tries to fill the hidden field, it simply doesn't exist anymore. I don't think the problem is in the javascript, but is indeed in the form-handling page. Because of the different setting of PHP (the register_globals setting) you will need to use the so-called superglobals to get to your GET and POST data. In this case it means you cannot just use $array_built in your PHP script, but you need to use $_GET['array_built'] or $_POST['array_built'] (depending on wether it is a GET or a POST method form). |
|
#3
|
||||||||
|
||||||||
|
RE: JavaScript question
crisp-
YES, it should look very familuar. It helped me out tremendously. Thanks again. I fear I need your help again. I understand your explenations about the superglobals, but I don't even think its making it to the javascript correctly. I can't even seem to get the paramater passed to the javascript. I added this code: php Code:
and I get back a bunch of stuff similar to this, but the interesting part is the .value object is null which means to me that it isn't even passing the parameter correctly: php Code:
Maybe I am missing something. Also, is there a better method for debugging? I'm certanily open to suggestions. Currently I'm using IE6 as my web browser. TIA, mike |
|
#4
|
|||
|
|||
|
RE: JavaScript question
your very first document.write already overwrites the page with everything in it.
I'd say in this case the best debugging method would be to change <INPUT TYPE="hidden" NAME="array_build" ><BR> into <INPUT TYPE="text" NAME="array_build" ><BR> so you can actually see what is written to it. Alternatively you can use alert() to display a value. Mozilla has a built-in javascript debugger which can sometimes also be helpfull (Mozilla's javascript errormessages also make more sence). But anyway, I just tested the code after removing the document.write's and it looks to me like it is working just fine. Else could you maybe post the parsed HTML (using view-source from your browser)? |
|
#5
|
|||
|
|||
|
RE: JavaScript question
crisp- I get the feeling i'm in way over my head. Something you are telling me just isn't sinking in. I feel like I'm missing something. OK, I have taken out the document.write statements and un-hid the array_build field in the form. Here is the parsed HTML: php Code:
|