hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : JavaScript help needed
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

JavaScript help needed

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 08-16-2004, 12:54 PM
portalplanet portalplanet is offline
Web Hosting Master
 
Join Date: Nov 2003
Location: Florence, KY
Posts: 604
Question

JavaScript help needed


Hi all. I have a field in a form called cart_quantity that looks like this:
Code:
<input type="hidden" name="id[txt_3]" value="Justin">
after the </form> I am trying to just display an alert with the value of the hidden field like this:
Code:
alert(document.forms["cart_quantity"].id[txt_3].value);
This is not working. I'm thinking it's because of the []'s and javascript thinking I'm talking about an array. I have tried this:

Code:
alert(document.forms["cart_quantity"].id\[txt_3\].value);
to no avail. Anyone have any suggestions what to try next? I'm customizing osCommerce so I need to keep the []'s in there.

Thanks!
Justin

Reply With Quote


Sponsored Links
  #2  
Old 08-16-2004, 01:07 PM
GHDpro GHDpro is offline
Junior Guru
 
Join Date: Nov 2000
Location: Holland
Posts: 246
First: if you're not doing it already, you'd might want to use FireFox or Mozilla
for testing, as those browsers have a convinient Javascript console which
will show what has gone wrong.

Without the error message that will probably be in the Javascript console,
it's a bit hard to just guess at what's going wrong, but:

Afaik Javascript arrays do support associative arrays (using strings as index)
but you do need to use quotes if you want to access them:

document.forms["cart_quantity"].id["txt_3"].value

But that's just a guess at what might be the problem...

Btw, instead of:

document.forms["cart_quantity"].

the following should also work (afaik):

document.cart_quantity.

__________________
.

Reply With Quote
  #3  
Old 08-16-2004, 02:12 PM
JimPanse JimPanse is offline
Newbie
 
Join Date: Aug 2004
Posts: 27
hm

i dont understand and have no clue about the strange nametag you using but



<script>
var a = document.getElementsByName("id[txt_3]")[0];
alert(a.value);
</script>


dunno if this will work.....maybe its a try

Reply With Quote
Sponsored Links
  #4  
Old 08-16-2004, 03:32 PM
portalplanet portalplanet is offline
Web Hosting Master
 
Join Date: Nov 2003
Location: Florence, KY
Posts: 604
Awesome! Thanks GHDpro! That seems to have fixed my problem.

Justin

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Facebook's Recently Acquired Mobile App Platform Parse Launches Web Hosting for Developers Web Hosting News 2013-05-08 10:49:17
Web Host GeekStorage Opens New Office in Oklahoma, Names Account Manager Web Hosting News 2012-07-31 14:04:33
Web Host VISI Provides Hosting Services to Minnesota Public Radio Web Hosting News 2011-12-30 15:45:36
Software Developer Softaculous Launches Softaculous Auto Installer Version 3.8 Web Hosting News 2011-11-25 15:34:49
Microsoft Launches First Beta of Microsoft WebMatrix 2.0 Web Hosting News 2011-09-26 15:43:24


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?