views:

347

answers:

1

Hi there,

I have two different forms which is formA and formB where each form in different .asp file. In each form there is a textarea where the user need to enter their address. Beside the textarea in formB there is a checkbox where the user can click on it if the address for both textareas are the same. My question is how can I copy the value from textarea in formA into the textarea in formB by using checkbox. I can't figure it out because it involve to different forms from two different .asp file. Hope you can help. Thank you.

A: 

If this is something like a checkout procedure where you want to copy the value of shipping address to be the same as mailing address, it's quite simple to do.

In form B, you basically load the other address (from form A or from storage if you persist it) in a hidden form field and then detect the checkbox is changed in javacsript. If it is ticked, then copy the hidden form value to the new textbox.

3 pieces that you need (all in form b asp page):

<%
  Dim addressInFormA

  'Retrieve the address from previous page (form a)
  'Change to Request.Form or Request.QueryString for more efficient code
  'Using Request as a catch all here.
  'Need to add necessary clean up code to prevent script injection vulnerability here
  'For simplicity sake, I'm not doing it here.
  addressInFormA = Request("txtAddress")
%>

<input type="hidden" name="hidAddress" id="hidAddress" value="<%=addressInFormA%>" />

<input type="checkbox" name="chkUseAddressA" id="chkUseAddressA" onclick="checkCopyAddress()" />
<input type="text" name="txtAddress" id="txtAddress" />

<script>
function checkCopyAddress() {
  'Get me the checkbox
  'This is just for example, in reality I won't do it this way.
  var checkBox = document.getElementById("chckUseAddressA");

  document.getElementById("txtAddress").value = 
(checkBox.checked) ? document.getElementById("hidAddress").value : "";
}
</script>
Jimmy Chandra
Can you show me the codes for this parts: 'Retrieve the address from previous page (form a) 'Change to Request.Form or Request.QueryString for more efficient code 'Using Request as a catch all here. 'Need to add necessary clean up code to prevent script injection vulnerability hereI think I didnot manage to run the codes because I have problem with those parts..Plz help..
I strongly suggest you read the following MSDN article: http://msdn.microsoft.com/en-us/library/ms972337.aspx
Jimmy Chandra