Shop OBEX P1 Docs P2 Docs Learn Events
PINK HTML questions — Parallax Forums

PINK HTML questions

Ron CzapalaRon Czapala Posts: 2,418
edited 2009-09-17 18:40 in BASIC Stamp
Does anyone know if there is a way to pass·querystring arguments (e.g.· test.htm?Nb_var01) to a PINK web page?

I get a page not found 404 error when I try test.htm?Nb_var01 but test.htm#Nb_var01 shows the page but document.location.search is empty.

<html><head><title></title>
</head><body>
<script language="javascript">
  if (document.location.search) {
    var querystring=document.location.search.split("&");
    alert(document.location.search);
//    alert(querystring[noparse][[/noparse]0].substr(0));
    document.write("Value: <" + querystring[noparse][[/noparse]0].substr(0) + ">");
  }  
</script>
</body></html>


I am trying to pass the name of a PINK variable to·a page.

Comments

  • xanatosxanatos Posts: 1,120
    edited 2009-09-17 16:54
    Yes - You have to have the page read the values into hidden inputs, then you can assign values in JS just like normal with document.getElementById as in:

    hTotal = document.getElementById("htotalh").firstChild.nodeValue;
    mTotal = document.getElementById("mtotalh").firstChild.nodeValue;

    I am using this to pass values between pages, and between the host computer reading the PINK page and the DS1302 to set its time equal to the host computer.

    Does this help?

    Dave
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2009-09-17 17:24
    Dave,
    ·I really should have provided more info.
    ·I am trying to pass variable names (e.g. Nb_var00 ...)·to·resp.htm·in the querystring using a xmlHttpRequest when I click·various buttons (see attached jpg).

    var xmlRequest;
    function HttpReqPost(sendtext) {
      var URL;
      URL = "resp.htm";  //?" + varname;
      
      xmlRequest = getXMLHttpRequest();
      xmlRequest.open("post", URL);
      xmlRequest.setRequestHeader("Content-Type", "text/xml");
      //xmlRequest.setRequestHeader("Connection", "close");
      xmlRequest.onreadystatechange = processReqChange;
      xmlRequest.send(sendtext);
    }
    function getXMLHttpRequest() {
      if (window.XMLHttpRequest) {
        return new window.XMLHttpRequest;
      }else{
        try {
          return new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch(ex) {
          alert("No http request capability");
          return null;
        }
      }
    }
    </script>
    

      <input type="button" value="On" onclick="return HttpReqPost('Nb_var01=1')">
    


    resp.htm code

    <html><head><title></title>
    </head><body>
    <script language="javascript">
      if (document.location.search) {
        var querystring=document.location.search.split("&");
    //    alert(document.location.search);
    //    alert(querystring[noparse][[/noparse]0].substr(0));
        document.write("Value: <" + querystring[noparse][[/noparse]0].substr(0) + ">");
      }  
    </script>
    </body></html>
    
    

    Post Edited (ronczap) : 9/19/2009 12:28:23 PM GMT
  • xanatosxanatos Posts: 1,120
    edited 2009-09-17 17:50
    OK, got it. That said, I've never passed vars or querystrings between pages using a GET method with the PINK, I always use the POST method, and write the values directly to the various Nb_vars, and when the page refreshes with those values written into the var locations, the first thing my page does is to write those values into hidden inputs and read them into JavaScript as above... so to pass a query string, I honestly can't say. Sorry I couldn't offer more help.

    Briefly, for what it may/not be worth:
    I have a page with a dropdown selector that gets read on submission and sets values of the hidden inputs accordingly:

    if (whichOne == 1) {document.dockForm.Nb_var21.value = date2;document.dockForm.Nb_var51.value = packdate2;}

    At the bottom of the pages I have a listing of the vars:

    <INPUT TYPE="hidden" NAME="Nb_var21" MAXLENGTH=12>

    Then at the top of the code in the page, when it refreshes the first thing it does is read and act on the new variable data:

    function totalTime() {
    hTotal = document.getElementById("htotalh").firstChild.nodeValue;
    mTotal = document.getElementById("mtotalh").firstChild.nodeValue;

    if (hTotal == "NA") {
    hTotal = 0;
    }

    if (mTotal == "NA") {
    mTotal = 0;
    }

    document.getElementById("htotal").firstChild.nodeValue = hTotal;
    document.getElementById("mtotal").firstChild.nodeValue = mTotal;
    }



    I have all of my data acquisition AND the code that acts on the data in the same page - I post it to itself. I write flags to Nb-var registers to tell the page what to do when it first loads each time... So the page may look different, and certainly contains the desired results (and/or directs the stamp to perform the selected actions), but it remains the same page.

    That's about all I can offer...

    Dave
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2009-09-17 18:40
    Thanks Dave.

    · I have used the technique of hidden inputs and posting back to the same page before, but the xmlHttpRequest post/get method has some advantages but the PINK module isn't a full-fledged web server so I may have to try some otther approaches.

    - Ron
Sign In or Register to comment.