Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Posts
    8

    Question Unanswered: 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 22:21.

  2. #2
    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().

  3. #3
    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

  4. #4
    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 07:24.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •