2014-03-27 3 views
0

채팅 창을 만드는 외부 ASP 파일에 몇 가지 변수를 제출하는 html 양식을 작성하려고합니다.외부 asp 스크립트에 HTML 양식 제출

나에게 제공되는 예제는 http://na.ntrsupport.com/nv/WebIntegration/Connectwise/contactform.aspx?account=41403&lang=us&banner=0&button=connect이지만 두 단계 프로세스가 필요합니다.

제공된 예에서 고객은 입력란을 채우고 "제출"을 클릭 한 다음 별도의 페이지로 이동하여 동적으로 생성 된 자바 스크립트 링크를 클릭하여 채팅 창을 시작합니다.

내가 대신 한 페이지에이로 할 싶지만 일반적인 입력 한 위의 코드에서 외부 스크립트

<script language='JavaScript' src='https://na.ntrsupport.com/nv/inquiero/web/an/ann4.asp?login=41403&lang=us&button=connect&cat=&cob=&oper=&skin=&urloffline=&urlbusy=&sur=&surpre=&bgcolor=&txtcolor=&ref2=/o1https://na.ntrsupport.com/nv/Webintegration/Connectwise/entrypoint.asp?p=1;email%40address.com;Description;Customers+Name;Company+Name&ref=Customers+Name&clientid=Company+Name'> </script> 

올바르게 내 HTML 양식에서 변수를 전달하는 방법을 찾는 데 문제가 있어요 "Company Name"및 "[email protected]"과 같은 필드에 텍스트를 입력하여 예제 링크를 얻으십시오.

여러 가지 방법을 시도해 보았지만 양식에서 변수로 url을 보내려는 javascript를 직접 사용하거나 HTML 양식의 동작 부분에서 url을 사용하는 등 원하는 결과를 얻지 못했습니다.

na.ntrsupport.com의 스크립트가 작동하는 방식이나 요청을받는 방식에 대한 제어권이 없으므로이 스크립트를 끝까지 가져와야합니다.

중요한 도움이되지 않을 경우 도움을 주시면 감사하겠습니다.

내 코드 지금까지

<!DOCTYPE html> 
<html> 
<head> 
<title>Chat</title> 
<script> 
function launchChat() 
{ 
    var name = document.getElementById('name').value; 
    var company = document.getElementById('company').value; 
    var email = document.getElementById('email').value; 
    var description = document.getElementById('description').value; 

    var url = "https://na.ntrsupport.com/nv/inquiero/web/an/ann4.asp?login=41403&lang=us&button=connect&cat=&cob=&oper=&skin=&urloffline=&urlbusy=&sur=&surpre=&bgcolor=&txtcolor=&ref2=/o1https://na.ntrsupport.com/nv/Webintegration/Connectwise/entrypoint.asp?p=1;" + email + ";" + description + ";" + name + ";" + company + "&ref=" + name + "&clientid=" + company; 

window.location(url); 
return false; 
} 
</script> 
<style> 
div{ 
    width:400px; 
    height:200px; 
    position:absolute; 
    left:50%; 
    top:50%; 
    margin-left:-100px; /* Negative half the width*/ 
    margin-top:-100px; /* Negative half the height */ 
} 
</style> 
</head> 
<body> 
<div> 
<form onsubmit="return launchChat();"> 
<table> 
<tr> 
<td colspan=2> 
Put Banner here 
</td> 
</tr> 
<tr> 
<td> 
Name: 
</td> 
<td> 
<input type="text" id=="name" name="name" required> 
</td> 
</tr> 
<tr> 
<td> 
Company: 
</td> 
<td> 
<input type="text" id="company" name="company" required> 
</td> 
</tr> 
<tr> 
<td> 
Email: 
</td> 
<td> 
<input type="email" id=name="email" name="email" required> 
</td> 
</tr> 
<tr> 
<td> 
Description: 
</td> 
<td> 
<input type="text" id="description" name="description" required> 
</td> 
</tr> 
<tr> 
<td colspan=2> 

<input type="submit" id="submit" name="submit" value="Start Chatting"/> 
</td> 
</tr> 
</table> 
</form> 
</div> 
</html> 
+0

당신은 같은 URL을 구축하는 데 문제가 있습니까? – Shomz

+0

javascript를 사용하여 URL을 만들고 필드에서 변수를 가져올 수는 있지만 내장 URL을 사용하여 외부 스크립트를 호출하려면 어떻게해야합니까? – Beuy

+0

나는 무엇이 잘못되었는지를 99 % 확신하지만, 답을주기 전에 양식과 관련된 코드를 보여 주시겠습니까? – Shomz

답변

0

좋아, 그래서 당신은 거기에 조금 너무 복잡했다.

첫 번째 사항 : 문자열에 연결하려는 변수에 encodeURIComponent (키입니다!)을 사용해야합니다. 그 중 일부는 URL에 허용되지 않는 문자를 가질 가능성이 있기 때문입니다.

둘째 : 양식에 GET 메서드를 사용하면 자동으로 URL을 작성합니다. 예를 들면 :

<form action="a.html" method="GET"> 
    <input name="var1" value="value1" /> 
    <input name="var1" value="value1" /> 
</form> 

자동으로처럼 보이는 링크를 구축 할 것입니다 : a.html?var1=value1&var2=value2, 당신이 필요로하는 무엇의 일부입니다, 여러분의 인생을 더 쉽게 만들 수 있습니다. 나는 당신이 기본적으로 그것들 중 두 가지 (메인 URL, 나는 하드 코드 된 것으로 확신 할 수 없다.)와 ref2 부분을 만들어야한다는 것을 안다.


또 한가지 :

window.location(url); 

은 다음과 같아야합니다

window.location = url; 
+0

"https://na.ntrsupport.com/nv/inquiero/web/an/ann4.asp?로그인 = 41403 & lang = us & button = 연결 & cat = & cob = & oper = & skin = & urloffline = & urlbusy = & sur = & surpre = & bgcolor = & txtcolor = & ref2 =/o1https : //na.ntrsupport.com/nv/Webintegration/Connectwise/entrypoint.asp? p = 1; "부분은 하드 코드 된 상태로 남아있을 것입니다, 그냥 양식의 작업 태그에 넣으려고했으나 제출시 ann4.asp 이후의 모든 내용이 잘리는 것처럼 보입니까? – Beuy

+0

이상하게 들리며 window.location과 관련 될 수 있습니다 (내 업데이트 된 답변),하지만 왜 ann3.asp 후 이유를 이해하지 못한다 ... 지금 작동하는지 말해. 제대로 빌드 된 경우 보려면 위치를 변경하는 대신 콘솔 (또는 경고) URL을 출력 할 수 있습니다. – Shomz

+0

여기에 혼란 스러울 때가 있습니다. launchChat() 함수에서 링크를 만들거나 양식 태그에서 작업을 사용해야합니까? – Beuy