Link to home
Start Free TrialLog in
Avatar of CasparUK
CasparUK

asked on

Accessing the contents of a form textbox using the ID?

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
Avatar of sajuks
sajuks

just use
document.getElementById('accountname').value
<!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
Avatar of CasparUK

ASKER

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
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.
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
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>
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?
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?

ASKER CERTIFIED SOLUTION
Avatar of sajuks
sajuks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial