LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-07-2007, 12:44 AM   #1
firemankurt
LQ Newbie
 
Registered: Jul 2006
Location: Ferndale WA USA
Distribution: MEPIS 6
Posts: 19

Rep: Reputation: 0
PHP Form Arrays and Javascript DOM


Ok I figured this out once a long time ago but now I can not remember the proper way to do this.
I have a form named "formName" with a field "OTAuth[1]" that is later processed as a PHP array.

I have some text "RG-220" surrounded by a span tag I want to click on the text to fill "220" in the text box for me.


[HTML]
<form name="formName">
<span onclick="document.formName.OTAuth[1].value='220';">
RG-220
</span>

<br/>
<INPUT type="text" name="OTAuth[1]" value="">
</form>
[/HTML]

I recieve the following error.

Error: document.formName.OTAuth has no properties

How can I reference the "OTAuth[1]" input with javascript and not have javascript drop the "[1]" part?
 
Old 01-07-2007, 11:18 AM   #2
rylan76
Senior Member
 
Registered: Apr 2004
Location: Potchefstroom, South Africa
Distribution: FC11 2.6.29.4-167.fc11.i686.PAE
Posts: 1,370

Rep: Reputation: 69
Hmm - as far I know you'll need to define the array as a javascript variable? I. e. the error you get is correct - there is no array to reference, that is why is "has no properties"....? I. e. I think the PHP array is "invisible" to Javascript. (Not sure)
 
Old 01-07-2007, 11:58 AM   #3
MicahCarrick
Member
 
Registered: Jul 2004
Distribution: Fedora
Posts: 240

Rep: Reputation: 31
Why do you need to name the input OTAuth[1]? Is it because there will be multiple inputs which are loaded into an array in PHP? If that's the case, you may want to instead call them "OTAuth_1" etc. so that JS doesn't confuse them with a JS array. Maybe you can just use the id and leave the name alone (though I don't know if that's a valid name for a form element... I would run it through the w3c validator).

Code:
<form name="formName">
  <span 
    onclick="document.getElementById('OTAuth_1').value='220';">
    RG-220
  </span>
  <br/>
  <input type="text" id="OTauth_1" name="OTAuth[1]" value="">
</form>

Last edited by MicahCarrick; 01-07-2007 at 11:59 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with javascript DOM programming tooparam Linux - Software 1 02-07-2006 06:28 AM
javaScript - DOM, djgerbavore Programming 2 03-03-2005 04:44 AM
lookin for a javascript DOM guru... pld Programming 1 02-17-2005 05:14 PM
Arrays, checkboxes in javascript & PHP Elijah Programming 21 11-15-2004 11:37 PM
willing to pay $$$ PHP / Javascript multiple paged form; carrying over variables micro_sucks General 1 12-26-2003 09:37 AM


All times are GMT -5. The time now is 06:43 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration