getElementsByName() generates undefined ouput value in a textbox

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Aug 2007
Posts: 58
Reputation: rrocket is an unknown quantity at this point 
Solved Threads: 0
rrocket's Avatar
rrocket rrocket is offline Offline
Junior Poster in Training

getElementsByName() generates undefined ouput value in a textbox

 
0
  #1
Sep 4th, 2007
I am passing a value through query string to a popup and then trying to pass it back to the main page... I store the value in a hidden input box
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <input type="text" name="FromZip" id="FromZip" value="<% response.write(Request.QueryString("txtZipFr")) %>" />


and am passing it back through query string to the main page with
  1. <script language="JavaScript" type="text/javascript">
  2. //<!--
  3. //opener.location.reload(true);
  4. //window.opener.location='bl_zip_sngl.asp?
  5. var x;
  6. x = document.getElementsByName("FromZip").value;
  7. alert(x);
  8. window.opener.location='bl_zip_sngl.asp?txtZipFr=' +x
  9. self.close();
  10. // -->
  11. </script>

It gives me undefined as the output, but when I do it like this
  1. <script language="JavaScript" type="text/javascript">
  2. //<!--
  3. //opener.location.reload(true);
  4. //window.opener.location='bl_zip_sngl.asp?
  5. var x;
  6. document.getElementsByName("FromZip").value = 79797; //Only difference
  7. x = document.getElementsByName("FromZip").value;
  8. alert(x);
  9. window.opener.location='bl_zip_sngl.asp?txtZipFr=' +x
  10. self.close();
  11. // -->
  12. </script>
it at least returns a real value. Unfortunately I need to dynamically populate the box with what the user originally typed in.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: getElementsByName() generates undefined ouput value in a textbox

 
0
  #2
Sep 5th, 2007
document.getElementsByName() returns a nodeList or simply put an array. You just can't directly assign a value to an array reference. You need to do something like the one given below assuming there is only element which goes by the name of 'FromZip'. document.getElementsByName("FromZip")[0].value = 79797;
Last edited by ~s.o.s~; Sep 5th, 2007 at 12:35 pm.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 19
Reputation: guest is an unknown quantity at this point 
Solved Threads: 0
guest guest is offline Offline
Newbie Poster

Re: getElementsByName() generates undefined ouput value in a textbox

 
0
  #3
Feb 26th, 2009
For me that not work try on this website maybe will help you
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC