Changing Client side JS to Server Side JS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anonymousstar
    New Member
    • Mar 2008
    • 15

    Changing Client side JS to Server Side JS

    Hi, I was wondering if I can get some help with changing client side javascript to server side javascript. I have a survey connected to an Enterprise Manager SQL database. My code works and the database is updated successfully but I get a warning message

    "This Website uses a data provider that may be unsafe. If you trust the website click OK otherwise click cancel."

    This warning happens twice which I understand one is to open the database and one is to insert data into it.

    I do know serverside begins with

    <%@ LANGUAGE = JavaScript%>

    But I'm not sure how to take this code and adapt it to serverside javascript, and also where to place it within the asp file.

    I've taken snippets of my code and placed it below.

    Any help would be appreciated.

    Kind regards
    Code:
     
    // Find latest ID or default to 1 for first time
    	  	if (rs.eof) 
    	  	{
    		   var	new_id = 1;
    		}
    		else
    		{
    		   var new_id = rs(0) + 1;	
    		}
    
    // Find Selected anser for Q1
    		for (var i=0; i < document.survey.q1.length; i++)
       		{
       			if (document.survey.q1[i].checked)
    	      	{
    	      		var q1_ans = document.survey.q1[i].value;
    	   	   	}
       		}
    
    var email_ans    = document.survey.email.value.replace("'","''");
    		var feedback_ans = document.survey.feedback.value.replace("'","''");
    
    		var strInsertSQL = "INSERT INTO SURVEY_RESULTS_TAB VALUES (" + new_id + ",'" + email_ans + "','" + 
     			                q1_ans + "','" + q2_ans + "','" + q3_ans + "','" + q4_ans + "','" + q5_ans + "','" + 
    			                q6_ans + "','" + q7_ans + "','" + q8_ans + "','" + q9_ans + "','" + feedback_ans + "')";
    
    		adoConnection.Execute(strInsertSQL);
    							
    		rs.close();						
    							
    		adoConnection.Close();
    
    		document.body.style.cursor = "default";
    
    		location.href = "thankyou.html";
    
    	}
    	
    	//-->
       
    </SCRIPT>
    Code:
    <form name=survey method=post onSubmit=survey_answers()>
    
    <input name="q1" type="radio" value="VS">
    
    <input name="q1" type="radio" value="S">
     
    <input name="q1" type="radio" value="D">
    
    <input name="q1" type="radio" value="VD">
    
    <input name="q1" type="radio" value="NA" checked>
    
      <INPUT type=button value="Submit" onClick="survey_answers()"> 
    </form>
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    i'm not aware of such an approach ... the server doesn't know the values of form-elements without getting them transferred via a GET or POST ... so i would simply suggest to submit a form and process only the values serverside ... you cannot read them serverside from the client ...

    Comment

    • anonymousstar
      New Member
      • Mar 2008
      • 15

      #3
      Is it possible to give me an example of how I might do this using the code above?

      Thanks

      Comment

      • anonymousstar
        New Member
        • Mar 2008
        • 15

        #4
        Hi, Just thought it would help if I attached the warning I get when I submit the form. This appears twice and this is what I am trying to get rid of.
        Attached Files

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          as far as i'm aware your code will only work in IE - and you asking how to process submitted form values serverside? ... this is quite basic and in this case you should ask in the appropriate serverside language forum ... ASP or JSP or whatever you want to use.

          Comment

          Working...