0

Im on trouble on redirect to subdomain. My goal is to send total value to my subdomain. Let me show you my form

<form name="myform" id="myform">
   <div class="input-field">
      <p class="flow-text">Item yg dipesan...</p>
      <p>
         <label>
         <input type="checkbox" name="chkall" onclick="checkAll(this)">
         <span>Pilih Semua</span>
         </label>
      </p>
      <p>
         <label>
         <input type="checkbox" name="chkbox" value="10000">
         <span>Item 1</span>
         </label>
      </p>
      <p>
         <label>
         <input type="checkbox" name="chkbox" value="20000">
         <span>Item 2</span>
         </label>
      </p>
      <p>
         <label>
         <input type="checkbox" name="chkbox" value="30000">
         <span>Item 3</span>
         </label>
      </p>
      <p>
         <label>
         <input type="checkbox" name="chkbox" value="40000">
         <span>Item 4</span>
         </label>
      </p>
   </div>
   <div class="input-field">
      <button class="btn" type="button" onclick="getSum()">Submit</button>
   </div>
</form>

Here is the js

 function getSum() {
    totalvalue = 0
    obj = document.myform.chkbox
    for (i = 0; i < obj.length; i++) {
        if (obj[i].checked) {
            totalvalue += parseInt(obj[i].value)
        }

    }

    if (totalvalue == 0) {
        alert("Please select atleast one product!!");
    } else {
        var url= "subdomain.domainname.com/cgi-bin/sale.cgi?cashflow="+totalvalue+"&secret=secretword"; 
        window.location.href = url;
    }

}

function checkAll(obj) {
    if (obj.checked) {
        obj = document.myform.chkbox
        for (i = 0; i < obj.length; i++) {
            obj[i].checked = true
        }
    } else {
        obj = document.myform.chkbox
        for (i = 0; i < obj.length; i++) {
            obj[i].checked = false
        }
    }

}

Let say that my domain name is domainname.com i try to redirect to subdomain.domainname.com/cgi-bin/sale.cgi?cashflow="+totalvalue+"&secret=secretword after submit button pressed. I expect the final url look like this subdomain.domainname.com/cgi-bin/sale.cgi?cashflow=100000&secret=secretword

The current result display final url like this domainname.com/subdomain.domainname.com/cgi-bin/sale.cgi?cashflow=100000&secret=secretword

1 Answer 1

3

Your location.href redirects to sub-url. Simply add http:// to make absolute redirect:

var url= "http://subdomain.domainname.com/cgi-bin/sale.cgi?cashflow="+totalvalue+"&secret=secretword"; 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.