javascript question...

octane

I have issues, OK!
Hi all, got an interesting enough problem here.

Here is the javascript I use to instruct a site visitor what to do when they see a text field. When the user clicks into the text field, the instruction disappears.

All good stuff. Problem: I _need_ to have the fields named a very specific way, this interferes with the mechanics of the javascript:

onfocus="document.form_details.details[textfield_lastname<?php echo ("$i"); ?>].value=''"

In the final rendered html, this:

details[textfield_lastname<?php echo ("$i"); ?>]

Looks like this:

details[textfield_lastname1]

This name stops the javascript from executing properly.

How do I make it work but still keeping the naming convention?

Is there another way to do it?

Thanks...
 
The PHP interpretor on the server parses any and all PHP code in your pages and returns the results before the browser writes a single line of HTML. If your PHP script echoes a value (as most do), then that's all that will show up in your page. In this case, it seems $i = 1, so the PHP interpretor returns 1 where your code is.

If you rename the file as a .html instead of .php, it will not parse the data. Also, if you have the script set to say [textfield_lastname<?php echo '<?php echo ("$i"); ?>'] it will write out that code as is, though it will be a problem if you need the code executed before being written to the browser.

Mind providing a few more details? What are you trying to accomplish? What is this specific script supposed to do? And, do you have a functional example?
 
Arden said:
The PHP interpretor on the server parses any and all PHP code in your pages and returns the results before the browser writes a single line of HTML. If your PHP script echoes a value (as most do), then that's all that will show up in your page. In this case, it seems $i = 1, so the PHP interpretor returns 1 where your code is.

If you rename the file as a .html instead of .php, it will not parse the data. Also, if you have the script set to say [textfield_lastname<?php echo '<?php echo ("$i"); ?>'] it will write out that code as is, though it will be a problem if you need the code executed before being written to the browser.

Arden, I know you're trying to help, but you've stated a big chunk of the obvious. I know all of this .. I am a php developer.

Arden said:
Mind providing a few more details? What are you trying to accomplish? What is this specific script supposed to do? And, do you have a functional example?

It's simply a form field. The value, depending on what the user decides, there may be as many as ten of these fields: hence the iteration in number.

The form field in raw html is: details[textfield_lastname1]

But in php, this becomes: $_POST['details']['textfield_lastname1']

Or rather, to cycle through the numbered elements or to access them specifically: $_POST['details'][textfield_lastname.$i]

Where: $i is the loop counter variable.

Which is an array element. This means I can group all of the form elements in a particular form into one array...
 
Yes I have an example, but I'd prefer not to let people use it.

It has a vehicle registration & postal code look up system [socket connections linking to web access commands on a Sun server] and every time you do a look up, it costs the client to perform the look up...
 
Alrighty then, so what's the array, $i? For it to behave as such you need to include the array paramaters, $i[], $i[para, meter], etc.

Can you make a mockup? Even if you can't let us actually use the system, a working model would be better than nothing.
 
Arden said:
Alrighty then, so what's the array, $i? For it to behave as such you need to include the array paramaters, $i[], $i[para, meter], etc...

Arden, read through it again.

The examples I've given you are valid, sound and currently working away as we speak.

The variable: $i is merely a loop variable: for ($i=0; $i<count($array_name); $i++) {
 
Back
Top