If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > How to pass the variable in the asp form to a javascript function?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-06-04, 21:11
yllas yllas is offline
Registered User
 
Join Date: Nov 2003
Posts: 8
Question How to pass the variable in the asp form to a javascript function?

How to pass the variable in the asp form to a javascript function "Validatedata()" while form submit?

<%
dim CountryCode,strNumber,strAddress,strCity,strState, strPostcode,
dim MyServID,CustRefNo
dim strServiceId,strCompany
%>

<SCRIPT LANGUAGE="JavaScript">
function Validatedata(){

var strurl, strCountry,strcompname,strcompnumber,strcompaddres s,strcompcity,strcompstate,strcompzipcode,servicet ype;
var emptyflag,CustRefNo ;
emptyflag = 0;
var t,serviceid;

if(emptyflag == 0 ){
strurl= "payforservices.asp?fromaction=4&MyServID="+servic eid+"&Country="+ strCountry +"&Number="+strcompnumber+"&Name="+ strcompname + "&Address="+strcompaddress+"&State="+strcompstate+ "&City="+strcompcity+"&Postcode="+strcompzipcode+" &CustRefNo="+CustRefNo;
location.href = strurl;
}
}
</SCRIPT>

<%
connectDB()
Set RS = Server.CreateObject("ADODB.Recordset")
RS.ActiveConnection=objConn
RS.Source=sql
RS.open
If not RS.eof then
if RS("servicetype") = "12" and RS("serviceid") = "14" then %>

<form method=post name="frmindex">

<table border=0 width=98% align=center cellspacing=0 cellpadding=2>
<TR class="formSectionHeader">
<TD colspan=2 align=left>Details</TD>

<TR class="FormSectionbody">
<td class=formLabel width=30% align=left>Service </td>
<TD width=70% class="clsMainFont" align=left><%=RS("servicedescription")%>&nbsp;</TD>
</TR>
<TR class="FormSectionbody">
<td class=formLabel width=30% align=left>Type</td>
<TD width=70% class="clsMainFont" align=left><%=RS("settingsdescription")%>&nbsp;</TD>
</TR>

<TR class="FormSectionbody">
<td class=formLabel width=30% align=left>Name</td>
<TD width=70% class="clsMainFont" align=left ><%=RS("subjectname")%>&nbsp;</TD>
</TR>
<TR class="FormSectionbody">
<td class=formLabel width=30% align=left>Subject #</td>
<TD width=70% class="clsMainFont" align=left><%=RS("subjectuniqueid")%>&nbsp;

</TR>

<TR class="FormSectionbody">
<td class=formLabel width=30% align=left>Address</td>
<TD width=70% class="clsMainFont" align=left><%=RS("subjectaddress1")%>&nbsp;<%=RS(" subjectaddress2")%>&nbsp;</TD>
</TR>
<TR class="FormSectionbody">
<td class=formLabel width=30% align=left>City</td>
<TD width=70% class="clsMainFont" align=left><%if subjectcity <> "" then%><%=RS("subjectcity")%><%end if%>&nbsp;</TD>
</TR>
<TR class="FormSectionbody">
<td class=formLabel width=30% align=left>State</td>
<TD width=70% class="clsMainFont" align=left><%if subjectstate <> "" then%>&nbsp;<%=RS("subjectstate")%><%end if%>&nbsp;</TD>
</TR>
<TR class="FormSectionbody">
<td class=formLabel width=30% align=left>Country</td>
<TD width=70% class="clsMainFont" align=left><%=GetCountrySettings(RS("subjectcountr y"))%>&nbsp;</TD>
</TR>
<TR class="FormSectionbody">
<td class=formLabel width=30% align=left>Post Code</td>
<TD width=70% class="clsMainFont" align=left>
<%if subjectzip <> "" then%>&nbsp;<%=RS("subjectzip")%><%end if%>&nbsp;</TD>

</TR>
<TR class="FormSectionbody">
<td class=formLabel width=30% align=left>Customer Ref.#</td>
<TD width=70% class="clsMainFont" name="CustRefNo" value="<%=RS("customerreferencenumber")%>" align=left><%=RS("customerreferencenumber")%>&nbsp ;</TD>
</TR>
<TR class="FormSectionbody">
<TD class="formLabel" align=left>&nbsp;</TD>
<TD><INPUT TYPE="button" value=" Next " onclick="javascript: Validatedata();" maxlength="200" id=button1 name=button1></TD>
</TR>

<%
RS.close
set RS = Nothing
disconnectDB()
%>

Last edited by yllas; 01-06-04 at 21:21.
Reply With Quote
  #2 (permalink)  
Old 01-06-04, 21:30
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
no data to be submitted

In your form, there is no any data to be submitted. So you can not pass the data to your JavaScript Validatedata().
Reply With Quote
  #3 (permalink)  
Old 01-07-04, 18:09
Bullschmidt Bullschmidt is offline
Guru
 
Join Date: Jun 2003
Location: USA
Posts: 1,032
And here's something that's somewhat related which I previously put together and may hopefully help clarify your thoughts in some way about mixing server-side ASP (which gets processed first) with client-side JavaScript.

It's easy to use the value of a VBScript variable in JavaScript:
document.writeln('<%= MyVBScriptVariable %>');

Or here is an example which puts the value of a VBScript variable into a JavaScript alert box:
Response.Write "<script language='JavaScript'>alert('The value is " & MyVBScriptVariable & "');</script>"

But to send the value of a JavaScript variable to VBScript, well that's another story. You could have the JavaScript fill in a hidden form field and then post the form. That way VBScript can pick up the value of the hidden form field with Request.Form("MyFieldName")
__________________
J. Paul Schmidt, Freelance Web and Database Developer
www.Bullschmidt.com
Access Database Sample, Web Database Sample, ASP Design Tips
Reply With Quote
  #4 (permalink)  
Old 01-09-04, 06:19
arnelR arnelR is offline
Registered User
 
Join Date: Dec 2003
Location: Philippines
Posts: 11
if you want to pass variables from asp form to script use innertext property. ex. tableID.tdID.innertext. This will give you the text inside the <TD></TD> tag. You should provide an ID to the TD and TABLE tag to do this.

Last edited by arnelR; 01-09-04 at 06:24.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On