Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Accessing the contents of a form textbox using the ID?

Posted on 2004-12-01
9
Medium Priority
?
233 Views
Last Modified: 2010-08-05
Hi,

I'm using some third party software to deliver HTML/ASP generated pages to the browser.  The browser (the IE engine) actually sits inside the third party software.   When the third party software starts up it gets invoked by the user by passing a account number into it.   The third party software then runs it's own component methods to look up the account number from a MSSQL database and return the details of that account.

The returned data gets populated into FORM fields identified by the id, for example

<form name=account>
<input id=accountname size=20>

<input id=accountpassword size=10>
</form>
etc...

So when the page first loads all of the data has already been queried from the db and then pushed into those form boxes, based on the id.  The id tag is the database table field name, fyi.


So my question is... is there a way to now access the contents of those fields, like:

var accountname
accountname = document.account.accountname.value

and then I can use that data?


Caspar
0
Comment
Question by:CasparUK
  • 5
  • 4
9 Comments
 
LVL 33

Expert Comment

by:sajuks
ID: 12714171
just use
document.getElementById('accountname').value
0
 
LVL 33

Expert Comment

by:sajuks
ID: 12714185
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function getVal()
{
var acc = document.getElementById('accountname').value
var accp = document.getElementById('accountpassword').value
alert ( 'accountname is ' +acc )
alert ( 'accountpassword is ' + accp)
}
//-->
</SCRIPT>
</HEAD>

<BODY>
<form name=account>
<input id=accountname size=20 value = "ACCT HEAD">
<input id=accountpassword size=10 value = "TXT">
<input type = "button" onclick = "getVal()">
</form>
</BODY>
</HTML>

Once you have the values you could do the validations/manipulations that you want
0
 
LVL 1

Author Comment

by:CasparUK
ID: 12715016
I agree that that shd work, but it doesn't in my case... :(

The third party software, which creates uses an object somewhat prevents that information to be captured...


The below code gets loaded when the page is viewed:
Dim AgentDisp

Sub Window_OnLoad
  Set AgentDisp = GetObject("","AgentDisp.AgentDispatcher")

  AgentDisp.PopulateFields

  window.Focus
End Sub



Where in the webserver can I gain access to this object?


C
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Expert Comment

by:sajuks
ID: 12722794
You're using vbscript  ? What actually are you trying to do and where? The page is generated by a third party software .Fine. Now you want to access these values ? Ok . From where ? Are you trying to modify the generated  page or what ?Sorry i cant seem to get the flow rite.Can you elaborate a bit.
0
 
LVL 1

Author Comment

by:CasparUK
ID: 12734437
Yep VBscript.... the code above works fine...but the problem was that it was being called before the form was populated, i.e. within the HTML HEAD, but the form is populated by an OnLoad call...

Code so far:
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function FunPhoneNum()
{
var PhoneNum = document.getElementById('PhoneNum').value
alert ( 'accountname is ' +PhoneNum )
}
//-->
</SCRIPT>
<form name=frmPhoneNum>
      <INPUT id=PhoneNum Size=15>      
      <input type = "button" onclick = "FunPhoneNum()">
      
</form>      
<a href="javascript:FunPhoneNum()">Confirm call</a>

</BODY>
</HTML>


The problem now is how do I submit this form automatically without using the onload call, as this is already being used and I don't think I can use it too...

The page needs to fully load...can I have like a redirect at the bottom of the page appending the form field PhoneNum in the QueryString, if so how?

C
0
 
LVL 33

Expert Comment

by:sajuks
ID: 12734522
The page loads and then u need to redirect.Not sure but check this am assuming that the value of PhoneNum
has already been set. You could also call two funcs on body onload, but since you mention that it cant be used////

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<form name=frmPhoneNum>
     <INPUT id=PhoneNum Size=15 value = 1234>    
    <input type = "button" onclick = "FunPhoneNum()">
</form>    

<script language ="javascript">
location.href = "http://search.google.com?id="+document.getElementById('PhoneNum').value
</script>


</BODY>
</HTML>
0
 
LVL 1

Author Comment

by:CasparUK
ID: 12734721
I think there must be a delay from the time the page loads to the time the field is automatically populated...cause whenever I try and do anything auto submit/redirect that field is always empty! ah! :S

Can a pause be inserted before the location.href redirection?
0
 
LVL 1

Author Comment

by:CasparUK
ID: 12734768
This works a treat, since it pauses the page and allows the 3rd part application container to finish populating the field:

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function getPhoneNum()
{
var PhoneNum = document.getElementById('PhoneNum').value
location.href = "start.asp?bob=4&PhoneNum="+document.getElementById('PhoneNum').value
}
//-->
</SCRIPT>
<form name=frmPhoneNum>
      <INPUT id=PhoneNum Size=15>      
      <input type = "button" onclick = "getPhoneNum()">      
</form>      
</BODY>
</HTML>

but the user still has to do something :(

Any ideas how I can automate a 1/2 second pause?

0
 
LVL 33

Accepted Solution

by:
sajuks earned 500 total points
ID: 12734850
//try this , setTimeout is measured in milliseconds,
<HTML>
<HEAD>
<script>
function callit()
{
location.href = "http://search.google.com?id="+document.getElementById('PhoneNum').value
}
</script>
</HEAD>
<BODY>
<form name=frmPhoneNum>
     <INPUT id=PhoneNum Size=15 value = 1234>    
    <input type = "button" onclick = "FunPhoneNum()">
</form>    

<script language ="javascript">
setTimeout( "callit()",500)
</script>
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question