Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Script question - Copy text field from one form to another 1

Status
Not open for further replies.

MavrickStl

Programmer
Feb 20, 2001
71
US
Guys,

Is it possible to copy values from FORM - B (text field) to another form FORM - A using checkbox (on FORM -B) as selection criteria? Can someone point to me a sample code? I am using ASP.

Thanks,

Mav
 
Mavrick5tl,

>I am using ASP.
But your functionality seems to be client-side. The model answer is to ask javascript forum. But, I take it vbscript can do client-side as well and this illustrates how it is done.
Code:
<html>
<head>
<script language="vbscript">
function sync
	dim oelem
	set oelem=document.getElementById("chkbxb")
	if oelem.checked then
		document.form_a.txta.value=document.form_b.txtb.value
		document.form_a.txta.disabled=true
	else
		document.form_a.txta.value=document.form_a.txta.getAttribute("default")
		document.form_a.txta.disabled=false
	end if
end function
</script>
</head>
<body>
<form name="form_a" id="form_a">
<p></p><input type="text" name="txta" default="default value" value="default value" onblur="sync" /></p>
</form>
<form name="form_b" id="form_b">
<input type="text" name="txtb" onblur="sync" />
<p></p>sync form_a with form_b: &nbsp;<input type="checkbox" id="chkbxb" onclick="sync" /></p>
</form>
</form>
</body>
</html>
As to distributing/building the html from response body. It's entirely an independent functionality which serves to build the page functioning like above.

regards - tsuji
 
-Amendment-

A less restrictive behavior on form-a textbox is to comment out the line on the default.
[tt]
function sync
dim oelem
set oelem=document.getElementById("chkbxb")
if oelem.checked then
document.form_a.txta.value=document.form_b.txtb.value
document.form_a.txta.disabled=true
else
[green]'less restrictive if comment out this line
'document.form_a.txta.value=document.form_a.txta.getAttribute("default")[/green]
document.form_a.txta.disabled=false
end if
end function
[/tt]
- tsuji
 
-Correction(typo)-

Forgot to edit out two auto-gen </p> immediately followng <p>. ([tt]<p>[red]</p>[/red][/tt])

- tsuji
 
Thanks tsuji,

I am going to try this and will let you know the results.

I appreciate it.

mav
 
tsuji,

Well, It works, but I have FORM A and FORM B on two different browser windows. FROM - B will have a submit button for uses's to click after they have used the check box criteria for text they want to copy onto a text box on form - A.

Any thoughts .....

Mav
 
MavrickStl,

If they are of different pages, they must be related one another via some kind of parent-child relation, short, some handles they can talk to each other? If pageB is a popup through pageA, pageB can refer to pageA through opener object and pageA can refer to pageB through the handle established at creation time via set handle=window.open(...). If pageB is sort of modaldialog, then you have to device message returned to pageA when close etc... On an arbitary setting where pageA and pageB do not the existence of the other, then it is _not_ very realistic and each would need to do thing on the client's m/c testing client's security. Just a thought.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top